{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline\n", "from pylab import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%%script glpsol -m /dev/stdin -o /dev/stdout -y display.txt --out output\n", "\n", "# Landhills Winery Case Study\n", "\n", "# sets\n", "set GRAPES;\n", "set WINES;\n", "set VARIETIES;\n", "set VINTAGES;\n", "set AREAS;\n", "\n", "# grape parameters (values are in the data section)\n", "param gVariety{GRAPES} symbolic;\n", "param gArea{GRAPES} symbolic;\n", "param gVintage{GRAPES} symbolic;\n", "param gAcidity{GRAPES};\n", "param gSugar{GRAPES};\n", "param gAlcohol{GRAPES};\n", "param gAvailable{GRAPES};\n", "param gCost{GRAPES};\n", "\n", "# wine parameters (values in the data section)\n", "param wVariety{WINES} symbolic;\n", "param wArea{WINES} symbolic;\n", "param wVintage{WINES} symbolic;\n", "param wAcidity{WINES};\n", "param wSugar{WINES};\n", "param wAlcohol{WINES};\n", "param wPrice{WINES};\n", "\n", "# decision variables\n", "var Revenue >= 0;\n", "var Cost >= 0;\n", "\n", "var wProduction{WINES} >= 0, <= 500000; # wine production in bottles\n", "var gConsumption{GRAPES} >= 0, <= 200000; # Grape consumption in bottles\n", "var x{WINES,GRAPES} >= 0, <= 200000, integer; # allocation of grapes to wines\n", "\n", "# Objective\n", "maximize Profit : Revenue - Cost;\n", "s.t. CostDef: Cost == sum{g in GRAPES} gCost[g]*gConsumption[g];\n", "s.t. RevenueDef: Revenue == sum{w in WINES} wPrice[w]*wProduction[w];\n", " \n", "# Relationships (if any) among the decision variables\n", "subject to grapes {g in GRAPES} : sum{w in WINES} x[w,g] == gConsumption[g];\n", "subject to wines {w in WINES} : sum{g in GRAPES} x[w,g] == wProduction[w];\n", "\n", "# Limits on Grape usage\n", "s.t. capacity {g in GRAPES} : gConsumption[g] <= gAvailable[g];\n", "\n", "# Varietal Content\n", "s.t. varietal {w in WINES} : sum{g in GRAPES : wVariety[w]<> '' && wVariety[w]==gVariety[g]} x[w,g] >= 0.75*wProduction[w];\n", "\n", "solve;\n", "\n", "printf \"Profit = %12.2f\\n\", Profit;\n", "printf \"Revenue = %12.2f\\n\", Revenue;\n", "printf \"Cost = %12.2f\\n\\n\", Cost;\n", "\n", "printf \" Wine Production \";\n", "printf {g in GRAPES} \" %10s \", g;\n", "printf \"\\n\";\n", "for {w in WINES} {\n", " printf \"%8s \", w;\n", " printf \"%10.1f \", wProduction[w];\n", " for {g in GRAPES} printf \" %10.1f\", x[w,g];\n", " printf \"\\n\";\n", "}\n", "printf \"Availability \";\n", "for {g in GRAPES} printf \" %10.1f \", gAvailable[g];\n", "\n", "\n", "data;\n", "\n", "set AREAS := 'SB', 'SLO';\n", "set VARIETIES := 'CabSav', 'Merlot';\n", "set VINTAGES := '2010', '2011';\n", "\n", "param : GRAPES : gVariety gArea gVintage gAcidity, gSugar, gAlcohol, gAvailable, gCost :=\n", "CS_SB_2011 CabSav SB 2011 0.35 0.12 13.5 50000 2.35 \n", "CS_SL_2010 CabSav SLO 2010 0.75 0.25 15.3 60000 2.60\n", "CS_SL_2011 CabSav SLO 2011 0.55 0.30 11.5 30000 2.10\n", "Mr_SB_2010 Merlot SB 2010 0.25 0.08 15.7 200000 1.55;\n", "\n", "param : WINES : wVariety wArea wVintage wAcidity, wSugar, wPrice :=\n", "wSB11 'CabSav' SB \"2011\" 0.7 0.2 9.00\n", "wSL10 CabSav SLO \"2010\" 0.7 0.2 9.00\n", "wSL11 CabSav SLO \"2011\" 0.7 0.2 9.00\n", "wCabS CabSav \"\" \"\" 0.7 0.2 6.50\n", "wMerl Merlot \"\" \"\" 0.3 1.0 2.95;\n", "\n", "end;\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(open('display.txt').read())" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print output" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }