SlideShare a Scribd company logo
1 of 20
SCPSolver

Linear Programming in Java made
              easy
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 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
Constraints define halfspaces



 x2




            x1

           Hannes Planatscher   4
Constraints define halfspaces



 x2




            x1

           Hannes Planatscher   5
Feasible region



x2

     feasible region




                       x1

                   Hannes Planatscher   6
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
Location of global optima

                                         If the linear program is
                                         feasible and not
                                         unbounded, the
                                         optimum can be found
          optimum
                                         at a vertex, in special
x2                                       cases also at an
                                         edge, of the polytope.




                     x1

                    Hannes Planatscher                              8
Location of global optima

                      If the linear program is
                      feasible and not
                      unbounded, the
                      optimum can be found
            optimum
                      at a vertex, in special
x2                    cases also at an
                      edge, of the polytope.




                 x1

                                                 9
Simplex
                                                           The Simplex
                                                           Algorithm visits one
                                                           vertex after another
                                                           until the optimum is
                            optimum
                                                           found.
               x2

potential optimum                            potential optimum
                    feasible region




                                      potential optimum




                                      x1

                                                                                  10
Interior Point
                                                           Interior point
                                                           algorithms try find to
                                                           optimum starting from
                                                           within the feasible
                            optimum
                                                           region.
               x2

potential optimum                            potential optimum
                    feasible region




                                      potential optimum




                                      x1

                                                                                    11
Integer Variables



x2




           x1

                         12
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
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 „platform
     independent“
   – automate binary library
     deployment
   – separate modelling from
     the solver
• Not a goal: Write a new
  Solver in Java!

                        Hannes Planatscher   15
„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.0


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);




                                      Hannes Planatscher                            16
„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.0


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());




                                    Hannes Planatscher          17
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
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
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

More Related Content

Viewers also liked

Preterite: AR verbs
Preterite: AR verbs Preterite: AR verbs
Preterite: AR verbs NoeliaRG
 
Spanish 1 Semester project
Spanish 1 Semester projectSpanish 1 Semester project
Spanish 1 Semester projectNoeliaRG
 
Case Studies: Harnessing Speed for Competitive Advantage
Case Studies: Harnessing Speed for Competitive AdvantageCase Studies: Harnessing Speed for Competitive Advantage
Case Studies: Harnessing Speed for Competitive AdvantageVMware Tanzu
 
Microservices in the Enterprise: A Research Study and Reference Architecture
Microservices in the Enterprise: A Research Study and Reference ArchitectureMicroservices in the Enterprise: A Research Study and Reference Architecture
Microservices in the Enterprise: A Research Study and Reference ArchitectureJesus Rodriguez
 
Karmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemKarmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemAjay Dhamija
 
Helping Students Become More Self-Regulated Learners
Helping Students Become More Self-Regulated LearnersHelping Students Become More Self-Regulated Learners
Helping Students Become More Self-Regulated LearnersBradley Vaden
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonIgor Anishchenko
 
Cálculo de la edad gestacional
Cálculo de la edad gestacionalCálculo de la edad gestacional
Cálculo de la edad gestacionalHenry Bolaños
 
OpenFOAM-v3.0+ tutorials
OpenFOAM-v3.0+ tutorialsOpenFOAM-v3.0+ tutorials
OpenFOAM-v3.0+ tutorialsEtsuji Nomura
 
8. goal programming (program tujuan)
8. goal programming (program tujuan)8. goal programming (program tujuan)
8. goal programming (program tujuan)Nadia Rahmatul Ummah
 

Viewers also liked (10)

Preterite: AR verbs
Preterite: AR verbs Preterite: AR verbs
Preterite: AR verbs
 
Spanish 1 Semester project
Spanish 1 Semester projectSpanish 1 Semester project
Spanish 1 Semester project
 
Case Studies: Harnessing Speed for Competitive Advantage
Case Studies: Harnessing Speed for Competitive AdvantageCase Studies: Harnessing Speed for Competitive Advantage
Case Studies: Harnessing Speed for Competitive Advantage
 
Microservices in the Enterprise: A Research Study and Reference Architecture
Microservices in the Enterprise: A Research Study and Reference ArchitectureMicroservices in the Enterprise: A Research Study and Reference Architecture
Microservices in the Enterprise: A Research Study and Reference Architecture
 
Karmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemKarmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming Problem
 
Helping Students Become More Self-Regulated Learners
Helping Students Become More Self-Regulated LearnersHelping Students Become More Self-Regulated Learners
Helping Students Become More Self-Regulated Learners
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Cálculo de la edad gestacional
Cálculo de la edad gestacionalCálculo de la edad gestacional
Cálculo de la edad gestacional
 
OpenFOAM-v3.0+ tutorials
OpenFOAM-v3.0+ tutorialsOpenFOAM-v3.0+ tutorials
OpenFOAM-v3.0+ tutorials
 
8. goal programming (program tujuan)
8. goal programming (program tujuan)8. goal programming (program tujuan)
8. goal programming (program tujuan)
 

More from Hannes Planatscher

Unixkurs 04 - Rechteverwaltung
Unixkurs 04 - RechteverwaltungUnixkurs 04 - Rechteverwaltung
Unixkurs 04 - RechteverwaltungHannes Planatscher
 
Unixkurs 07 - Prozess- und Speicherverwaltung
Unixkurs 07 - Prozess- und SpeicherverwaltungUnixkurs 07 - Prozess- und Speicherverwaltung
Unixkurs 07 - Prozess- und SpeicherverwaltungHannes Planatscher
 
Unixkurs 01 - Allgemeines zu Unix
Unixkurs 01 - Allgemeines zu UnixUnixkurs 01 - Allgemeines zu Unix
Unixkurs 01 - Allgemeines zu UnixHannes Planatscher
 
Kombinatorische Optimierung für Immunoaffinitätsproteomik
Kombinatorische Optimierung für ImmunoaffinitätsproteomikKombinatorische Optimierung für Immunoaffinitätsproteomik
Kombinatorische Optimierung für ImmunoaffinitätsproteomikHannes Planatscher
 

More from Hannes Planatscher (8)

Unixkurs 04 - Rechteverwaltung
Unixkurs 04 - RechteverwaltungUnixkurs 04 - Rechteverwaltung
Unixkurs 04 - Rechteverwaltung
 
Unixkurs 03 - Pipes
Unixkurs 03 - PipesUnixkurs 03 - Pipes
Unixkurs 03 - Pipes
 
Unixkurs 06 - Shellskripte
Unixkurs 06 - ShellskripteUnixkurs 06 - Shellskripte
Unixkurs 06 - Shellskripte
 
Unixkurs 07 - Prozess- und Speicherverwaltung
Unixkurs 07 - Prozess- und SpeicherverwaltungUnixkurs 07 - Prozess- und Speicherverwaltung
Unixkurs 07 - Prozess- und Speicherverwaltung
 
Unixkurs 04 - Dateien
Unixkurs 04 - DateienUnixkurs 04 - Dateien
Unixkurs 04 - Dateien
 
Unixkurs 02 - VIM
Unixkurs 02 - VIMUnixkurs 02 - VIM
Unixkurs 02 - VIM
 
Unixkurs 01 - Allgemeines zu Unix
Unixkurs 01 - Allgemeines zu UnixUnixkurs 01 - Allgemeines zu Unix
Unixkurs 01 - Allgemeines zu Unix
 
Kombinatorische Optimierung für Immunoaffinitätsproteomik
Kombinatorische Optimierung für ImmunoaffinitätsproteomikKombinatorische Optimierung für Immunoaffinitätsproteomik
Kombinatorische Optimierung für Immunoaffinitätsproteomik
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 

SCPSolver

  • 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. 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. Constraints define halfspaces x2 x1 Hannes Planatscher 4
  • 5. Constraints define halfspaces x2 x1 Hannes Planatscher 5
  • 6. Feasible region x2 feasible region x1 Hannes Planatscher 6
  • 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. Location of global optima If the linear program is feasible and not unbounded, the optimum can be found optimum at a vertex, in special x2 cases also at an edge, of the polytope. x1 Hannes Planatscher 8
  • 9. Location of global optima If the linear program is feasible and not unbounded, the optimum can be found optimum at a vertex, in special x2 cases also at an edge, of the polytope. x1 9
  • 10. Simplex The Simplex Algorithm visits one vertex after another until the optimum is optimum found. x2 potential optimum potential optimum feasible region potential optimum x1 10
  • 11. Interior Point Interior point algorithms try find to optimum starting from within the feasible optimum region. x2 potential optimum potential optimum feasible region potential optimum x1 11
  • 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. 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. 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. „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.0 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); Hannes Planatscher 16
  • 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.0 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()); Hannes Planatscher 17
  • 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. 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. 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