cute-jumper / gmpl-mode

Major mode for editing GMPL (MathProg) files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gmpl-mode

https://melpa.org/packages/gmpl-mode-badge.svg https://stable.melpa.org/packages/gmpl-mode-badge.svg

Major mode for editing GMPL (MathProg) files.

If you are writing GMPL and using GLPK and to solve problems, try this out!

Overview

GMPL is a modeling language to create mathematical programming models which can be used by GLPK.

Although GMPL is a subset of AMPL, the current Emacs major mode for AMPL, which can be found at https://github.com/dpo/ampl-mode, doesn’t work well with GMPL files. Here is the list of the reasons why gmpl-mode works better compared to ampl-mode when editing GMPL files:

  1. Support single quoted string and C style comments.
  2. Some keywords(such as for, end) are highlighted properly, and it provides better hightlighting generally.
  3. A usable indent function.
  4. Some useful commands to interact with glpsol directly.

Usage

Using the Major Mode

First, add the load-path and load the file:

(add-to-list 'load-path "/path/to/gmpl-mode.el")
(require 'gmpl-mode)

Use gmpl-mode when editing files with the .mod extension:

(add-to-list 'auto-mode-alist '("\\.mod\\'" . gmpl-mode))

Using gmpl-glpsol-solve-dwim

When in gmpl-mode, you can use C-c C-c to invoke gmpl-glpsol-solve-dwim. This command will use the content of the current buffer(or the region if the region is active) as the input for the glpsol command, and then display the results in a separate buffer with some colors added. The following command is basically what gmpl-glpsol-solve-dwim does(Yes, --ranges only makes sense for simplex):

glpsol -m input-file -o output-file --ranges sensitivity-file

You can set the variable gmpl-glpsol-program to the exact location of your glpsol command if it is not in the PATH or has some other magic name.

It is also possible that you can pass extra arguments to glpsol command. The buffer-local variable, gmpl-glpsol-extra-args, controls the value of extra arguments. To set extra arguments for glpsol, use M-x gmpl-glpsol-set-extra-args (which is bound to C-c C-a).

For example, if you want to set the --interior option for glpsol, you can use M-x gmpl-glpsol-set-extra-args or C-c C-a. This command will set the value of gmpl-glpsol-extra-args and add the following lines at the end of the file:

# Local Variables:
# gmpl-glpsol-extra-args: "--interior"
# End:

After that, when we invoke gmpl-glpsol-solve-dwim, essentially following command will be used:

glpsol -m input-file -o output-file --ranges sensitivity-file --interior

You can use gmpl-glpsol-set-extra-args to set the value of gmpl-glpsol-extra-args in different buffers so that you can have different commnd line arguments for different problems.

Screenshot

Here is the screenshot using Emacs 24’s builtin theme tsdh-dark:

./screenshot.png

TODO

  • Translate LaTeX equations to GMPL format and solve the problem directly.
  • Add company-keywords support.

About

Major mode for editing GMPL (MathProg) files


Languages

Language:Emacs Lisp 100.0%