{ "metadata": { "name": "", "signature": "sha256:bae1c53652e6c5deda42091aceffab7c30a2eeaf5486c48440c3cb36b7645f67" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 6, "metadata": {}, "source": [ "The latest version of this IPython notebook is available at [http://github.com/jckantor/ESTM60203](http://github.com/jckantor/ESTM60203) for noncommercial use under terms of the [Creative Commons Attribution Noncommericial ShareAlike License (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "J.C. Kantor (Kantor.1@nd.edu)" ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Getting Started with GNU MathProg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This [IPython notebook](http://ipython.org/notebook.html) describes the installation and use of GLPK/MathProg from an IPython notebook." ] }, { "cell_type": "heading", "level": 6, "metadata": {}, "source": [ "Initializations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.core.display import HTML\n", "HTML(open(\"styles/custom.css\", \"r\").read())" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "GNU MathProg is a Mathematical Programming Language" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mathematical programming languages are designed for the purpose of writing applied optimization problems in a concise, high-level, maintainable manner with sufficient precision to be translated and solved using optimization software.\n", "\n", "[GAMS](http://www.gams.com/) (the General Algebraic Modeling System) is generally cited as the first example of a commercially successful mathematical programming language. Since the introduction of GAMS in the late 1970's, a number of succesful languages have been produced including [AIMMS](http://business.aimms.com/), [AMPL](http://www.ampl.com/), [LINDO/LINGO](http://www.lindo.com/), [MPL](http://www.maximalsoftware.com/), [XPRESS-MOSEL](http://www.fico.com/en/products/fico-xpress-optimization-suite/), and many others. Of these, AMPL appears to be most widely adopted language for university training.\n", "\n", "[GNU MathProg](http://en.wikibooks.org/wiki/GLPK/GMPL_(MathProg)) is part of the open source [GNU GLPK project](http://www.gnu.org/software/glpk/). MathProg offers a subset of the AMPL language roughly equivalent to AMPL as it distributed in the early 1990's and described in the [AMPL book](http://www.ampl.com/BOOK/download.html). Though distributed as part of GLPK, MathProg interfaces are available for other solvers including [lpsolve](http://lpsolve.sourceforge.net/5.5/MathProg.htm) and COIN-OR CBC. MathProg can export models in a several formats compatiable with most commercial and non-commericial solvers for mixed-integer linear programs." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Installing GLPK/MathProg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You will need to install a working copy of GLPK before executing code cells in the following tutorial. Here some basic recommendations.\n", "\n", "1. For Windows/PC hardware, the [Windows for GLPK web site](http://winglpk.sourceforge.net/) maintains a pre-compiled version of GLPK based on the lastest official release.\n", "\n", "2. For MacOS users, the most convenient installation process is to use a package manager. If you are not already doing so, you may consider installing the excellect [Homebrew package manager](http://brew.sh/) using the instructions on their homepage. Once Homebrew is installed, GLPK can be installed with two commands\n", "\n", "
\n",
      "  brew tap homebrew/science\n",
      "  brew install glpk\n",
      "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If GLPK has been installed correctly on your machine, you should be able to execute the following command. Test this before going further with this tutorial." ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"Hello World\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello World\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "%%script glpsol -m /dev/stdin -o /dev/stdout --out output\n", "\n", "printf \"Hello, World\\n\";\n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin -o /dev/stdout\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:3: warning: final NL missing before end of file\n", "3 lines were read\n", "Hello, World\n", "Model has been successfully generated\n", "GLPK Simplex Optimizer, v4.52\n", "0 rows, 0 columns, 0 non-zeros\n", "~ 0: obj = 0.000000000e+00 infeas = 0.000e+00\n", "OPTIMAL SOLUTION FOUND\n", "Time used: 0.0 secs\n", "Memory used: 0.0 Mb (41523 bytes)\n", "Writing basic solution to `/dev/stdout'...\n", "Problem: stdin\n", "Rows: 0\n", "Columns: 0\n", "Non-zeros: 0\n", "Status: OPTIMAL\n", "Objective: 0 (MINimum)\n", "\n", " No. Row name St Activity Lower bound Upper bound Marginal\n", "------ ------------ -- ------------- ------------- ------------- -------------\n", "\n", " No. Column name St Activity Lower bound Upper bound Marginal\n", "------ ------------ -- ------------- ------------- ------------- -------------\n", "\n", "Karush-Kuhn-Tucker optimality conditions:\n", "\n", "KKT.PE: max.abs.err = 0.00e+00 on row 0\n", " max.rel.err = 0.00e+00 on row 0\n", " High quality\n", "\n", "KKT.PB: max.abs.err = 0.00e+00 on row 0\n", " max.rel.err = 0.00e+00 on row 0\n", " High quality\n", "\n", "KKT.DE: max.abs.err = 0.00e+00 on column 0\n", " max.rel.err = 0.00e+00 on column 0\n", " High quality\n", "\n", "KKT.DB: max.abs.err = 0.00e+00 on row 0\n", " max.rel.err = 0.00e+00 on row 0\n", " High quality\n", "\n", "End of output\n", "\n" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Using GLPK/MathProg in IPython Notebooks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Cell magics](http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/notebooks/Cell%20Magics.ipynb)\n", "provide mechanisms for using GLPK/MathProg inside the cells of an IPython notebook. \n", "\n", "To process a MathProg model from a cell, use the cell magic\n", "\n", "`%%script glpsol -m /dev/stdin` \n", "\n", "as the first line of the cell. This line uses the cell magic [`%%script`](http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/notebooks/Script%20Magics.ipynb) to run the command `glpsol -m /dev/stdin` as if it were entered directly into a terminal window. [`glpsol`](http://en.wikibooks.org/wiki/GLPK/Using_GLPSOL) calls the glpk solver. The argument `-m /dev/stdin` tells the solver to process a MathProg model from the standard input. In the case of IPython notebooks, is the remaining contents of the cell.\n", "\n", "We'll demonstrate this for a simple model that adds two parameter values and displays the result. Look for the displayed result among the other output generated by the `glpsol` command." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%script glpsol -m /dev/stdin\n", "\n", "param a := 12.3;\n", "param b := 13;\n", "\n", "display a + b;\n", "\n", "end;" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:7: warning: final NL missing before end of file\n", "7 lines were read\n", "Display statement at line 5\n", "25.3\n", "Model has been successfully generated\n", "GLPK Simplex Optimizer, v4.52\n", "0 rows, 0 columns, 0 non-zeros\n", "~ 0: obj = 0.000000000e+00 infeas = 0.000e+00\n", "OPTIMAL SOLUTION FOUND\n", "Time used: 0.0 secs\n", "Memory used: 0.0 Mb (49555 bytes)\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Often you will want to separate the display output of the MathProg model from other output generated by `glpsol`. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%script --out output glpsol -m /dev/stdin -y out.txt \n", "\n", "param a := 12.3;\n", "param b := 13;\n", "\n", "display a + b;\n", "\n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `-y out.txt` option redirects display output to the file `out.txt`. The file can be read and displayed using the usual python methods as shown here:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('out.txt')\n", "print f.read()\n", "f.close()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Display statement at line 5\n", "25.3\n", "\n" ] } ], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `--out output` is an option passed to script that redirects normal cell output to a python variable `output`. This will contain the remaining output of the `glpsol` command which can be displayed as follows:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin -y out.txt\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:7: warning: final NL missing before end of file\n", "7 lines were read\n", "Model has been successfully generated\n", "GLPK Simplex Optimizer, v4.52\n", "0 rows, 0 columns, 0 non-zeros\n", "~ 0: obj = 0.000000000e+00 infeas = 0.000e+00\n", "OPTIMAL SOLUTION FOUND\n", "Time used: 0.0 secs\n", "Memory used: 0.0 Mb (49602 bytes)\n", "\n" ] } ], "prompt_number": 7 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Solving Linear Equations with MathProg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "GLPK/MathProg will find feasible solutions to a system of linear equations. The basic steps necessary to describe and solve a system of linear equations are demonstrated in the next example." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%script --out output glpsol -m /dev/stdin\n", "\n", "# declare problem variables\n", "var x;\n", "var y;\n", "var z;\n", "\n", "# list all equations\n", "eqn1 : 3*x + 2*y + z = 12;\n", "eqn2 : 2.1*x + y = -3;\n", "eqn3 : y - z = 4;\n", "\n", "# solve\n", "solve;\n", "\n", "# display results\n", "display x, y, z;\n", "\n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "A few things to notice are that all unknowns must be declared as variables, and that all equations are written with a unique name followed by the equation itself.\n", "\n", "First we'll look at the diagnostic output generated by `glpsol`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:18: warning: final NL missing before end of file\n", "18 lines were read\n", "Generating eqn1...\n", "Generating eqn2...\n", "Generating eqn3...\n", "Model has been successfully generated\n", "GLPK Simplex Optimizer, v4.52\n", "3 rows, 3 columns, 7 non-zeros\n", "Preprocessing...\n", "3 rows, 3 columns, 7 non-zeros\n", "Scaling...\n", " A: min|aij| = 1.000e+00 max|aij| = 3.000e+00 ratio = 3.000e+00\n", "Problem data seem to be well scaled\n", "Constructing initial basis...\n", "Size of triangular part is 2\n", " 0: obj = 0.000000000e+00 infeas = 1.420e+01 (1)\n", "* 1: obj = 0.000000000e+00 infeas = 0.000e+00 (0)\n", "OPTIMAL LP SOLUTION FOUND\n", "Time used: 0.0 secs\n", "Memory used: 0.1 Mb (94191 bytes)\n", "Display statement at line 16\n", "x.val = -7.57575757575758\n", "y.val = 12.9090909090909\n", "z.val = 8.90909090909091\n", "Model has been successfully processed\n", "\n" ] } ], "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "If things went well we should see a line `OPTIMAL LP SOLUTION FOUND` along with additional information that is useful in tuning larger models for efficient solution. If things didn't go well, an appropriate message will be displayed indicating an error in processing the model description, or problems in finding a numerical solution.\n", "\n", "In this case `glpsol` says an optimal solution was found. The next step is to show the displayed results that were written to the file `out.txt`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('out.txt');\n", "print(f.read())\n", "f.close()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Display statement at line 5\n", "25.3\n", "\n" ] } ], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The extra `.val` appended to each variable name indicates that we are looking at value of the variable found by the solver. Also associated with each variable is a `.dual` value that will be useful in analyzing the results of linear optimization problems. " ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Reading Data from .csv Files" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%writefile input.csv\n", "Name, Age\n", "Abigail, 22.1\n", "Brent, 24.1\n", "Carla, 21.0\n", "Doug, 20.0" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Overwriting input.csv\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "%%script --out output glpsol -m /dev/stdin\n", "\n", "set NAMES;\n", "\n", "param Age{NAMES};\n", "\n", "table tin IN \"CSV\" \"input.csv\" : NAMES <- [Name], Age;\n", " \n", "for {n in NAMES}: printf \"%s\\n\", n;\n", " \n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:10: warning: final NL missing before end of file\n", "10 lines were read\n", "Reading tin...\n", "/dev/stdin:6: field Age missing in input table\n", "MathProg model processing error\n", "\n" ] } ], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "import pandas\n", "pandas.read_csv(\"input.csv\")" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Name Age
0 Abigail 22.1
1 Brent 24.1
2 Carla 21.0
3 Doug 20.0
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 14, "text": [ " Name Age\n", "0 Abigail 22.1\n", "1 Brent 24.1\n", "2 Carla 21.0\n", "3 Doug 20.0" ] } ], "prompt_number": 14 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Writing MathProg Output to .csv Files" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%script --out output glpsol -m /dev/stdin\n", "\n", "# declare problem variables\n", "var x;\n", "var y;\n", "var z;\n", "\n", "# list all equations\n", "eqn1 : 3*x + 2*y + z = 12;\n", "eqn2 : 2.1*x + y = -3;\n", "eqn3 : y - z = 4;\n", "\n", "# solve\n", "solve;\n", "\n", "# output results to .csv file\n", "table result {1..1} OUT \"CSV\" \"out.csv\" : x, y, z;\n", " \n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 15 }, { "cell_type": "markdown", "metadata": {}, "source": [ "First check the diagnostic output to verify that no errors were encountered." ] }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:18: warning: final NL missing before end of file\n", "18 lines were read\n", "Generating eqn1...\n", "Generating eqn2...\n", "Generating eqn3...\n", "Model has been successfully generated\n", "GLPK Simplex Optimizer, v4.52\n", "3 rows, 3 columns, 7 non-zeros\n", "Preprocessing...\n", "3 rows, 3 columns, 7 non-zeros\n", "Scaling...\n", " A: min|aij| = 1.000e+00 max|aij| = 3.000e+00 ratio = 3.000e+00\n", "Problem data seem to be well scaled\n", "Constructing initial basis...\n", "Size of triangular part is 2\n", " 0: obj = 0.000000000e+00 infeas = 1.420e+01 (1)\n", "* 1: obj = 0.000000000e+00 infeas = 0.000e+00 (0)\n", "OPTIMAL LP SOLUTION FOUND\n", "Time used: 0.0 secs\n", "Memory used: 0.1 Mb (94191 bytes)\n", "Writing result...\n", "Model has been successfully processed\n", "\n" ] } ], "prompt_number": 16 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The result of the `table` command is a `.csv` file that can be read by virtually any spreadsheet or data analysis software. Let's first verify the format" ] }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('out.csv');\n", "print(f.read())\n", "f.close()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "x,y,z\n", "-7.57575757575758,12.9090909090909,8.90909090909091\n", "\n" ] } ], "prompt_number": 17 }, { "cell_type": "markdown", "metadata": {}, "source": [ "As an example of it's use, here's how the file could be read as a pandas DataFrame and the results plotted." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import pandas\n", "df = pandas.read_csv(\"out.csv\");\n", "display(df)\n", "df.plot(kind='bar')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyz
0-7.575758 12.909091 8.909091
\n", "
" ], "metadata": {}, "output_type": "display_data", "text": [ " x y z\n", "0 -7.575758 12.909091 8.909091" ] }, { "metadata": {}, "output_type": "pyout", "prompt_number": 18, "text": [ "" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD7CAYAAAB68m/qAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADi9JREFUeJzt3V9sXFVix/HvXQcohTG20zRhYYUjq38WaRXTqlCpwDql\n26ZCaoSgQg5E4whQXhpE+7JleYj7R2oRAlWoKi8NGClVsHhoCYJaIZVHIFXazYoQAtp0WRNLyYbd\nVkocTwIPhEwfZuw4jk3suffMPXPn+5Gu4ntncu51Ev9y9Jszd0CSJEmSJEmSJEmSJEmSJKltvAz8\nEji64NgocBI43Ni2tP6yJEmrdQ9wB5cH+m7gr/K5HEnqTN/IYIz3gDNLHE8yGFuStEJZBP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xL9DrBhieM/AN5cxXlczqLCmp6ezvsS\nJODqgf69Jsb8OfCtBfu3No4tdiRJkk1NjC9F59VXX837EtQ5joQcfBL43QX7twMfANcCG4Ep8l3v\nLkm6igeAE8AXwC+A/1zw2A+ovxh6DPiT1l+aJEmS1KasQqTV+Tb1pblzK7dOAvuBn+R2RVKDb/iR\nVu771N9jAfDDxvaNxrGn87ooSdLqfQJcs8Txa6m/ZiTlyhm6tHJfsfSb5L7ZeEzK1dXWoUu65Cng\nIPXZ+InGsW8BvwH8RV4XJc3xRVFpdbqo35voFurvgP458GPgQp4XJUmSJEmSJEmSJEmSJEnt4f8B\nZBs7NNNqRp8AAAAASUVORK5CYII=\n", "text": [ "" ] } ], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "%%writefile input.csv\n", "A,B,C\n", "12.2, 13.1, 13.2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Overwriting input.csv\n" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "%%script --out output glpsol -m /dev/stdin\n", "\n", "set S;\n", "\n", "param a;\n", "param b;\n", "param c;\n", "\n", "table input IN \"CSV\" \"input.csv\": S <- [A], a~A, b~B, c~C;\n", " \n", "end;" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ "print output" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "GLPSOL: GLPK LP/MIP Solver, v4.52\n", "Parameter(s) specified in the command line:\n", " -m /dev/stdin\n", "Reading model section from /dev/stdin...\n", "/dev/stdin:8: a must have 1 subscript rather than 0\n", "Context: ...am b ; param c ; table input IN '...' '...' : S <- [ A ] , a\n", "MathProg model processing error\n", "\n" ] } ], "prompt_number": 21 } ], "metadata": {} } ] }