Professional Documents
Culture Documents
DM515 - Introduction To Linear and Integer Programming: Sheet 2, Spring 2010
DM515 - Introduction To Linear and Integer Programming: Sheet 2, Spring 2010
The exercises in this assignment sheet will be carried out in class during exercise session of April
23th to be hold in IMADA’s terminal room. Make sure you have read the assignment, wrote the
models on paper and skimmed through the ZIMPL documentation before the session.
This assignment has the goal of introducing the students to mathematical modelling languages.
Mathematical modelling languages allow to write in an easy and compact way LP/MIP problems
and to feed them in opportune forms to MIP/LP solvers.
The most famous mathematical programming languages are AMPL, GAMS, ZIMPL and GNU
MathProg. Beside customizations for the specific solver with which they are associated, most of
them allow to export the model in .lp or .mps format that is almost universal among the various
solver systems.
In this course, we will use the ZIB Optimization Suite developed by the Zuse Institute in Berlin.
It consists of a set of tools called ZIMPL/SoPlex/SCIP to model and solve Linear and Integer
Linear Programming problems.
ZIMPL is a command-line tool that takes a mathematical formulation (written in the ZIMPL
language) of a MIP/LP and outputs a file in .lp or .mps format. The .lp and .mps-format
are standard formats that can be read by most existing MIP/LP solvers.
SoPlex is a command-line LP-solver. It can read a LP-file (with only real variables) and display
the solution. SoPlex is an implementation of the revised simplex algorithm. It features
primal and dual solving routines for linear programs and is implemented as a C++ class
library that can be used with other programs. It is also used internally by SCIP when
solving IP problems. It can solve stand alone linear programs given in MPS or LP format.
SCIP is a command-line MIP solver (but can of course also solve LPs). It will read a LP-file
(or alternatively a ZIMPL-file directly) and solve the model and display the found solution
(if one exists and the model can be solved in reasonable time). During the process it will
report various statistics.
The ZIBOPT suite is free for academic use. There is a multitude of other software for solving
LP/IP problems. For a guide to many others optimization software you may consult the NEOS
Server for Optimization.
The ZIBOPT suite should be installed in any machines of the IMADA terminal room. If problems
arise please consult the teacher holding the exercise session.
ZIMPL syntax highlightning are available for Emacs and Kate. (With Emacs put zimpl-mode.el
in $HOME/.lisp/ and add (load "$HOME/.lisp/zimpl-mode") anywhere in your .emacs(.el)
config file.
1
DM515 – Spring 2010 Assignment Sheet
Exercise 1
Model the formulation of the LP problem of Exercise 1 in the Assignment Sheet 1 using ZIMPL.
Documentation about ZIMPL can be found in the ZIMPL user guide.
ZIBsuite is installed in
/opt/ziboptsuite-1.2.0
and should run by typing scip, soplex, zimpl from command line. Otherwise, you may try
directly with:
/opt/ziboptsuite-1.2.0/zimpl-3.0.0/zimpl
/opt/ziboptsuite-1.2.0/scip-1.2.0/scip
/opt/ziboptsuite-1.2.0/soplex-1.4.2/soplex
To get started here is a tiny example. First create (using your favourite text editor) a text-file
named example.zpl with the following content.
var x1 real >= 0;
var x2 real >= 0;
var x3 real >= 0;
var x4 real >= 0;
You may recognize the problem given by Chvátal that constitute the smallest example of a
problem with risk of cycling for the simplex algorithm with largest coefficient pivoting rule.
To solve the problem with SoPlex you need first to transform it in .lp or .mps format using zimpl.
$ zimpl example.zpl
$ soplex example.lp
************************************************************************
* SoPlex --- the Sequential object-oriented simPlex. Release 1.4.1 *
* Copyright (C) 1997-2009 Zuse Institute Berlin *
************************************************************************
... some output ...
Solution value is: 1.2000000e+02
Luckily, SoPlex does not cycle. To control some features of SoPlex see
soplex --help
In particular,
2
DM515 – Spring 2010 Assignment Sheet
Alternatively, you can parse directly the ZIMPL file by using SCIP
$ scip example.zpl
or interactively
$ scip
SCIP version 1.1.0 [mode: optimized] [LP solver: SoPlex 1.4.0]
Copyright (c) 2002-2008 Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)
SCIP calls internally SoPlex and finds the optimal solution to the LP problem. Explanation of
the information in the output display is available here. To show the solution:
Help for SCIP can be found by issuing the command help to SCIP.
SCIP> help
All of the above can also be done directly and in one command on the command-line by running
$ scip -f example.zpl
Exercise 2
Diet Problem Bob wants to plan a nutritious diet, but he is on a limited budget, so he wants to
spend as little money as possible. His nutritional requirements are as follows:
2000 Kcal
55 g protein
800 mg calcium
3
DM515 – Spring 2010 Assignment Sheet
Serving Size Energy (Kcal) Protein (g) Calcium (mg) Price per serving
Oatmeal 28 g 0.3 110 4 2
Chicken 100 g 2.4 205 32 12
Eggs 2 large 1.3 160 13 54
Milk 237 cc 0.9 160 8 285
Pie 170 g 2 420 4 22
Pork 260 g 1.9 260 14 80
With the help of ZIBOPT suite, find the number of servings of each type of food in the diet.
You find the data above together with an initial ZIMPL model to complete in the repository:
http://www.imada.sdu.dk/~marco/DM515/Files
The Pill Salesman A pill salesman offers Bob energy, protein, and calcium pills to fulfill his
nutritional needs. He needs to estimate the prices of units of serving, that is, the cost of 1 kcal,
the cost of 1 g of protein, the cost of 1 mg of calcium. He wants to make as much money as
possible, given Bob’s constraints. He knows that Bob wants 2000 kcal, 55 g protein, and 800 mg
calcium. How can we help him in guaranteeing that he does not make a bad deal?
Exercise 3
Model the shortest path problem as an LP problem. Write the model in zimpl using the skeleton
sp.zpl available from the directory SP of http://www.imada.sdu.dk/~marco/DM515/Files/ that
reads data from 20points.txt.
zimpl sp.zpl
Solve the LP problem in soplex and parse the output so that the solution is put in a file
20points.sol:
soplex -x sp.lp | cut -s --fields=1 | cut -s -d "#" --fields=2-3 | sed s/"#"/" "/ > 20points.sol
Compile and run the C++ program to create an svg file to visualize the solution:
firefox spgraph.svg