SCPSolver
-
Upload
hannes-planatscher -
Category
Documents
-
view
10.370 -
download
3
description
Transcript of SCPSolver
SCPSolver
Linear Programming in Java madeeasy
Overview
• What is Linear Programming?
• Why one would like to use it?
• What is SCPSolver (not)?
• Demo
– Modelling for Beginners
– Modelling for Advanced Users
Hannes Planatscher 2
Linear Optimization
• „Linear Programming is a technique for the optimization of a linear objective function subject to linear constraints.“
Hannes Planatscher 3
n
i
ii xc1
max
1
,1n
ij i j
i
a x b j m
subject to m linear constraints
n-dimensional linear objective function
Constraints define halfspaces
Hannes Planatscher 4
x1
x2
Constraints define halfspaces
Hannes Planatscher 5
x1
x2
Feasible region
Hannes Planatscher 6
x1
x2
feasible region
Location of global optima
Hannes Planatscher 7
x1
x2
feasible regionpotential optimum
potential optimum
potential optimum
potential optimum
If the linear program is
feasible and not
unbounded, the
optimum can be found
at a vertex, in special
cases also at an
edge, of the polytope.
Location of global optima
Hannes Planatscher 8
x1
x2
optimum
If the linear program is
feasible and not
unbounded, the
optimum can be found
at a vertex, in special
cases also at an
edge, of the polytope.
Location of global optima
9
x1
x2
optimum
If the linear program is
feasible and not
unbounded, the
optimum can be found
at a vertex, in special
cases also at an
edge, of the polytope.
Simplex
10
x1
x2
feasible regionpotential optimum
optimum
potential optimum
potential optimum
The Simplex
Algorithm visits one
vertex after another
until the optimum is
found.
Interior Point
11
x1
x2
feasible regionpotential optimum
optimum
potential optimum
potential optimum
Interior point
algorithms try find to
optimum starting from
within the feasible
region.
Integer Variables
12
x1
x2
Why use Linear Programming?
• Even if the Simplex Algorithm has exponentialworst case complexity, it is very fast in mostreal world scenarios.
• Very efficient solvers, which can solve linear (integer) programs with several 100.000 variables and constraints, exist.
• If possible, always try to reformulate youroptimization problem as a Linear Program.
Hannes Planatscher 13
Linear Programming in Java
• Using existing Linear Programming Solvers in Java programs is a pain, because of:
– platform dependency (.dll, .so, .jnilib)
– bad API s
– difficult deployment (where to put the libraries)
• You have to stick with its (usually bad) API, once you have chosen a solver.
Hannes Planatscher 14
SCPSolver
• Main goals– make it easy to develop
– keep the API lean
– get „platformindependent“
– automate binary librarydeployment
– separate modelling fromthe solver
• Not a goal: Write a newSolver in Java!
Hannes Planatscher 15
„Low-level“-Modelling
Hannes Planatscher 16
LinearProgram lp = new LinearProgram(new double[]{5.0,10.0});
lp.setMinProblem(true);
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{3.0,1.0}, 8.0, "c1"));
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{0.0,4.0}, 4.0, "c2"));
lp.addConstraint(new LinearSmallerThanEqualsConstraint(new double[]{2.0,0.0}, 2.0, "c3"));
LinearProgramSolver solver = SolverFactory.newDefault();
double[] sol = solver.solve(lp);
1 2min5.0 10.0x x
1 23.0 1.0 8.0x x
24.0 4.0x
12.0 2.0x
„High-Level“-Modelling
Hannes Planatscher 17
LPWizard lpw = new LPWizard();
lpw.plus("x1",5.0).plus("x2",10.0);
lpw.addConstraint("c1",8,"<=").plus("x1",3.0).plus("x2",1.0);
lpw.addConstraint("c2",4,"<=").plus("x2",4.0);
lpw.addConstraint("c3", 2, ">=").plus("x1",2.0);
System.out.println(lpw.solve());
1 2min5.0 10.0x x
1 23.0 1.0 8.0x x
24.0 4.0x
12.0 2.0x
Solver Packs
• Solvers
– lpsolve (Open Source)
– GLPK (Open Source)
– CPLEX (closed
• Platforms
– Linux 32/64-bit (tested: Ubuntu, Scientific Linux)
– Mac Os X 64-bit (> 10.5)
– Windows 32-bit(tested: XP)
Hannes Planatscher 18
solver_x86.dll
solver_x86.so
solver_x64.jnilib
JNI Interface to solver
Solver Pack Jar
Solver Packs
• All libraries are asstatically linked aspossible
• Minimal dependencies on execution environment.
• Advantage– packs runs instantly on
many systems
• Disadvantage– the solver packs are pretty
large (lpsolve 1.3 MB, GLPK 2.3 MB, CPLEX 19 MB)
Hannes Planatscher 19
solver_x86.dll
solver_x86.so
solver_x86.jnilib
JNI Interface to solver
Solver Pack Jar
Farming
• Need to decide how much tons of wheat and/or rye toproduce.
• Rye earns 198 Euro/ton, wheat 226 Euro/ton• Rye needs 0.2 ha/ton, wheat 0.15 ha/ton• Rye needs 50 labour-units/ton, wheat 80 labour-
units/ton.• 50 ha and 5000 labour-units available• There are two barns, which can store up to 30 and 65
tons of one type of crop.• Because of EU-Regulations we have to produce exact
integer tons of both crops.
Hannes Planatscher 20