Windowed Planning)
Total Page:16
File Type:pdf, Size:1020Kb
OptaPlanner User Guide The OptaPlanner team [http://www.optaplanner.org/community/team.html] OptaPlanner User Guide by Version 6.5.0.Final 1. OptaPlanner Introduction ............................................................................................ 1 1.1. What is OptaPlanner? ......................................................................................... 1 1.2. Requirements ..................................................................................................... 3 1.3. What is a Planning Problem? .............................................................................. 4 1.3.1. A Planning Problem is NP-complete or NP-hard ......................................... 4 1.3.2. A Planning Problem Has (Hard and Soft) Constraints ................................. 5 1.3.3. A Planning Problem Has a Huge Search Space ......................................... 5 1.4. Download and Run the Examples ........................................................................ 6 1.4.1. Get the Release .zip and Run the Examples .............................................. 6 1.4.2. Run the Examples in an IDE (IntelliJ, Eclipse, NetBeans) ............................ 9 1.4.3. Use OptaPlanner with Maven, Gradle, Ivy, Buildr or ANT .......................... 10 1.4.4. Build OptaPlanner from Source ............................................................... 11 1.5. Governance ...................................................................................................... 12 1.5.1. Status of OptaPlanner ............................................................................ 12 1.5.2. Backwards Compatibility ......................................................................... 12 1.5.3. Community and Support ......................................................................... 13 1.5.4. Relationship with Drools and jBPM .......................................................... 13 2. Quick Start ................................................................................................................. 15 2.1. Cloud Balancing Tutorial ................................................................................... 15 2.1.1. Problem Description ............................................................................... 15 2.1.2. Problem Size ......................................................................................... 16 2.1.3. Domain Model Design ............................................................................ 17 2.1.4. Main Method .......................................................................................... 18 2.1.5. Solver Configuration ............................................................................... 19 2.1.6. Domain Model Implementation ................................................................ 20 2.1.7. Score Configuration ................................................................................ 23 2.1.8. Beyond this Tutorial ............................................................................... 26 3. Use Cases and Examples .......................................................................................... 27 3.1. Examples Overview .......................................................................................... 27 3.2. Basic Examples ................................................................................................ 31 3.2.1. N Queens .............................................................................................. 31 3.2.2. Cloud Balancing ..................................................................................... 35 3.2.3. Traveling Salesman (TSP - Traveling Salesman Problem) ......................... 35 3.2.4. Dinner Party .......................................................................................... 36 3.2.5. Tennis Club Scheduling .......................................................................... 37 3.2.6. Meeting Scheduling ................................................................................ 38 3.3. Real Examples ................................................................................................. 39 3.3.1. Course Timetabling (ITC 2007 Track 3 - Curriculum Course Scheduling) .... 39 3.3.2. Machine Reassignment (Google ROADEF 2012) ...................................... 41 3.3.3. Vehicle Routing ...................................................................................... 44 3.3.4. Project Job Scheduling ........................................................................... 54 3.3.5. Hospital Bed Planning (PAS - Patient Admission Scheduling) .................... 57 3.4. Difficult Examples ............................................................................................. 60 3.4.1. Exam Timetabling (ITC 2007 track 1 - Examination) ................................. 60 iii OptaPlanner User Guide 3.4.2. Employee Rostering (INRC 2010 - Nurse Rostering) ................................. 64 3.4.3. Traveling Tournament Problem (TTP) ...................................................... 71 3.4.4. Cheap Time Scheduling ......................................................................... 74 3.4.5. Investment asset class allocation (portfolio optimization) ........................... 78 4. Planner Configuration ................................................................................................ 79 4.1. Overview .......................................................................................................... 79 4.2. Solver Configuration .......................................................................................... 80 4.2.1. Solver Configuration by XML .................................................................. 80 4.2.2. Solver Configuration by Java API ............................................................ 81 4.2.3. Annotations Configuration ....................................................................... 82 4.3. Model a Planning Problem ................................................................................ 84 4.3.1. Is This Class a Problem Fact or Planning Entity? ..................................... 84 4.3.2. Problem Fact ......................................................................................... 86 4.3.3. Planning Entity ....................................................................................... 87 4.3.4. Planning Variable ................................................................................... 90 4.3.5. Planning Value and Planning Value Range .............................................. 92 4.3.6. Shadow Variable .................................................................................. 100 4.3.7. Planning Problem and Planning Solution ................................................ 107 4.4. Use the Solver .............................................................................................. 115 4.4.1. The Solver Interface ............................................................................ 115 4.4.2. Solving a Problem ................................................................................ 116 4.4.3. Environment Mode: Are There Bugs in my Code? .................................. 117 4.4.4. Logging Level: What is the Solver Doing? ............................................. 119 4.4.5. Random Number Generator .................................................................. 122 5. Score Calculation ..................................................................................................... 123 5.1. Score Terminology .......................................................................................... 123 5.1.1. What is a Score? ................................................................................. 123 5.1.2. Score Constraint Signum (Positive or Negative) ...................................... 124 5.1.3. Score Constraint Weight ....................................................................... 125 5.1.4. Score Constraint Level (hard, soft, ...) .................................................... 127 5.1.5. Pareto Scoring (AKA Multi-objective Optimization Scoring) ...................... 129 5.1.6. Combining Score Techniques ................................................................ 131 5.1.7. Score interface ..................................................................................... 131 5.1.8. Avoid Floating Point Numbers in Score Calculation ................................. 132 5.2. Choose a Score Definition ............................................................................... 134 5.2.1. SimpleScore ......................................................................................... 134 5.2.2. HardSoftScore (Recommended) ............................................................ 134 5.2.3. HardMediumSoftScore .......................................................................... 135 5.2.4. BendableScore ..................................................................................... 135 5.2.5. Implementing a Custom Score .............................................................. 135 5.3. Calculate the Score ........................................................................................ 136 5.3.1. Score Calculation Types ....................................................................... 136 5.3.2. Easy Java Score Calculation ................................................................. 137 5.3.3. Incremental Java Score Calculation ......................................................