0% found this document useful (0 votes)
57 views55 pages

ThanhLX VJU OR ZimplScip

The document provides a comprehensive guide on solving linear and integer programming problems using ZIMPL and SCIP. It introduces the necessity of computational software for large linear programs, presents examples such as the Diet problem of Stigler, and outlines installation and usage procedures for ZIMPL and SCIP. Additionally, it includes simple and advanced examples to demonstrate the application of these tools in real-life scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views55 pages

ThanhLX VJU OR ZimplScip

The document provides a comprehensive guide on solving linear and integer programming problems using ZIMPL and SCIP. It introduces the necessity of computational software for large linear programs, presents examples such as the Diet problem of Stigler, and outlines installation and usage procedures for ZIMPL and SCIP. Additionally, it includes simple and advanced examples to demonstrate the application of these tools in real-life scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

.

Solving Linear Programs and Integer Programs


. with ZIMPL and SCIP

Lê Xuân Thanh
Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
Introduction

Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
Introduction

The need of having LP solvers

Linear programs in real-life often have large sizes

Human computational performance is limited

Era of industry 4.0

⇒ The need of computational softwares


Introduction

Example: Diet problem of Stigler2

Posed by Stigler in 19451 :


For a moderately active man (economist) weighing 154 pounds,
how much of each of 77 foods should be eaten on a daily basis
so that the man’s intake of nine nutrients (including calories)
will be at least equal to the recommended dietary allowances
(RDAs) suggested by the National Research Council in 1943,
with the cost of the diet being minimal?

1
G. J. Stigler. The cost of subsistence. Journal of Farm Economics,
27(2):303–314, 1945
2
George Joseph Stigler (17.01.1911-01.12.1991): an American economist,
Nobel Memorial Prize in Economic Sciences 1982
Introduction

Example: Diet problem of Stigler (cont.)


Introduction

Example: Diet problem of Stigler (cont.)


Nutrients and prices of 77 foods (in USD, year 1945)
https :// github .com/ lxthanh 86/ StiglerDiet

Solution of Stigler
Introduction

Example: Diet problem of Stigler (cont.)

Stigler did not use simplex method

Need 9 accountants working in 120 days


to solve by hand using Stigler’s method

By SCIP: 0.01 second!


Introduction to ZIMPL and SCIP What and Why

Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
Introduction to ZIMPL and SCIP What and Why

From real-life problems to their solutions

Many real-life problems can be formulated as linear programs.

ZIMPL SCIP
*.mps
(LP) solution
*.lp
Introduction to ZIMPL and SCIP What and Why

What is ZIMPL?

ZIMPL
*.mps
(LP) *.lp

Prof. Thorsten Koch

ZIMPL3 :
Zuse Institut Mathematical Programming Language
[Link]

3
Thorsten Koch. Rapid Mathematical Programming. PhD thesis, Technische
Universität Berlin, 2004
Introduction to ZIMPL and SCIP What and Why

Alternatives for ZIMPL

Name Full name URL


AIMMS Advanced Integrated Multi-dimensional Modeling Software [Link]
AMPL A Modeling Language for Mathematical Programming [Link]
GAMS General Algebraic Modeling System [Link]
LINGO Lingo [Link]
LPL (Linear|Logical|Literate) Programming Language [Link]
MINOPT Mixed Integer Non-linear Optimizer [Link]/MINOPT
MOSEL Mosel [Link]
MPL Mathematical Programming Language [Link]
OMNI Omni [Link]
OPL Optimization Programming Language [Link]
GNU-MP GNU Mathematical Programming Language [Link]/software/glpk
Introduction to ZIMPL and SCIP What and Why

Why ZIMPL?

Special features of ZIMPL:

Free, open source

Independent of solver

Infinite rational

Easy to install, easy to use


Introduction to ZIMPL and SCIP What and Why

What is SCIP?

*.mps SCIP
solution
*.lp

Dr. Tobias Achterberg

SCIP4 :
Solving Constraint Integer Programs
[Link]

4
Tobias Achterberg. Constraint Integer Programming. PhD thesis,
Technische Universität Berlin, 2007
Introduction to ZIMPL and SCIP What and Why

Alternatives for SCIP

Name Full name URL


CBC COIN Branch and Cut [Link]/Cbc/
GLPL GNU Linear Programming Kit [Link]/software/glpk/
MIPCL Mixed Integer Programming Class Library
SoPlex Sequential object-oriented simPlex [Link]
Xpress FICO Xpress optimizer [Link]/en/products/fico-xpress-solver
CPLEX IBM CPLEX Optimizer [Link]/analytics/cplex-optimizer
GUROBI GUROBI [Link]/
Introduction to ZIMPL and SCIP What and Why

Why SCIP?

Special features of SCIP:

Free, open source

Fastest among free solvers

Easy to install, easy to use


Introduction to ZIMPL and SCIP What and Why

Why SCIP?

[Link]
Introduction to ZIMPL and SCIP What and Why

Why SCIP?

Locations of registered institutes


([Link]
Introduction to ZIMPL and SCIP Install on Windows

Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
Introduction to ZIMPL and SCIP Install on Windows

Download ZIMPL and SCIP

Step 1: Click
https :// www. scipopt .org/ index .php# download
then choose Version 8.0.3 (latest version) and OS Windows
Introduction to ZIMPL and SCIP Install on Windows

Download ZIMPL and SCIP (cont.)


Step 2: Go to Precompiled Packages and choose
[Link]
(for Windows 64 bits)
[Link]
(for Windows 32 bits)
Introduction to ZIMPL and SCIP Install on Windows

Download ZIMPL and SCIP (cont.)


Step 3: Register before downloading
Introduction to ZIMPL and SCIP Install on Windows

Install ZIMPL and SCIP

Step 4: Find the downloaded file and double click


Introduction to ZIMPL and SCIP Install on Windows

Install ZIMPL and SCIP (cont.)


Step 5: In case of unrecognized app:
choose More info then Run anyway
and follow default instruction
Introduction to ZIMPL and SCIP Install on Windows

Install ZIMPL and SCIP (cont.)


Step 5: In case of unrecognized app:
choose More info then Run anyway
and follow default instruction
Introduction to ZIMPL and SCIP Install on Windows

Install ZIMPL and SCIP (cont.)

Step 6: Go to
C: \Program Files \SCIPOptSuite 8.0.3 \bin
and copy 3 files: [Link], [Link], [Link]
Introduction to ZIMPL and SCIP Install on Windows

Install ZIMPL and SCIP (cont.)

Step 7: Create a folder (should be on Desktop)


and paste 3 files: [Link], [Link], [Link] into this folder
How to use ZIMPL and SCIP Procedure

Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
How to use ZIMPL and SCIP Procedure

Procedure

Step 1:
In the folder containing 3 files [Link], [Link], [Link],
create a text file *.zpl in which * is the file name

Step 2:
In file *.zpl, write down the ZIMPL code
for the linear program to be solved
(see examples later)
How to use ZIMPL and SCIP Procedure

Procedure (cont.)

Step 3:
Go to the title box of the folder, type cmd then hit Enter
(to open Command Prompt terminal)
How to use ZIMPL and SCIP Procedure

Procedure (cont.)
Step 4:
In Command Prompt terminal, type the commands
zimpl *.zpl then scip -q -f *.lp -l *.out
in which * is the file name
How to use ZIMPL and SCIP Procedure

Procedure (cont.)

Step 5:
Find solution in file *.out in the same folder
How to use ZIMPL and SCIP Simple examples

Contents

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
How to use ZIMPL and SCIP Simple examples

Example 1

Solve

max 50x1 +42x2


s.t. x1 + x2 ≤ 40
x1 ≤ 30
x2 ≤ 30
x1 ≥ 0
x2 ≥ 0
How to use ZIMPL and SCIP Simple examples

ZIMPL code
ZIMPL code:

Program:

max 50x1 + 42x2


subject to
x1 + x2 ≤ 40
x1 ≤ 30
x2 ≤ 30
x1 ≥ 0
x2 ≥ 0
How to use ZIMPL and SCIP Simple examples

Structure of ZIMPL code


Structure:
Code:
Comment lines start with #

Declare variables
var [Declare variables];

Objective:
maximize [Name]: [Objective];
or
minimize [Name]: [Objective];

Constrains:
subto [Name]: [Constraints];

Remark:
Names of variables, objective, constraints
start with alphabet characters
How to use ZIMPL and SCIP Simple examples

Results obtained by SCIP


How to use ZIMPL and SCIP Simple examples

Example 2

Solve the following LP by using ZIMPL and SCIP:

max 5x1 + 4x2 + 3x3


s.t. 2x1 + 3x2 + x3 ≤ 5
4x1 + x2 + 2x3 ≤ 11
3x1 + 4x2 + 2x3 ≤ 8
x1 , x2 , x3 ≥ 0
How to use ZIMPL and SCIP Simple examples

Example 3

Solve the following LP by using ZIMPL and SCIP:

max 10x1 + 12(x2 + y2 ) + 17(x3 + y3 ) + 8(x4 + y4 )


s.t. 10x1 + 13x2 + 15x3 + 9x4 ≤ 1995
25x1 + 20y2 + 27y3 + 33y4 ≤ 1953
0.1x1 + 0.15(x2 + y2 ) + 0.5(x3 + y3 ) + 0.05(x4 + y4 ) ≤ 50
x2 + y2 = 2(x3 + y3 )
x1 , x2 , x3 , x4 ≥ 0
y2 , y3 , y4 ≥ 0
How to use ZIMPL and SCIP Advanced examples

Content

1. Introduction

2. Introduction to ZIMPL and SCIP


What and Why
Install on Windows

3. How to use ZIMPL and SCIP


Procedure
Simple examples
Advanced examples
How to use ZIMPL and SCIP Advanced examples

Outline

Stigler’s diet problem

Sudoku
How to use ZIMPL and SCIP Advanced examples

[Recall] Stigler’s diet problem


For a moderately active man (economist) weighing 154 pounds,
how much of each of 77 foods should be eaten on a daily basis
so that the man’s intake of nine nutrients (including calories)
will be at least equal to the recommended dietary allowances
(RDAs) suggested by the National Research Council in 1943,
with the cost of the diet being minimal?

Data:
Lists of 77 foods and 9 nutrients
RDAs of 9 nutrients
Amounts of nutrients in each of 77 foods
Price of 77 foods (in USD, year 1945)
See [S1945]5 or
https :// github .com/ lxthanh 86/ StiglerDiet
5
G. J. Stigler. The cost of subsistence. Journal of Farm Economics,
27(2):303–314, 1945
How to use ZIMPL and SCIP Advanced examples

Model
Data:
F: set of 77 foods (file [Link])
N: set of 9 nutrients (file [Link])
an : RDA of nutrient n ∈ N per day
(file [Link])
dfn : amount of nutrient n ∈ N in each unit of food f ∈ F
(file [Link], in USD)
Variables:
xf = payment (in USD) to buy food f ∈ F in the diet
Model:

min xf
f∈F

s.t. dfn xf ≥ an ∀n ∈ N
f∈F
xf ≥ 0 ∀f ∈ F
How to use ZIMPL and SCIP Advanced examples

ZIMPL code

To show in Control Prompt terminal.


How to use ZIMPL and SCIP Advanced examples

Result obtained by SCIP

solution status: optimal solution found


objective value: 0.108662278206757
x$WheatFlour(Enriched) 0.0295190616764883 (obj:1)
x$Liver(Beef) 0.00189255729070527 (obj:1)
x$Cabbage 0.0112144352461449 (obj:1)
x$Spinach 0.0050076604667252 (obj:1)
x$NavyBeansDried 0.0610285635266932 (obj:1)
How to use ZIMPL and SCIP Advanced examples

Outline

Stigler’s diet problem

Sudoku
How to use ZIMPL and SCIP Advanced examples

Sudoku puzzle
Given a 9 × 9 grid (as a composition of nine 3 × 3 subgrids).
Rules:
Only digits from 1 to 9 can be filled in the grid
Each cell of the grid must be filled by exactly one digit
Each digit appears exactly once in each column, row, and 3 × 3 subgrid
Input: a partially complete grid
Objective: completely fill the grid
8 9
1 3 9
5 2 4
2 6 8
9 7 6 5
3 6 5
1 3 5
8 7 1
4 5
How to use ZIMPL and SCIP Advanced examples

Sudoku puzzle
Given a 9 × 9 grid (as a composition of nine 3 × 3 subgrids).
Rules:
Only digits from 1 to 9 can be filled in the grid
Each cell of the grid must be filled by exactly one digit
Each digit appears exactly once in each column, row, and 3 × 3 subgrid
Input: a partially complete grid
Objective: completely fill the grid
3 6 7 4 2 5 8 9 1
4 2 1 3 8 9 5 7 6
8 5 9 6 7 1 2 3 4
5 7 4 1 3 2 6 8 9
9 1 8 7 4 6 3 2 5
2 3 6 5 9 8 4 1 7
1 8 3 9 6 4 7 5 2
6 9 2 8 5 7 1 4 3

7 4 5 2 1 3 9 6 8
How to use ZIMPL and SCIP Advanced examples

SudokuIMH: a Sudoku solver


How to use ZIMPL and SCIP Advanced examples

Variables

(1, 1)

(9, 9)

{
1 if k is filled into cell (i, j)
xijk =
0 otherwise
How to use ZIMPL and SCIP Advanced examples

A mathematical formulation for Sudoku

G = {(i, j, k) | k is already filled into cell (i, j)}


S = {1, . . . , 9}, N = {1, . . . , 3}
Formulations:
xijk = 1 ∀(i, j, k) ∈ G

9
xijk = 1 ∀i ∈ S, j ∈ S
k=1

9
xijk = 1 ∀j ∈ S, k ∈ S
i=1

9
xijk = 1 ∀i ∈ S, k ∈ S
j=1


3q ∑
3p
xijk = 1 ∀k ∈ S, p ∈ N, q ∈ N
j=3q−2 i=3p−2

xijk ∈ {0, 1} ∀i ∈ S, j ∈ S, k ∈ S
How to use ZIMPL and SCIP Advanced examples

Data file

8 9
1 3 9
5 2 4
2 6 8
9 7 6 5
3 6 5
1 3 5
8 7 1
4 5
How to use ZIMPL and SCIP Advanced examples

ZIMPL model
How to use ZIMPL and SCIP Advanced examples

(First part of) result obtained by SCIP

3 6 7 4 2 5 8 9 1
4 2 1 3 8 9 5 7 6
8 5 9 6 7 1 2 3 4
5 7 4 1 3 2 6 8 9
9 1 8 7 4 6 3 2 5
2 3 6 5 9 8 4 1 7
1 8 3 9 6 4 7 5 2
6 9 2 8 5 7 1 4 3

7 4 5 2 1 3 9 6 8
Thanks

Thank you for your attention!

You might also like