Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Department of Mathematics and Computer Science May 6, 2010

University of Southern Denmark, Odense Marco Chiarandini

DM515 – Introduction to linear and integer


programming
Sheet 2, Spring 2010 [pdf format]

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.

The following instruction should help you to get started.

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;

maximize profit: 120 * x1 -57 * x2 - 9 * x3 - 24 * x4;

subto c1: -0.5 * x1 + 5.5 * x2 + 2.5 * x3 - 9 * x4 <= 0;


subto c2: -0.5 * x1 + 1.5 * x2 + 0.5 * x3 - x4 <= 0;
subto c3: x1 <= 1;

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

soplex -s0 -x example.lp

will show the value of the variables in the solution.

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)

user parameter file <scip.set> not found - using default parameters

SCIP> read example.lp


original problem has 4 variables (0 bin, 0 int, 0 impl, 4 cont) and 3 constraints
SCIP> optimize
...
SCIP Status : problem is solved [optimal solution found]
Solving Time (sec) : 0.00
Solving Nodes : 1
Primal Bound : +1.20000000000000e+02 (1 solutions)
Dual Bound : +1.20000000000000e+02
Gap : 0.00 %

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:

SCIP> display solution

objective value: 120


x1 1 (obj:120)

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

Bob is considering the following foods with corresponding nutritional values

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.

Create a .lp file

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:

g++ makesvg.cpp -o makesvg


makesvg 20points.txt 20points.sol

See the result:

firefox spgraph.svg

You might also like