Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SCPSolver

38,160 views

Published on

Presenting s

  • Be the first to comment

SCPSolver

  1. 1. SCPSolverLinear Programming in Java made easy
  2. 2. 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
  3. 3. Linear Optimization• „Linear Programming is a technique for the optimization of a linear objective function subject to linear objective function n-dimensional linear constraints.“ n max ci xi i 1 subject to m linear constraints n aij xi b j ,1 j m i 1 Hannes Planatscher 3
  4. 4. Constraints define halfspaces x2 x1 Hannes Planatscher 4
  5. 5. Constraints define halfspaces x2 x1 Hannes Planatscher 5
  6. 6. Feasible regionx2 feasible region x1 Hannes Planatscher 6
  7. 7. Location of global optima If the linear program is feasible and not unbounded, the optimum can be found potential optimum at a vertex, in special x2 cases also at an edge, of the polytope.potential optimum potential optimum feasible region potential optimum x1 Hannes Planatscher 7
  8. 8. Location of global optima If the linear program is feasible and not unbounded, the optimum can be found optimum at a vertex, in specialx2 cases also at an edge, of the polytope. x1 Hannes Planatscher 8
  9. 9. Location of global optima If the linear program is feasible and not unbounded, the optimum can be found optimum at a vertex, in specialx2 cases also at an edge, of the polytope. x1 9
  10. 10. Simplex The Simplex Algorithm visits one vertex after another until the optimum is optimum found. x2potential optimum potential optimum feasible region potential optimum x1 10
  11. 11. Interior Point Interior point algorithms try find to optimum starting from within the feasible optimum region. x2potential optimum potential optimum feasible region potential optimum x1 11
  12. 12. Integer Variablesx2 x1 12
  13. 13. Why use Linear Programming?• Even if the Simplex Algorithm has exponential worst case complexity, it is very fast in most real 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 your optimization problem as a Linear Program. Hannes Planatscher 13
  14. 14. 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
  15. 15. SCPSolver• Main goals – make it easy to develop – keep the API lean – get „platform independent“ – automate binary library deployment – separate modelling from the solver• Not a goal: Write a new Solver in Java! Hannes Planatscher 15
  16. 16. „Low-level“-Modelling min 5.0 x1 10.0 x2 3.0 x1 1.0 x2 8.0 4.0 x2 4.0 2.0 x1 2.0LinearProgram 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); Hannes Planatscher 16
  17. 17. „High-Level“-Modelling min 5.0 x1 10.0 x2 3.0 x1 1.0 x2 8.0 4.0 x2 4.0 2.0 x1 2.0LPWizard 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()); Hannes Planatscher 17
  18. 18. Solver Packs• Solvers Solver Pack Jar – lpsolve (Open Source) – GLPK (Open Source) JNI Interface to solver – CPLEX (closed solver_x64.jnilib• Platforms – Linux 32/64-bit (tested: solver_x86.so Ubuntu, Scientific Linux) – Mac Os X 64-bit (> 10.5) solver_x86.dll – Windows 32-bit(tested: XP) Hannes Planatscher 18
  19. 19. Solver Packs• All libraries are as statically linked as Solver Pack Jar possible JNI Interface to solver• Minimal dependencies on execution environment. solver_x86.jnilib• Advantage – packs runs instantly on solver_x86.so many systems• Disadvantage solver_x86.dll – the solver packs are pretty large (lpsolve 1.3 MB, GLPK 2.3 MB, CPLEX 19 MB) Hannes Planatscher 19
  20. 20. Farming• Need to decide how much tons of wheat and/or rye to produce.• 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

×