Minizinc Handbook Release 2.3.1
Total Page:16
File Type:pdf, Size:1020Kb
MiniZinc Handbook Release 2.3.1 Peter J. Stuckey, Kim Marrio, Guido Tack Jul 10, 2019 Contents 1 Overview 3 1.1 Introduction 5 1.1.1 Structure ....................................... 5 1.1.2 How to Read This ................................... 6 1.2 Installation 7 1.2.1 Microsoft Windows .................................. 7 1.2.2 Linux .......................................... 8 1.2.2.1 Snap ...................................... 8 1.2.2.2 AppImage ................................... 8 1.2.2.3 Archive .................................... 9 1.2.3 Apple macOS ..................................... 9 1.2.4 Adding Third-party Solvers .............................. 9 1.3 First steps with MiniZinc 11 1.3.1 The MiniZinc IDE ................................... 11 1.3.2 The MiniZinc command line tool .......................... 16 2 A MiniZinc Tutorial 19 2.1 Basic Modelling in MiniZinc 21 2.1.1 Our First Example ................................... 21 2.1.2 An Arithmetic Optimisation Example ........................ 25 2.1.3 Datafiles and Assertions ............................... 26 2.1.4 Real Number Solving ................................. 29 2.1.5 Basic structure of a model .............................. 31 2.2 More Complex Models 35 2.2.1 Arrays and Sets .................................... 35 2.2.2 Global Constraints .................................. 45 2.2.3 Conditional Expressions ............................... 46 2.2.4 Enumerated Types .................................. 48 2.2.5 Complex Constraints ................................. 50 2.2.6 Set Constraints .................................... 56 2.2.7 Putting it all together ................................. 58 2.3 Predicates and Functions 61 2.3.1 Global Constraints .................................. 61 2.3.1.1 Alldifferent .................................. 61 2.3.1.2 Cumulative .................................. 61 2.3.1.3 Table ..................................... 63 2.3.1.4 Regular .................................... 65 i 2.3.2 Defining Predicates .................................. 68 2.3.3 Defining Functions .................................. 70 2.3.4 Reflection Functions ................................. 72 2.3.5 Local Variables .................................... 73 2.3.6 Context ........................................ 75 2.3.7 Local Constraints ................................... 76 2.3.8 Domain Reflection Functions ............................. 77 2.3.9 Scope ......................................... 79 2.4 Option Types 81 2.4.1 Declaring and Using Option Types .......................... 81 2.4.2 Hidden Option Types ................................. 82 2.5 Search 85 2.5.1 Finite Domain Search ................................. 85 2.5.2 Search Annotations .................................. 89 2.5.3 Annotations ...................................... 91 2.5.4 Restart ......................................... 92 2.5.5 Warm Starts ...................................... 94 2.6 Effective Modelling Practices in MiniZinc 97 2.6.1 Variable Bounds .................................... 97 2.6.2 Effective Generators ................................. 98 2.6.3 Redundant Constraints ................................100 2.6.4 Modelling Choices ..................................101 2.6.5 Multiple Modelling and Channels . 103 2.6.6 Symmetry .......................................105 2.6.6.1 Static Symmetry Breaking . 105 2.6.6.2 Other Examples of Symmetry . 107 2.7 Boolean Satisfiability Modelling in MiniZinc 109 2.7.1 Modelling Integers ..................................109 2.7.2 Modelling Disequality ................................110 2.7.3 Modelling Cardinality ................................111 2.8 FlatZinc and Flattening 119 2.8.1 Flattening Expressions ................................119 2.8.1.1 Simplification and Evaluation . 120 2.8.1.2 Defining Subexpressions . 120 2.8.1.3 FlatZinc constraint form . 121 2.8.1.4 Bounds analysis ................................121 2.8.1.5 Objectives ...................................122 2.8.2 Linear Expressions ..................................122 2.8.3 Unrolling Expressions .................................123 2.8.4 Arrays .........................................124 2.8.5 Reification .......................................126 2.8.6 Predicates .......................................129 2.8.7 Let Expressions ....................................131 3 User Manual 135 3.1 The MiniZinc Command Line Tool 137 ii 3.1.1 Basic Usage ......................................137 3.1.2 Adding Solvers ....................................138 3.1.2.1 Configuration files ..............................138 3.1.2.2 Configuration for MIP solvers . 139 3.1.3 Options ........................................139 3.1.3.1 General options ................................139 3.1.3.2 Solving options ................................140 3.1.3.3 Flattener input options ............................141 Flattener two-pass options . 142 Flattener output options ............................142 3.1.3.4 Solution output options . 143 3.1.4 User Configuration Files ...............................144 3.2 The MiniZinc IDE 147 3.2.1 Editing files ......................................147 3.2.1.1 Editing functions ...............................147 3.2.1.2 Fonts and dark mode .............................148 3.2.2 Configuring and Running a Solver . 148 3.2.2.1 Running a model ...............................148 3.2.2.2 Solver configurations .............................149 3.2.2.3 Automatic Solution Checking . 151 3.2.2.4 Compiling a model ..............................151 3.2.3 Working With Projects ................................152 3.2.4 Submitting Solutions to Online Courses . 152 3.2.5 Configuration Options ................................155 3.2.5.1 Locating the MiniZinc installation . 155 3.2.5.2 Adding Third-Party Solvers . 155 Configuring existing solvers . 155 Adding new solvers ...............................155 3.3 Solving Technologies and Solver Backends 159 3.3.1 Constraint Programming Solvers . 159 3.3.1.1 Gecode ....................................159 3.3.1.2 Chuffed ....................................159 3.3.1.3 OR-Tools ...................................160 3.3.2 Mixed-Integer Programming Solvers . 160 3.3.2.1 MIP-Aware Modeling (But Mostly Useful for All Backends) . 160 3.3.2.2 Useful Flattening Parameters . 161 3.3.2.3 Some Solver Options and Changed Default Values . 162 3.3.2.4 Subtour Elimination Constraints . 162 3.3.2.5 Unified Domains (MIPdomains) . 162 3.3.2.6 Indicator Constraints .............................162 3.3.2.7 Pools of User Cuts and Lazy Constraints . 163 3.3.2.8 Warm Starts ..................................163 3.3.3 Non-linear Solvers ..................................163 3.4 Automatic Solution Checking 165 3.4.1 Basic checker models .................................166 3.4.2 Detailed feedback ...................................167 3.4.3 Instance data in checker models . 169 3.4.4 Checking optimisation problems . 170 3.4.5 Hidden variables ...................................170 iii 3.5 Globalizer 173 3.5.1 Basic Usage ......................................173 3.5.2 Caveats ........................................175 3.5.3 Supported Constraints ................................175 3.5.4 Using Globalizer in the MiniZinc IDE . 176 3.5.5 How it works .....................................177 3.5.6 Performance tips ...................................178 3.5.7 Limitations / Future work ..............................179 3.6 FindMUS 181 3.6.1 Basic Usage ......................................181 3.6.1.1 Commandline arguments . 181 3.6.1.2 Example ....................................183 3.6.2 Using FindMUS in the MiniZinc IDE . 186 3.6.3 How it works .....................................189 3.6.4 Performance tips ...................................189 3.6.5 Limitations / Future work ..............................189 3.7 Using MiniZinc in Jupyter Notebooks 191 3.7.1 Installation ......................................191 3.7.2 Basic usage ......................................191 3.8 Python Interface 195 3.9 Installation from Source Code 197 3.9.1 Installation Instructions for Microsoft Windows . 197 3.9.1.1 MiniZinc ...................................197 3.9.1.2 MiniZinc IDE .................................198 3.9.1.3 Gecode ....................................198 3.9.1.4 Chuffed ....................................199 3.9.1.5 COIN-OR CBC ................................200 3.9.2 Installation Instructions for Linux and macOS . 201 3.9.2.1 MiniZinc ...................................201 3.9.2.2 MiniZinc IDE .................................201 3.9.2.3 Gecode ....................................202 3.9.2.4 OR Tools ...................................203 3.9.2.5 Chuffed ....................................203 3.9.2.6 COIN-OR CBC ................................204 3.9.2.7 SCIP ......................................205 3.9.3 Installation Instructions for Webassembly / JavaScript . 206 4 Reference Manual 207 4.1 Specification of MiniZinc 209 4.1.1 Introduction ......................................209 4.1.1.1 Original authors. ...............................210 4.1.2 Notation ........................................210 4.1.3 Overview of a Model .................................211 4.1.3.1 Evaluation Phases ..............................211 4.1.3.2 Run-time Outcomes .............................211 4.1.3.3 Output .....................................212 iv 4.1.4 Syntax Overview ...................................213 4.1.4.1 Character Set .................................213