GLPK/Using GLPSOL

This page lists some tips and hints when using GLPSOL, the GLPK command-line solver.

Note that GLPSOL is built, by default, when GLPK is built. Hence GLPSOL should be generally present whenever GLPK is installed.

Usage
Usage:

glpsol [options...] filename

For example, using the options in their long-form:

glpsol --cuts --fpump --mipgap 0.001 --model problem.mod --data problem.dat

Options
The following information is derived from the usage option --help.

General options: --mps            read LP/MIP problem in fixed MPS format --freemps        read LP/MIP problem in free MPS format (default) --lp             read LP/MIP problem in CPLEX LP format --glp            read LP/MIP problem in GLPK format --math           read LP/MIP model written in GNU MathProg modeling language -m filename, --model filename read model section and optional data section from filename (same as --math) -d filename, --data filename read data section from filename (for --math only); if model file also has data section, it is ignored -y filename, --display filename send display output to filename (for --math only); by default the output is sent to terminal --seed value     initialize pseudo-random number generator used in                     MathProg model with specified seed (any integer); if seed value is ?, some random seed will be used --mincost        read min-cost flow problem in DIMACS format --maxflow        read maximum flow problem in DIMACS format --simplex        use simplex method (default) --interior       use interior point method (LP only) -r filename, --read filename read solution from filename rather to find it with the solver --min            minimization --max            maximization --scale          scale problem (default) --noscale        do not scale problem -o filename, --output filename write solution to filename in printable format -w filename, --write filename write solution to filename in plain text format --ranges filename write sensitivity analysis report to filename in                    printable format (simplex only) --tmlim nnn      limit solution time to nnn seconds --memlim nnn     limit available memory to nnn megabytes --check          do not solve problem, check input data only --name probname  change problem name to probname --wmps filename  write problem to filename in fixed MPS format --wfreemps filename write problem to filename in free MPS format --wlp filename   write problem to filename in CPLEX LP format --wglp filename  write problem to filename in GLPK format --log filename   write copy of terminal output to filename -h, --help       display this help information and exit -v, --version    display program version and exit

LP basis factorization options: --luf            LU + Forrest-Tomlin update (faster, less stable; default) --cbg            LU + Schur complement + Bartels-Golub update (slower, more stable) --cgr            LU + Schur complement + Givens rotation update (slower, more stable)

Options specific to the simplex solver: --primal         use primal simplex (default) --dual           use dual simplex --std            use standard initial basis of all slacks --adv            use advanced initial basis (default) --bib            use Bixby's initial basis --ini filename   use as initial basis previously saved with -w (disables LP presolver) --steep          use steepest edge technique (default) --nosteep        use standard "textbook" pricing --relax          use Harris' two-pass ratio test (default) --norelax        use standard "textbook" ratio test --presol         use presolver (default; assumes --scale and --adv) --nopresol       do not use presolver --exact          use simplex method based on exact arithmetic --xcheck         check final basis using exact arithmetic

Options specific to the interior-point solver: --nord           use natural (original) ordering --qmd            use quotient minimum degree ordering --amd            use approximate minimum degree ordering (default) --symamd         use approximate minimum degree ordering

Options specific to the MIP solver: --nomip          consider all integer variables as continuous (allows solving MIP as pure LP) --first          branch on first integer variable --last           branch on last integer variable --mostf          branch on most fractional variable --drtom          branch using heuristic by Driebeck and Tomlin (default) --pcost          branch using hybrid pseudocost heuristic (may be                     useful for hard instances) --dfs            backtrack using depth first search --bfs            backtrack using breadth first search --bestp          backtrack using the best projection heuristic --bestb          backtrack using node with best local bound (default) --intopt         use MIP presolver (default) --nointopt       do not use MIP presolver --binarize       replace general integer variables by binary ones (assumes --intopt) --fpump          apply feasibility pump heuristic --gomory         generate Gomory's mixed integer cuts --mir            generate MIR (mixed integer rounding) cuts --cover          generate mixed cover cuts --clique         generate clique cuts --cuts           generate all cuts above --mipgap tol     set relative mip gap tolerance to tol

Options for CNF-SAT satisfiability problems: --cnf filename    read CNF-SAT problem in DIMACS format from filename --wcnf filename   write CNF-SAT problem in DIMACS format to filename --minisat         solve CNF-SAT problem with glp_infeas1 solver --objbnd bound    add inequality bounds to 0-1 feasibility problem (assumes --minisat)

Compressed files
The size of output files can be reduced by appending the suffix .gz. This indicates gzip compression. For instance:

glpsol ... --wlp squash.lp.gz

Similarly, GLPSOL will automatically decompress any file that it encounters that ends with the extension .gz.

Standard streams
GLPSOL supports the following three standard streams:


 * /dev/stdin
 * /dev/stdout
 * /dev/stderr

These are treated as special filenames by the GLPK I/O routines in a platform-independent manner. Hence the following command should work equally on Windows, Mac OS X, and Linux, delivering the solution report to the terminal instead of to a regular file:

glpsol .. --output "/dev/stdout"

Passing values via the command-line
If you need to pass a parameter value via the command-line, the following example shows how to do this using a shell script.

The shell script, either test.bat or test.sh, first creates a dynamic data file <tt>test.dat</tt>, which contains the required command-line value. The shell script then invokes GLPSOL with a hard-coded model name which, in this example, simply prints the value originally passed in from the command-line.

Observe that you can specify multiple data files within the shell script, for instance:

glpsol -m test.mod -d one.dat -d two.dat -d three.dat

With a little more ingenuity, a whole raft of information could be passed to the shell script and the script itself could exercise some intelligence when making its internal calls (cf. GLPK/Scripting_plus_MathProg).

xglpsol bash script
The <tt>xglpsol</tt> bash script (which you can rename to suit your needs) offers a simplified interface to the GLPSOL command-line solver. For example the command:

$ xglpsol -dkrsw short

produces and runs the GLPSOL call:

glpsol --scale --nopresol --nointopt --ranges "/dev/stdout" --output "/dev/stdout" --glp short.glpk

It then saves the screen capture to <tt>short.grab</tt> and diff's that against the previous screen capture file.

This script enables the user to rapidly change and view the effects of different GLPSOL options. Other GLPSOL options could be easily added, for instance, those governing MIP behavior. The help message from <tt>xglpsol</tt> is shown for reference purposes.

usage: xglpsol               model[.ext]     basic GLPSOL run xglpsol --            model[.ext]     basic GLPSOL run (for convenience) xglpsol -acdklmrswy   model[.ext]     extended run xglpsol --help                        display this message and exit (takes priority) run options:  -a                   implies -lms -c                  check model            --check -l                  add back LP presolve   --nopresol | --presol -m                  add back MIP presolve  --nointopt | --intopt -s                  add back scaling       --noscale  | --scale output options:  -d                   diff with the last available capture (implies -k) -k                  keep console output (with existing file backed up) -r                  display sensitivity analysis (simplex only)  --ranges -w                  display solution (includes KKT)              --output -y                  dry run, simply print the GLPSOL call extensions: model.glpk            GLPK problem      --glp model.lp              CPLEX LP problem  --lp model.mod             MathProg model    --math model.mps             free MPS problem  --freemps purpose: simplified interface to GLPK GLPSOL command-line solver hardcodes: GLPSOL utility            = glpsol default extension         = .glpk terminal capture extension = .grab diff call                 = diff --side-by-side --suppress-common-lines --width=167

The bash source can be copied from the collapsed table below. <tt>xglpsol</tt> is licensed under a Creative Commons BY-SA.

Using encrypted models
Model files may contain confidential data which deserves protection via encryption. A model file can easily be encrypted using the GNU Privacy Guard.

To avoid writing the decrypted model to disk it can be passed via a pipe to glpsol.

Set Xs; Set Ys; Param pcs {Ys, Xs}; Param pd {Xs}; Param ps {Ys};

Var vq{Ys, Xs} >= 0;

Minimize obj: Sum {I in Ys, j in Xs} pcs [i,j] * vq[i,j];

Subject to Ps {i in Ys}: Sum {j in Xs} Vq[i,j] <= ps [i];

Subject to Pd {j in Xs}: Sum {i in Ys} vq[i,j] = pd[j];

Solve; End;