+ All Categories
Home > Documents > IBM ILOG CPLEX Optimization Studio...

IBM ILOG CPLEX Optimization Studio...

Date post: 27-Jan-2021
Category:
Upload: others
View: 16 times
Download: 1 times
Share this document with a friend
564
IBM ILOG CPLEX Optimization Studio CPLEX User’s Manual Version 12 Release 6
Transcript
  • IBM ILOG CPLEX Optimization StudioCPLEX User’s ManualVersion 12 Release 6

    ���

  • IBM ILOG CPLEX Optimization StudioCPLEX User’s ManualVersion 12 Release 6

    ���

  • Copyright noticeDescribes general use restrictions and trademarks related to this document and the software described in this document.

    © Copyright IBM Corp. 1987, 2015

    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract withIBM Corp.

    Trademarks

    IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp.,registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or othercompanies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" atwww.ibm.com/legal/copytrade.shtml.

    Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of AdobeSystems Incorporated in the United States, and/or other countries.

    Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.

    UNIX is a registered trademark of The Open Group in the United States and other countries.

    Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States,other countries, or both.

    Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.

    Other company, product, or service names may be trademarks or service marks of others.

    Additional registered trademarks, copyrights, licenses

    IBM ILOG CPLEX states these additional registered trademarks, copyrights, and acknowledgements.

    Python is a registered trademark of the Python Software Foundation.

    MATLAB is a registered trademark of The MathWorks, Inc.

    OpenMPI is distributed by The Open MPI Project under the New BSD license and copyright 2004 - 2012.

    MPICH2 is copyright 2002 by the University of Chicago and Argonne National Laboratory.

    © Copyright IBM Corporation 1987, 2015.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    Meet CPLEX . . . . . . . . . . . . xiiiWhat is CPLEX? . . . . . . . . . . . . xiiiWhat does CPLEX do? . . . . . . . . . . xiiiWhat you need to know . . . . . . . . . . xvExamples online. . . . . . . . . . . . . xvNotation in this manual . . . . . . . . . . xviiRelated documentation . . . . . . . . . . xviiiOnline services . . . . . . . . . . . . . xxFurther reading . . . . . . . . . . . . . xx

    Part 1. Languages and APIs . . . . . 1

    Chapter 1. Concert Technology for C++users . . . . . . . . . . . . . . . . 3Overview . . . . . . . . . . . . . . . 3Architecture of a CPLEX C++ application. . . . . 3Compiling and linking . . . . . . . . . . . 4Creating a C++ application with Concert Technology 4Modeling an optimization problem with ConcertTechnology . . . . . . . . . . . . . . . 5

    Overview . . . . . . . . . . . . . . 5Creating the environment: IloEnv . . . . . . 5Defining variables and expressions: IloNumVar. . 6Declaring the objective: IloObjective . . . . . 7Adding constraints: IloConstraint and IloRange. . 7Formulating a problem: IloModel . . . . . . 7Managing data . . . . . . . . . . . . 8

    Solving the model . . . . . . . . . . . . 9Overview . . . . . . . . . . . . . . 9Extracting a model . . . . . . . . . . . 10Invoking a solver . . . . . . . . . . . 11Choosing an optimizer. . . . . . . . . . 11Controlling the optimizers . . . . . . . . 13

    Accessing solution information . . . . . . . . 14Accessing solution status . . . . . . . . . 14Querying solution data . . . . . . . . . 15Accessing basis information . . . . . . . . 16Performing sensitivity analysis . . . . . . . 16Analyzing infeasible problems . . . . . . . 16Assessing solution quality . . . . . . . . 17

    Modifying a model . . . . . . . . . . . . 17Overview . . . . . . . . . . . . . . 18Deleting and removing modeling objects . . . 18Changing variable type . . . . . . . . . 19

    Handling errors . . . . . . . . . . . . . 20Example: optimizing the diet problem in C++ . . . 21

    Overview . . . . . . . . . . . . . . 21Problem representation . . . . . . . . . 21Application description . . . . . . . . . 23Creating multi-dimensional arrays with IloArray 23Using arrays for input or output . . . . . . 23Solving the model with IloCplex . . . . . . 25Complete program . . . . . . . . . . . 26

    Chapter 2. Concert Technology forJava users . . . . . . . . . . . . . 27Architecture of a CPLEX Java application . . . . 27

    Overview . . . . . . . . . . . . . . 27Compiling and linking a Java application . . . 28

    Creating a Java application with Concert Technology 28Modeling an optimization problem with ConcertTechnology in the Java API . . . . . . . . . 29

    Overview . . . . . . . . . . . . . . 29Using IloModeler . . . . . . . . . . . 31The active model . . . . . . . . . . . 33Building the model . . . . . . . . . . . 34

    Solving the model . . . . . . . . . . . . 35Accessing solution information . . . . . . . . 36Choosing an optimizer . . . . . . . . . . 37

    Overview . . . . . . . . . . . . . . 37What does CPLEX solve? . . . . . . . . . 37Solving a single continuous model. . . . . . 38Solving subsequent continuous relaxations in aMIP . . . . . . . . . . . . . . . . 39

    Controlling CPLEX optimizers . . . . . . . . 39Overview . . . . . . . . . . . . . . 40Parameters . . . . . . . . . . . . . 40Priority orders and branching directions . . . . 41

    More solution information . . . . . . . . . 41Overview . . . . . . . . . . . . . . 41Writing solution files . . . . . . . . . . 41Dual solution information . . . . . . . . 42Basis information . . . . . . . . . . . 42Infeasible solution information . . . . . . . 42Solution quality . . . . . . . . . . . . 43

    Advanced modeling with IloLPMatrix . . . . . 43Modeling by column . . . . . . . . . . . 44

    What is modeling by column? . . . . . . . 44Procedure for Modeling by Column . . . . . 45

    Example: optimizing the diet problem in Java . . . 45Modifying the model . . . . . . . . . . . 47

    Chapter 3. Concert Technology for.NET users . . . . . . . . . . . . . 49Prerequisites . . . . . . . . . . . . . . 49Describe . . . . . . . . . . . . . . . 49Step 1: Describe the problem . . . . . . . . 50Step 2: Open the file . . . . . . . . . . . 50Model . . . . . . . . . . . . . . . . 51Step 3: Create the model . . . . . . . . . . 51Step 4: Create an array to store the variables . . . 51Step 5: Specify by row or by column . . . . . . 52Build by Rows . . . . . . . . . . . . . 52Step 6: Set up rows . . . . . . . . . . . . 52Step 7: Create the variables: build and populate byrows. . . . . . . . . . . . . . . . . 52Step 8: Add objective . . . . . . . . . . . 52Step 9: Add nutritional constraints. . . . . . . 53Build by Columns . . . . . . . . . . . . 53

    © Copyright IBM Corp. 1987, 2015 iii

  • Step 10: Set up columns . . . . . . . . . . 53Step 11: Add empty objective function andconstraints. . . . . . . . . . . . . . . 53Step 12: Create variables . . . . . . . . . . 54Solve . . . . . . . . . . . . . . . . 54Step 13: Solve . . . . . . . . . . . . . 54Step 14: Display the solution . . . . . . . . 54Step 15: End application . . . . . . . . . . 55Good programming practices . . . . . . . . 55Step 16: Read the command line (data from user). . 55Step 17: Show correct use of command line. . . . 55Step 18: Enclose the application in try catchstatements . . . . . . . . . . . . . . . 56Example: optimizing the diet problem in C#.NET. . 56Example: copying a model . . . . . . . . . 56

    Chapter 4. Callable Library . . . . . . 59Architecture of the Callable Library . . . . . . 59

    Overview . . . . . . . . . . . . . . 59Compiling and linking . . . . . . . . . 60

    Using the Callable Library in an application . . . 60Overview . . . . . . . . . . . . . . 60Initialize the CPLEX environment . . . . . . 60Instantiate the problem as an object . . . . . 61Put data in the problem object . . . . . . . 61Optimize the problem . . . . . . . . . . 62Change the problem object . . . . . . . . 62Destroy the problem object . . . . . . . . 62Release the CPLEX environment . . . . . . 62

    CPLEX programming practices . . . . . . . . 62Overview . . . . . . . . . . . . . . 63Variable names and calling conventions . . . . 63Data types. . . . . . . . . . . . . . 64Ownership of problem data . . . . . . . . 64Problem size and memory allocation issues. . . 64Status and return values . . . . . . . . . 65Symbolic constants . . . . . . . . . . . 65Parameter routines . . . . . . . . . . . 65Null arguments . . . . . . . . . . . . 66Row and column references . . . . . . . . 66Character strings . . . . . . . . . . . 66Checking and debugging problem data . . . . 67Callbacks . . . . . . . . . . . . . . 68Portability . . . . . . . . . . . . . . 69FORTRAN interface . . . . . . . . . . 70C++ interface . . . . . . . . . . . . . 71

    Managing parameters from the Callable Library . . 71Example: optimizing the diet problem in theCallable Library . . . . . . . . . . . . . 72

    Overview . . . . . . . . . . . . . . 73Problem representation . . . . . . . . . 73Program description . . . . . . . . . . 74Solving the model with CPXlpopt . . . . . . 75Complete program . . . . . . . . . . . 75

    Using surplus arguments for array allocations . . . 75Example: using query routines lpex7.c . . . . . 77

    Chapter 5. CPLEX for Python users . . 79Why Python? . . . . . . . . . . . . . . 79Meet the Python API . . . . . . . . . . . 80

    Modifying and querying problem data in thePython API . . . . . . . . . . . . . . 80Using polymorphism in the Python API . . . . . 80Example: generating a histogram . . . . . . . 81Querying solution information in the Python API . 82Examining variables with nonzero values in asolution . . . . . . . . . . . . . . . 83Displaying high precision nonzero values of asolution . . . . . . . . . . . . . . . 83Managing CPLEX parameters in the Python API . . 84Using callbacks in the Python API . . . . . . . 84Example: displaying solutions with increasedprecision from the Python API . . . . . . . . 85Example: examining the simplex tableau in thePython API . . . . . . . . . . . . . . 86Example: solving a sequence of related problems inthe Python API . . . . . . . . . . . . . 86Example: complex termination criteria in a callback 86

    Part 2.Programming considerations . . . 89

    Chapter 6. Developing CPLEXapplications . . . . . . . . . . . . 91Tips for successful application development . . . 91

    Prototype the model . . . . . . . . . . 91Identify routines to use . . . . . . . . . 91Test interactively . . . . . . . . . . . 91Assemble data efficiently . . . . . . . . . 92Test data . . . . . . . . . . . . . . 92Test and debug the model . . . . . . . . 92Choose an optimizer . . . . . . . . . . 93Program with a view toward maintenance andmodifications . . . . . . . . . . . . . 93

    Using the Interactive Optimizer for debugging . . 96Eliminating common programming errors . . . . 97

    Turn on the data check parameter . . . . . . 97Check your include files . . . . . . . . . 97Clean house and try again . . . . . . . . 98Read your messages . . . . . . . . . . 98Check return values . . . . . . . . . . 98Beware of numbering conventions . . . . . . 98Make local variables temporarily global . . . . 98Solve the problem you intended . . . . . . 99Special considerations for FORTRAN . . . . . 99Tell us . . . . . . . . . . . . . . . 99

    Chapter 7. Managing input and output 101Platform limits on files . . . . . . . . . . 101Representing very large models: 64-bit API . . . 101Selecting an encoding . . . . . . . . . . 106Understanding file formats . . . . . . . . . 107

    Overview. . . . . . . . . . . . . . 107Working with LP files . . . . . . . . . 107Working with MPS files . . . . . . . . . 108Converting file formats . . . . . . . . . 109

    Using Concert XML extensions . . . . . . . 110Using Concert csvReader . . . . . . . . . 111Managing log files . . . . . . . . . . . . 111

    iv CPLEX User’s Manual

  • Overview . . . . . . . . . . . . . . 111Creating, renaming, relocating log files . . . . 112Closing log files . . . . . . . . . . . 112

    Controlling message channels . . . . . . . . 112Overview. . . . . . . . . . . . . . 112Output channels in the Interactive Optimizer 113Callable Library routines for message channels 114Example: Callable Library message channels . . 115Concert Technology message channels . . . . 116

    Chapter 8. Timing interface . . . . . 117Determinism and the timing interface . . . . . 117Using the timing interface . . . . . . . . . 118Using the timing interface in callbacks . . . . . 119

    Chapter 9. Tuning tool . . . . . . . 121Meet the tuning tool . . . . . . . . . . . 121

    Overview: scope of the tuning tool . . . . . 121If CPLEX solves your problem to optimality . . 121If CPLEX finds solutions but does not proveoptimality . . . . . . . . . . . . . 122Tuning and time limits . . . . . . . . . 122Tuning time limits and determinism . . . . . 123Tuning results . . . . . . . . . . . . 124

    Invoking the tuning tool. . . . . . . . . . 124Examples: time limits on tuning in the InteractiveOptimizer . . . . . . . . . . . . . . 125Fixing parameters and tuning multiple models inthe Interactive Optimizer . . . . . . . . . 126

    Invoking the tuning tool in the InteractiveOptimizer . . . . . . . . . . . . . 127Fixed parameters to respect . . . . . . . 127Files of models to tune . . . . . . . . . 127

    Tuning models in the Callable Library (C API) . . 128Callbacks for tuning . . . . . . . . . . . 129Terminating a tuning session . . . . . . . . 129

    Part 3. Continuous optimization 131

    Chapter 10. Solving LPs: simplexoptimizers . . . . . . . . . . . . . 133Introducing the primal and dual optimizers . . . 133Choosing an optimizer for your LP problem . . . 133

    Overview of LP optimizers . . . . . . . . 133Automatic selection of an optimizer . . . . . 134Dual simplex optimizer . . . . . . . . . 135Primal simplex optimizer . . . . . . . . 135Network optimizer . . . . . . . . . . 135Barrier optimizer . . . . . . . . . . . 136Sifting optimizer . . . . . . . . . . . 136Concurrent optimizer. . . . . . . . . . 136Parameter settings and optimizer choice . . . 137

    Tuning LP performance . . . . . . . . . . 137Introducing performance tuning for LP models 137Preprocessing . . . . . . . . . . . . 137Starting from an advanced basis . . . . . . 139Simplex parameters . . . . . . . . . . 140

    Diagnosing performance problems . . . . . . 144Lack of memory . . . . . . . . . . . 144

    Ill conditioning . . . . . . . . . . . . 145Numeric difficulties . . . . . . . . . . 146

    Diagnosing LP infeasibility . . . . . . . . . 150Infeasibility reported by LP optimizers . . . . 150Coping with an ill-conditioned problem orhandling unscaled infeasibilities . . . . . . 151Interpreting solution quality . . . . . . . 152Finding a conflict . . . . . . . . . . . 155Repairing infeasibility: FeasOpt . . . . . . 155

    Examples: using a starting basis in LP optimization 155Overview. . . . . . . . . . . . . . 155Example ilolpex6.cpp . . . . . . . . . . 155Example lpex6.c . . . . . . . . . . . 156

    Chapter 11. Solving LPs: barrieroptimizer . . . . . . . . . . . . . 157Introducing the barrier optimizer . . . . . . . 157Barrier simplex crossover . . . . . . . . . 158Differences between barrier and simplex optimizers 158Using the barrier optimizer. . . . . . . . . 159Special options in the Interactive Optimizer . . . 160Controlling crossover . . . . . . . . . . . 160Using SOL file format . . . . . . . . . . 160Interpreting the barrier log file . . . . . . . 160

    Accessing and managing the log file of thebarrier optimizer . . . . . . . . . . . 161Sample log file from the barrier optimizer . . . 161Sample log file from the augmented systemsolver . . . . . . . . . . . . . . . 162Preprocessing in the log file . . . . . . . 163Nonzeros in lower triangle of A*A' in the logfile . . . . . . . . . . . . . . . . 163Ordering-algorithm time in the log file . . . . 163Cholesky factor in the log file . . . . . . . 163Iteration progress in the log file . . . . . . 164Infeasibility ratio in the log file . . . . . . 164

    Understanding solution quality from the barrier LPoptimizer . . . . . . . . . . . . . . . 165Tuning barrier optimizer performance . . . . . 166

    Overview of parameters for tuning the barrieroptimizer . . . . . . . . . . . . . . 166Memory emphasis: letting the optimizer usedisk for storage. . . . . . . . . . . . 167Preprocessing . . . . . . . . . . . . 168Detecting and eliminating dense columns . . . 169Choosing an ordering algorithm . . . . . . 169Using a starting-point heuristic . . . . . . 170

    Overcoming numeric difficulties . . . . . . . 171Default behavior of the barrier optimizer withrespect to numeric difficulty . . . . . . . 171Numerical emphasis settings . . . . . . . 171Difficulties in the quality of solution. . . . . 171Difficulties during optimization . . . . . . 173Difficulties with unbounded problems . . . . 174

    Diagnosing infeasibility reported by barrieroptimizer . . . . . . . . . . . . . . . 175

    Chapter 12. Solving network-flowproblems . . . . . . . . . . . . . 177Choosing an optimizer: network considerations 177

    Contents v

  • Formulating a network problem . . . . . . . 177Example: network optimizer in the InteractiveOptimizer . . . . . . . . . . . . . . 178

    Network flow problem description . . . . . 178Understanding the network log file . . . . . 179Tuning performance of the network optimizer 180

    Solving problems with the network optimizer . . 180Invoking the network optimizer . . . . . . 180Network extraction . . . . . . . . . . 181Preprocessing and the network optimizer . . . 181

    Example: using the network optimizer with theCallable Library netex1.c . . . . . . . . . 181Solving network-flow problems as LP problems 183Example: network to LP transformation netex2.c 184

    Chapter 13. Solving problems with aquadratic objective (QP) . . . . . . 185Distinguishing between convex and nonconvexQPs . . . . . . . . . . . . . . . . 185Entering QPs . . . . . . . . . . . . . 187

    Matrix view . . . . . . . . . . . . . 187Algebraic view . . . . . . . . . . . . 187Examples for entering QPs . . . . . . . . 187Reformulating QPs to save memory . . . . . 188

    Saving QP problems . . . . . . . . . . . 189Changing problem type in QPs . . . . . . . 189Changing quadratic terms . . . . . . . . . 190Optimizing QPs . . . . . . . . . . . . 191Diagnosing QP infeasibility. . . . . . . . . 192Examples: creating a QP, optimizing, finding asolution . . . . . . . . . . . . . . . 193

    Problem description of a quadratic program . . 193Example: iloqpex1.cpp . . . . . . . . . 193Example: QPex1.java . . . . . . . . . . 194Example: qpex1.c . . . . . . . . . . . 194

    Example: reading a QP from a file qpex2.c . . . 195

    Chapter 14. Solving problems withquadratic constraints (QCP) . . . . . 197Identifying a quadratically constrained program(QCP) . . . . . . . . . . . . . . . . 197

    Characteristics of a quadratically constrainedprogram . . . . . . . . . . . . . . 197Convexity . . . . . . . . . . . . . 197Semi-definiteness . . . . . . . . . . . 199Second order cone programming (SOCP) andnon PSD . . . . . . . . . . . . . . 199Representing SOCP as Lagrangian . . . . . 200

    Detecting the problem type of a QCP or SOCP . . 202Overview. . . . . . . . . . . . . . 202Concert Technology and QCP problem type . . 202Callable Library and QCP problem type . . . 202Interactive Optimizer and QCP problem type 203File formats and QCP problem type . . . . . 203

    Changing problem type in a QCP . . . . . . 206Changing quadratic constraints . . . . . . . 207Solving with quadratic constraints . . . . . . 208Numeric difficulties and quadratic constraints . . 208Accessing dual values and reduced costs of QCPsolutions . . . . . . . . . . . . . . . 208

    Accessing dual values and reduced costs of SOCPsolutions . . . . . . . . . . . . . . . 211Examples: SOCP . . . . . . . . . . . . 213Examples: QCP. . . . . . . . . . . . . 213

    Part 4. Discrete optimization . . . 215

    Chapter 15. Solving mixed integerprogramming problems (MIP) . . . . 217Stating a MIP problem . . . . . . . . . . 217Preliminary issues . . . . . . . . . . . . 218

    Entering MIP problems . . . . . . . . . 218Displaying MIP problems . . . . . . . . 219Changing problem type in MIPs . . . . . . 219Changing variable type . . . . . . . . . 221

    Using the mixed integer optimizer . . . . . . 221Invoking the optimizer for a MIP model. . . . 221Emphasizing feasibility and optimality . . . . 222Terminating MIP optimization . . . . . . . 223

    Tuning performance features of the mixed integeroptimizer . . . . . . . . . . . . . . . 225

    Branch & cut or dynamic search? . . . . . 225Introducing performance features of the MIPoptimizer . . . . . . . . . . . . . . 225Applying cutoff values . . . . . . . . . 226Applying tolerance parameters . . . . . . 226Applying heuristics . . . . . . . . . . 226When an integer solution is found: theincumbent . . . . . . . . . . . . . 226Controlling strategies: diving and backtracking 227Selecting nodes . . . . . . . . . . . . 227Selecting variables . . . . . . . . . . . 228Changing branching direction . . . . . . . 229Solving subproblems . . . . . . . . . . 229Using node files . . . . . . . . . . . 230Probing . . . . . . . . . . . . . . 230

    Cuts . . . . . . . . . . . . . . . . 231What are cuts? . . . . . . . . . . . . 231Boolean Quadric Polytope (BQP) cuts . . . . 231Clique cuts . . . . . . . . . . . . . 232Cover cuts . . . . . . . . . . . . . 232Disjunctive cuts . . . . . . . . . . . 232Flow cover cuts . . . . . . . . . . . 232Flow path cuts . . . . . . . . . . . . 233Gomory fractional cuts . . . . . . . . . 233Generalized upper bound (GUB) cover cuts . . 233Implied bound cuts: global and local . . . . 233Lift-and-project cuts . . . . . . . . . . 233Mixed integer rounding (MIR) cuts . . . . . 234Multi-commodity flow (MCF) cuts . . . . . 234Zero-half cuts . . . . . . . . . . . . 235Adding cuts and re-optimizing . . . . . . 235Counting cuts . . . . . . . . . . . . 235Parameters affecting cuts . . . . . . . . 236

    Heuristics . . . . . . . . . . . . . . 237What are heuristics? . . . . . . . . . . 237Node heuristic . . . . . . . . . . . . 238Relaxation induced neighborhood search (RINS)heuristic . . . . . . . . . . . . . . 238Solution polishing . . . . . . . . . . . 238

    vi CPLEX User’s Manual

  • Feasibility pump . . . . . . . . . . . 244Preprocessing: presolver and aggregator . . . . 244Starting from a solution: MIP starts . . . . . . 246Issuing priority orders . . . . . . . . . . 251Using the MIP solution . . . . . . . . . . 252

    Accessing a MIP solution as values in an array 252Writing integer solutions to a file . . . . . . 252Displaying a MIP solution in the InteractiveOptimizer . . . . . . . . . . . . . 252Accessing information about the MIP solution 252Analyzing MIP solution quality . . . . . . 253Working with the fixed MIP problem . . . . 254

    Progress reports: interpreting the node log . . . 255Troubleshooting MIP performance problems . . . 260

    Introducing troubleshooting for MIPperformance . . . . . . . . . . . . . 260Too much time at node 0 . . . . . . . . 260Trouble finding more than one feasible solution 261Large number of unhelpful cuts . . . . . . 261Lack of movement in the best node . . . . . 262Time wasted on overly tight optimality criteria 262MIP kappa: detecting and coping withill-conditioned MIP models . . . . . . . . 263Slightly infeasible integer variables . . . . . 265Running out of memory . . . . . . . . . 266Difficulty solving subproblems: overcomingdegeneracy . . . . . . . . . . . . . 270Unsatisfactory optimization of subproblems . . 270

    Examples: optimizing a simple MIP problem . . . 272ilomipex1.cpp . . . . . . . . . . . . 272MIPex1.java . . . . . . . . . . . . . 272MIPex1.cs and MIPex1.vb . . . . . . . . 272mipex1.c . . . . . . . . . . . . . . 272

    Example: reading a MIP problem from a file . . . 273ilomipex2.cpp . . . . . . . . . . . . 273mipex2.c . . . . . . . . . . . . . . 273

    Chapter 16. Solving mixed integerprogramming problems with quadraticterms . . . . . . . . . . . . . . . 275MIQP: mixed integer programs with quadraticterms in the objective function. . . . . . . . 275MIQCP: mixed integer programs with quadraticterms in the constraints . . . . . . . . . . 276

    Features of the MIP optimizer for MIQCP . . . 277

    Chapter 17. Solution pool: generatingand keeping multiple solutions. . . . 279What is the solution pool? . . . . . . . . . 279Example: simple facility location problem . . . . 279Filling the solution pool . . . . . . . . . . 281Accumulating incumbents in the solution pool . . 281Populating the solution pool . . . . . . . . 282

    What is populating the solution pool? . . . . 282Invoking the populate procedure . . . . . . 282Algorithm of the populate procedure . . . . 282Example: calling populate . . . . . . . . 283Stopping criteria for the populate procedure . . 285Stored solutions, populate limit, and poolcapacity . . . . . . . . . . . . . . 286

    Choosing whether to accumulate or populate. . . 286What’s the difference between accumulating andpopulating? . . . . . . . . . . . . . 286Advanced use: interaction of MIP optimizationand populate . . . . . . . . . . . . 287Example: using populate after MIP optimization 287

    Enumerating all solutions . . . . . . . . . 288How to enumerate all solutions . . . . . . 288Limitations due to continuous variables andfinite precision . . . . . . . . . . . . 289Limitations due to unbounded MIP models . . 289Limitations due to numeric difficulties . . . . 289

    Impact of change on the solution pool . . . . . 290Changes between MIP optimization andpopulate . . . . . . . . . . . . . . 290Persistence of solutions in the solution pool . . 290Model changes and the solution pool . . . . 290

    Examining the solution pool . . . . . . . . 291Accessing a solution in the solution pool . . . . 292Using solutions from the solution pool . . . . . 293Deleting solutions from the solution pool . . . . 294The incumbent and the solution pool . . . . . 294Parameters of the solution pool . . . . . . . 295

    Which parameters control the solution pool? 295Example: quality control through the solutionpool gap parameter . . . . . . . . . . 295Example: few or many solutions throughintensity parameter . . . . . . . . . . 296Example: diverse solutions through replacementparameter . . . . . . . . . . . . . 296

    Filtering the solution pool . . . . . . . . . 297What are filters of the solution pool? . . . . 297Diversity filters . . . . . . . . . . . . 298Range filters. . . . . . . . . . . . . 299Filter files . . . . . . . . . . . . . 300Example: controlling properties of solutionswith filters . . . . . . . . . . . . . 300Incumbent callback as a filter . . . . . . . 301

    Chapter 18. Using special orderedsets (SOS). . . . . . . . . . . . . 303What is a special ordered set (SOS)? . . . . . . 303Example: SOS Type 1 for sizing a warehouse . . . 303Declaring SOS members . . . . . . . . . . 304Example: using SOS and priority . . . . . . . 304

    ilomipex3.cpp . . . . . . . . . . . . 304mipex3.c . . . . . . . . . . . . . . 305

    Chapter 19. Using semi-continuousvariables: a rates example . . . . . . 307What are semi-continuous variables? . . . . . 307Describing the problem . . . . . . . . . . 307Representing the problem . . . . . . . . . 308Building a model . . . . . . . . . . . . 308Solving the problem . . . . . . . . . . . 309Ending the application . . . . . . . . . . 309Complete program . . . . . . . . . . . 309

    Contents vii

  • Chapter 20. Using piecewise linearfunctions in optimization: a transportexample. . . . . . . . . . . . . . 311What is a piecewise linear function? . . . . . . 311Syntax of piecewise linear functions . . . . . . 312Discontinuous piecewise linear functions . . . . 313Isolated points in piecewise linear functions . . . 315Using IloPiecewiseLinear in expressions . . . . 315Describing the problem . . . . . . . . . . 315

    Problem statement. . . . . . . . . . . 315Variable shipping costs . . . . . . . . . 316Model with varying costs . . . . . . . . 317

    Developing a model . . . . . . . . . . . 317Creating the environment and model . . . . 317Representing the data . . . . . . . . . 318Adding constraints . . . . . . . . . . 318Checking convexity and concavity . . . . . 318Adding an objective . . . . . . . . . . 319

    Solving the problem . . . . . . . . . . . 319Displaying a solution. . . . . . . . . . . 319Ending the application . . . . . . . . . . 320Complete program: transport.cpp. . . . . . . 320

    Chapter 21. Indicator constraints inoptimization . . . . . . . . . . . . 321What is an indicator constraint? . . . . . . . 321Example: fixnet.c . . . . . . . . . . . . 322Indicator constraints in the Interactive Optimizer 322What are indicator variables? . . . . . . . . 322Restrictions on indicator constraints . . . . . . 322Best practices with indicator constraints . . . . 323

    Chapter 22. Logical constraints inoptimization . . . . . . . . . . . . 325What are logical constraints? . . . . . . . . 325What can be extracted from a model with logicalconstraints? . . . . . . . . . . . . . . 325

    Overview. . . . . . . . . . . . . . 325Logical constraints in the C++ API . . . . . 326Logical constraints in the Java API . . . . . 327Logical constraints in the .NET API . . . . . 327

    Which nonlinear expressions can be extracted? . . 327Logical constraints for counting . . . . . . . 328Logical constraints as binary variables . . . . . 328How are logical constraints extracted? . . . . . 329

    Chapter 23. Using logical constraints:Food Manufacture 2 . . . . . . . . 331Introducing the example. . . . . . . . . . 331Describing the problem . . . . . . . . . . 331Representing the data . . . . . . . . . . 332Developing the model . . . . . . . . . . 334Formulating logical constraints . . . . . . . 335Solving the problem . . . . . . . . . . . 335

    Chapter 24. Using column generation:a cutting stock example . . . . . . . 337What is column generation? . . . . . . . . 337Column-wise models in Concert Technology . . . 337

    Describing the problem . . . . . . . . . . 338Representing the data . . . . . . . . . . 339Developing the model: building and modifying 340

    The master model and column generator in thisapplication. . . . . . . . . . . . . . 340Adding extractable objects: both ways . . . . 340Adding columns to a model . . . . . . . 341Changing the type of a variable . . . . . . 342Cut optimization model . . . . . . . . . 342Pattern generator model . . . . . . . . . 342

    Changing the objective function . . . . . . . 343Solving the problem: using more than onealgorithm. . . . . . . . . . . . . . . 343Ending the program . . . . . . . . . . . 344Complete program . . . . . . . . . . . 344

    Chapter 25. Early tardy scheduling 345Describing the problem . . . . . . . . . . 345Understanding the data file . . . . . . . . 345Reading the data . . . . . . . . . . . . 346Creating variables . . . . . . . . . . . . 346Stating precedence constraints . . . . . . . . 346Stating resource constraints. . . . . . . . . 347Representing the piecewise linear cost function . . 347Transforming the problem . . . . . . . . . 348Solving the problem . . . . . . . . . . . 348

    Part 5. Parallel optimization . . . . 351

    Chapter 26. Multithreaded paralleloptimizers . . . . . . . . . . . . . 353What are multithreaded parallel optimizers? . . . 353Threads . . . . . . . . . . . . . . . 353

    Thread safety . . . . . . . . . . . . 353Threads parameter . . . . . . . . . . 354Threads and performance considerations . . . 355

    Determinism of results . . . . . . . . . . 355Using parallel optimizers in the InteractiveOptimizer . . . . . . . . . . . . . . 356Using parallel optimizers in the ComponentLibraries . . . . . . . . . . . . . . . 357Using the parallel barrier optimizer . . . . . . 358Concurrent optimizer in parallel . . . . . . . 358Determinism, parallelism, and optimization limits 359Parallel MIP optimizer . . . . . . . . . . 360

    Introducing parallel MIP optimization . . . . 360Root relaxation and parallel MIP processing . . 360Memory considerations and the parallel MIPoptimizer . . . . . . . . . . . . . . 361Output from the parallel MIP optimizer . . . 361

    Clock settings and time measurement . . . . . 363

    Chapter 27. Remote object fordistributed parallel optimization . . . 365CPLEX remote object for distributed paralleloptimization. . . . . . . . . . . . . . 365Application layout for the remote object . . . . 366Programming paradigm in C for the CPLEXremote object . . . . . . . . . . . . . 367

    viii CPLEX User’s Manual

  • More about CPXXopenCPLEXremote . . . . . 370Programming in C++ with the CPLEX remoteobject . . . . . . . . . . . . . . . . 371Programming in Java with the CPLEX remoteobject . . . . . . . . . . . . . . . . 371Transport types for the remote object . . . . . 371

    Transport types for the remote object: local . . 372Transport types for the remote object: process 372Transport types for the remote object: MPI . . 373Transport types for the remote object: TCP/IP 374

    Contrasting local and remote environments andlibraries . . . . . . . . . . . . . . . 375Multicast: invoking the same methods on a groupof objects . . . . . . . . . . . . . . . 375Asynchronous execution. . . . . . . . . . 378

    Asynchronous execution in the Callable Library(C API) . . . . . . . . . . . . . . 378Asynchronous execution in the C++ API . . . 380Asynchronous execution in the Java API . . . 382

    User functions to run user-defined code on theremote machine . . . . . . . . . . . . 383Serializing for the remote object . . . . . . . 385Sending status messages to the master . . . . . 386Example: distributed concurrent MIP . . . . . 387

    Code running on the master . . . . . . . 388Creating and initializing a remote object . . . 388Dispatching problem data to remote objects . . 389Destroying remote objects . . . . . . . . 391Setting parameters in remote objects. . . . . 391Solving a problem with remote objects . . . . 392Fetching the results of distributed concurrentMIP optimization . . . . . . . . . . . 394Processing status updates and receivinginformational messages . . . . . . . . . 395Setting up status updates on the remotemachines: user functions . . . . . . . . 396Code running on the remote worker machines 396

    Deploying an application of the CPLEX remoteobject . . . . . . . . . . . . . . . . 397

    Using a makefile for an application of theCPLEX remote object . . . . . . . . . . 397Constrasting remote and local issues . . . . 398

    Example: parallel optimization of a Bendersdecomposition . . . . . . . . . . . . . 398

    Chapter 28. Solving a MIP withdistributed parallel optimization . . . 401Distributed optimization of MIPs: the algorithm 401Special characteristics of distributed branch andbound . . . . . . . . . . . . . . . . 402Technical limits of distributed branch and bound 403VMC file for specifying parameters andenvironment variables in distributed paralleloptimization. . . . . . . . . . . . . . 404Before you begin . . . . . . . . . . . . 405Distributed parallel MIP in the InteractiveOptimizer . . . . . . . . . . . . . . 406Using Open MPI with distributed parallel MIP . . 407Using MPICH with distributed parallel MIP . . . 409Using a process transport protocol with distributedparallel MIP . . . . . . . . . . . . . . 410

    Using TCP/IP as the transport protocol withdistributed parallel MIP . . . . . . . . . . 412Example: Callable Library (C API) . . . . . . 413Example: C++ API. . . . . . . . . . . . 415Example: Java API. . . . . . . . . . . . 416Example: Python API. . . . . . . . . . . 418Using multiple processes as workers on a singlemachine . . . . . . . . . . . . . . . 419

    Part 6. Infeasibility andunboundedness . . . . . . . . . 421

    Chapter 29. Preprocessing andfeasibility . . . . . . . . . . . . . 423Issues of infeasibility and unboundedness . . . . 423Early reports of infeasibility based onpreprocessing reductions . . . . . . . . . 423

    Chapter 30. Managing unboundedness 425What is unboundedness? . . . . . . . . . 425Avoiding unboundedness in a model . . . . . 425Diagnosing unboundedness . . . . . . . . 426

    Chapter 31. Diagnosing infeasibilityby refining conflicts . . . . . . . . 429What is a conflict? . . . . . . . . . . . . 429What a conflict is not. . . . . . . . . . . 429How to invoke the conflict refiner . . . . . . 429How a conflict differs from an IIS . . . . . . 430Meet the conflict refiner in the InteractiveOptimizer . . . . . . . . . . . . . . 431

    Limits of the conflict refiner in the InteractiveOptimizer . . . . . . . . . . . . . 431A model for the conflict refiner . . . . . . 431Optimizing the example . . . . . . . . . 432Interpreting the results and detecting conflict 432Displaying a conflict in the InteractiveOptimizer . . . . . . . . . . . . . 433

    Interpreting conflict . . . . . . . . . . . 433Understanding the conflict in the model . . . 433Deleting a constraint . . . . . . . . . . 434Understanding a conflict report . . . . . . 434Summing equality constraints . . . . . . . 435Changing a bound. . . . . . . . . . . 435Adding a constraint . . . . . . . . . . 435Changing bounds on cost . . . . . . . . 436Relaxing a constraint . . . . . . . . . . 437

    More about the conflict refiner . . . . . . . 437Refining a conflict in a MIP start . . . . . . . 439Using the conflict refiner in an application . . . 440

    Example: modifying ilomipex2.cpp . . . . . 440What belongs in an application to refine conflict 441

    Comparing a conflict application to InteractiveOptimizer . . . . . . . . . . . . . . 441

    Preferences in the conflict refiner . . . . . . 441Groups in the conflict refiner . . . . . . . 441

    Contents ix

  • Chapter 32. Repairing infeasibilitieswith FeasOpt . . . . . . . . . . . 443What is FeasOpt? . . . . . . . . . . . . 443Invoking FeasOpt . . . . . . . . . . . . 443Specifying preferences . . . . . . . . . . 444Interpreting output from FeasOpt . . . . . . 444Example: FeasOpt in Concert Technology . . . . 445

    Part 7. Advanced programmingtechniques . . . . . . . . . . . . 451

    Chapter 33. User-cut andlazy-constraint pools . . . . . . . . 453What are user cuts and lazy constraints? . . . . 453What are pools of user cuts or lazy constraints? 453Differences between user cuts and lazy constraints 454Identifying candidate constraints for lazy constraintpool . . . . . . . . . . . . . . . . 455Limitations on user-cut pools . . . . . . . . 456Adding user cuts and lazy constraints . . . . . 456

    Using the Component Libraries to add user cutsor lazy constraints . . . . . . . . . . . 456Using the Interactive Optimizer to add user cutsor lazy constraints . . . . . . . . . . . 457Reading and writing LP files . . . . . . . 457Reading and writing SAV files. . . . . . . 458Reading and writing MPS files . . . . . . 458

    Deleting user cuts and lazy constraints . . . . . 459

    Chapter 34. Using goals . . . . . . . 461Branch & cut with goals . . . . . . . . . . 461

    What is a goal? . . . . . . . . . . . . 461Overview of goals in the search . . . . . . 461How goals are implemented in branch & cut 462About the method execute in a goal . . . . . 462

    Special goals in branch & cut . . . . . . . . 462Or goal . . . . . . . . . . . . . . 463And goal . . . . . . . . . . . . . . 463Fail goal . . . . . . . . . . . . . . 463Local cut goal . . . . . . . . . . . . 463Null goal . . . . . . . . . . . . . . 464Branch as CPLEX goal . . . . . . . . . 464Solution goal . . . . . . . . . . . . 464

    Aggregating goals . . . . . . . . . . . . 465Example: goals in branch & cut . . . . . . . 465The goal stack . . . . . . . . . . . . . 467Memory management and goals . . . . . . . 468Cuts and goals . . . . . . . . . . . . . 469Injecting heuristic solutions. . . . . . . . . 471Controlling goal-defined search . . . . . . . 472Example: using node evaluators in a node selectionstrategy . . . . . . . . . . . . . . . 474Search limits. . . . . . . . . . . . . . 475

    Chapter 35. Using optimizationcallbacks . . . . . . . . . . . . . 477What are callbacks? . . . . . . . . . . . 477Informational callbacks . . . . . . . . . . 478

    What is an informational callback? . . . . . 478

    Reference documents about informationalcallbacks . . . . . . . . . . . . . . 479Where to find examples of informationalcallbacks . . . . . . . . . . . . . . 479Informational callbacks and distributed MIP:some special considerations . . . . . . . 480What informational callbacks can return . . . 481

    Query or diagnostic callbacks . . . . . . . . 482What are query or diagnostic callbacks? . . . 482Where query callbacks are called . . . . . . 482Query callbacks and dynamic search . . . . 484Query callbacks and parallel search . . . . . 484

    Control callbacks . . . . . . . . . . . . 484What are control callbacks?. . . . . . . . 484What control callbacks do . . . . . . . . 485Control callbacks and dynamic search . . . . 486Control callbacks and parallel search . . . . 487

    Implementing callbacks with Concert Technology 487How callback classes are organized . . . . . 487Writing callback classes by hand . . . . . . 488Writing callbacks with macros in C++ . . . . 489Callback interface . . . . . . . . . . . 490The continuous callback . . . . . . . . . 491

    Example: deriving the simplex callbackilolpex4.cpp . . . . . . . . . . . . . . 491Implementing callbacks in the Callable Library . . 492

    Callable Library callback facilities . . . . . 492Setting callbacks . . . . . . . . . . . 493Callbacks for continuous and discrete problems 493

    Example: using callbacks lpex4.c . . . . . . . 493Example: controlling cuts iloadmipex5.cpp . . . 494Interaction between callbacks and paralleloptimizers . . . . . . . . . . . . . . 498Return values for callbacks . . . . . . . . . 499Terminating without callbacks . . . . . . . . 499

    Chapter 36. Goals and callbacks: acomparison . . . . . . . . . . . . 501Overview. . . . . . . . . . . . . . . 501

    Chapter 37. Advanced presolveroutines. . . . . . . . . . . . . . 503Introduction to presolve . . . . . . . . . . 503A proposed example . . . . . . . . . . . 504Restricting presolve reductions . . . . . . . 504

    When to alert presolve to modifications . . . 505Adding constraints to the first solution . . . . 505Primal and dual considerations in presolvereductions . . . . . . . . . . . . . 505Cuts and presolve reductions . . . . . . . 506Infeasibility or unboundedness in presolvereductions . . . . . . . . . . . . . 506Protected variables in presolve reductions . . . 507

    Manual control of presolve . . . . . . . . . 507Modifying a problem . . . . . . . . . . . 509

    Chapter 38. Advanced MIP controlinterface . . . . . . . . . . . . . 511Introducing the advanced MIP control interface . . 511Introducing MIP control callbacks . . . . . . 511

    x CPLEX User’s Manual

  • What are MIP control callbacks? . . . . . . 511Thread safety and MIP control callbacks . . . 512Presolve and MIP control callbacks . . . . . 512

    Heuristic callback . . . . . . . . . . . . 513Cut callback . . . . . . . . . . . . . . 514Branch selection callback . . . . . . . . . 515Incumbent callback . . . . . . . . . . . 516Node selection callback . . . . . . . . . . 517Solve callback . . . . . . . . . . . . . 517

    Part 8. Appendixes . . . . . . . . 519

    Acknowledgment of use: dtoa routineof the gdtoa package . . . . . . . . 521

    Further acknowledgments: AMPL. . . 523

    Index . . . . . . . . . . . . . . . 525

    Contents xi

  • xii CPLEX User’s Manual

  • Meet CPLEX

    Introduces CPLEX, explains what it does, suggests prerequisites, and offers advicefor using this documentation with it.

    What is CPLEX?Describes CPLEX Component Libraries.

    IBM ILOG CPLEX offers C, C++, Java, .NET, and Python libraries that solve linearprogramming (LP) and related problems. Specifically, it solves linearly orquadratically constrained optimization problems where the objective to beoptimized can be expressed as a linear function or a convex quadratic function.The variables in the model may be declared as continuous or further constrainedto take only integer values.

    CPLEX comes in these forms to meet a wide range of users' needs:v The CPLEX Interactive Optimizer is an executable program that can read a

    problem interactively or from files in certain standard formats, solve theproblem, and deliver the solution interactively or into text files. The programconsists of the file cplex.exe on Windows platforms or cplex on UNIXplatforms.

    v Concert Technology is a set of libraries offering an API that includes modelingfacilities to allow a programmer to embed CPLEX optimizers in C++, Java, or.NET applications. The library is provided in these files: ilocplexXXX.lib,concert.lib, and cplexXXX.jar, where XXX represents a version number. Thisconvention of specifying the version number in the name of the library makes itpossible for you to maintain more than one version, if necessary. The library isalso provided in these files on Microsoft Windows platforms: cplexXXX.dll andconcertXXX.dll The library is also provided in these files on UNIX platforms:libilocplex.a, libconcert.a, and cplex.jar. In all those cases, ConcertTechnology makes use of the Callable Library (described next).

    v The CPLEX Callable Library is a C library that allows the programmer to embedCPLEX optimizers in applications written in C, Visual Basic, Fortran or anyother language that can call C functions. The library is provided as a DLL onWindows platforms and in a library (that is, with file extensions .a , .so , or .sl) on UNIX platforms.

    In this manual, the phrase CPLEX Component Libraries is used to refer equally toany of these libraries. While all libraries are callable, the term Callable Library asused here refers specifically to the C library.

    What does CPLEX do?Defines the scope of CPLEX.

    CPLEX is a tool for solving, first of all, linear optimization problems. Suchproblems are conventionally written like this:

    Minimize (ormaximize)

    c 1 x 1 + c 2 x 2 + . . . + c n x n

    subject to a 11 x 1 + a 12 x 2 + . . . + a 1n x n ~ b 1

    © Copyright IBM Corp. 1987, 2015 xiii

  • a 21 x 1 + a 22 x 2 + . . . + a 2n x n ~ b 2. . .

    a m1 x 1 + a m2 x 2 + . . . + a mn x n ~ b mwith these bounds l1 ≤ x1 ≤ u1, ... ln ≤ xn ≤ un

    where the relation ~ may be greater than or equal to, less than or equal to, orsimply equal to, and the upper bounds ui and lower bounds li may be positiveinfinity, negative infinity, or any real number.

    When a linear optimization problem is stated in that conventional form, itscoefficients and values are customarily referred to by these terms:

    objective functioncoefficients

    c 1 , . . . , c n

    constraint coefficients a 11 , . . . , a mnrighthand side b 1 , . . . , b mupper bounds u 1 , . . . , u nlower bounds l 1 , . . . , l nvariables orunknowns

    x 1 , . . . , x n

    In the most basic linear optimization problem, the variables of the objectivefunction are continuous in the mathematical sense, with no gaps between realvalues. To solve such linear programming problems, CPLEX implementsoptimizers based on the simplex algorithms (both primal and dual simplex) as wellas primal-dual logarithmic barrier algorithms and a sifting algorithm. Thesealternatives are explained more fully in Chapter 10, “Solving LPs: simplexoptimizers,” on page 133.

    CPLEX can also handle certain problems in which the objective function is notlinear but quadratic. Such problems are known as quadratic programs or QPs.Chapter 13, “Solving problems with a quadratic objective (QP),” on page 185,covers those kinds of problems.

    CPLEX also solves certain kinds of quadratically constrained problems. Suchproblems are known as quadratically constrained programs or QCPs. Chapter 14,“Solving problems with quadratic constraints (QCP),” on page 197, tells you moreabout the kinds of quadratically constrained problems that CPLEX solves,including the special case of second order cone programming (SOCP) problems.

    CPLEX is also a tool for solving mathematical programming problems in whichsome or all of the variables must assume integer values in the solution. Suchproblems are known as mixed integer programs or MIPs because they maycombine continuous and discrete (for example, integer) variables in the objectivefunction and constraints. MIPs with linear objectives are referred to as mixed integerlinear programs or MILPs, and MIPs with quadratic objective terms are referred toas mixed integer quadratic programs or MIQPs. Likewise, MIPs that are alsoquadratically constrained in the sense of QCP are known as mixed integerquadratically constrained programs or MIQCPs.

    Within the category of mixed integer programs, there are two kinds of discreteinteger variables: if the integer values of the discrete variables must be either 0(zero) or 1 (one), then they are known as binary; if the integer values are notrestricted in that way, they are known as general integer variables. This manual

    xiv CPLEX User’s Manual

  • explains more about the mixed integer optimizer in Chapter 15, “Solving mixedinteger programming problems (MIP),” on page 217.

    CPLEX also offers a network optimizer aimed at a special class of linear problemwith network structures. CPLEX can optimize such problems as ordinary linearprograms, but if CPLEX can extract all or part of the problem as a network, then itwill apply its more efficient network optimizer to that part of your problem anduse the partial solution it finds there to construct an advanced starting point tooptimize the rest of the problem. Chapter 12, “Solving network-flow problems,” onpage 177 offers more detail about how the CPLEX network optimizer works.

    What you need to knowSuggests prerequisites for using CPLEX.

    The manual assumes that you are familiar with CPLEX from reading GettingStarted with CPLEX and from following the tutorials there. Before you begin usingCPLEX, it is a good idea to read Getting Started with CPLEX and to try the tutorialsin it. It is available in the standard distribution of the product.

    In order to use CPLEX effectively, you need to be familiar with your operatingsystem, whether UNIX or Windows.

    This manual assumes that you are familiar with the concepts of mathematicalprogramming, particularly linear programming. In case those concepts are new toyou, the bibliography in “Further reading” on page xx in this preface indicatesreferences to help you there.

    This manual also assumes you already know how to create and manage files. Inaddition, if you are building an application that uses the Component Libraries, thismanual assumes that you know how to compile, link, and execute programswritten in a high-level language. The Callable Library is written in the Cprogramming language, while Concert Technology is written in C++, Java, and.NET. This manual also assumes that you already know how to program in theappropriate language and that you will consult a programming guide when youhave questions in that area.

    Examples onlineDescribes examples delivered with the product.

    For the examples explained in the manual, you will find the complete code for thesolution in the examples subdirectory of the standard distribution of CPLEX, sothat you can see exactly how CPLEX fits into your own applications. Table 1 liststhe examples in this manual and indicates where to find them.

    Table 1. Examples

    Example Source File In This Manual

    dietary optimization:building a model by rows(constraints) or by columns(variables), solving withIloCplex in C++

    ilodiet.cpp “Example: optimizing thediet problem in C++” onpage 21

    Meet CPLEX xv

  • Table 1. Examples (continued)

    Example Source File In This Manual

    dietary optimization:building a model by rows(constraints) or by columns(variables), solving withIloCplex in Java

    Diet.java “Example: optimizing thediet problem in Java” onpage 45

    dietary optimization:building a model by rows(constraints) or by columns(variables), solving withCplex in C#.NET

    Diet.cs “Example: optimizing thediet problem in C#.NET” onpage 56

    dietary optimization:building a model by rows(constraints) or by columns(variables), solving with theCallable Library

    diet.c “Example: optimizing thediet problem in the CallableLibrary” on page 72

    linear programming: startingfrom an advanced basis ilolpex6.cpp

    lpex6.c

    “Example ilolpex6.cpp” onpage 155

    “Example lpex6.c” on page156

    network optimization: usingthe Callable Library

    netex1.c “Example: using the networkoptimizer with the CallableLibrary netex1.c” on page181

    network optimization:relaxing a network flow toan LP

    netex2.c “Example: network to LPtransformation netex2.c” onpage 184

    quadratic programming:maximizing a QP iloqpex1.cpp

    QPex1.java

    qpex1.c

    “Example: iloqpex1.cpp” onpage 193

    “Example: QPex1.java” onpage 194

    “Example: qpex1.c” on page194

    quadratic programming:reading a QP from aformatted file

    qpex2.c “Example: reading a QP froma file qpex2.c” on page 195

    quadratically constrainedprogramming: QCP qcpex1.c

    iloqcpex1.cpp

    QCPex1.java

    “Examples: QCP” on page213

    second order coneprogramming: SOCP socpex1.c

    ilosocpex1.cpp

    SocpEx1.java

    “Examples: SOCP” on page213

    xvi CPLEX User’s Manual

  • Table 1. Examples (continued)

    Example Source File In This Manual

    mixed integer programming:optimizing a basic MIP ilomipex1.cpp

    mipex1.c

    “Examples: optimizing asimple MIP problem” onpage 272

    mixed integer programming:reading a MIP from aformatted file

    ilomipex2.cpp

    mipex2.c

    “Example: reading a MIPproblem from a file” on page273

    mixed integer programming:using special ordered sets(SOS) and priority orders

    ilomipex3.cpp

    mipex3.c

    “Example: using SOS andpriority” on page 304

    cutting stock: using columngeneration

    cutstock.cpp “What is columngeneration?” on page 337

    transport: piecewise-linearoptimization

    transport.cpp “Complete program:transport.cpp” on page 320

    food manufacturing 2: usinglogical constraints

    foodmanufac.cpp Chapter 23, “Using logicalconstraints:Food Manufacture 2,” onpage 331

    early tardy scheduling etsp.cpp Chapter 25, “Early tardyscheduling,” on page 345

    input and output: using themessage handler

    lpex5.c “Example: Callable Librarymessage channels” on page115

    using query routines lpex7.c “Example: using queryroutines lpex7.c” on page 77

    using callbacksilolpex4.cpp

    lpex4.c

    iloadmipex5.cpp

    “Example: deriving thesimplex callbackilolpex4.cpp” on page 491

    “Example: using callbackslpex4.c” on page 493

    “Example: controlling cutsiloadmipex5.cpp” on page494

    using the tuning tool tuneset.c “Meet the tuning tool” onpage 121 and “Examples:time limits on tuning in theInteractive Optimizer” onpage 125

    mixed integer programming:solution pool

    location.lp “Example: simple facilitylocation problem” on page279

    Notation in this manualDocuments notation in this manual.

    Like the reference manuals, this manual uses the following conventions:v Important ideas are italicized the first time they appear.

    Meet CPLEX xvii

  • v The names of C routines and parameters in the CPLEX Callable Library beginwith CPX ; the names of C++ and Java classes in CPLEX Concert Technologybegin with Ilo; and both appear in this typeface, for example:CPXcopyobjnames or IloCplex.

    v The names of .NET classes and interfaces are the same as the correspondingentity in Java, except the name is not prefixed by Ilo . Names of .NET methodsare the same as Java methods, except the .NET name is capitalized (that is,uppercase) to conform to Microsoft naming conventions.

    v Where use of a specific language (C++, Java, C, C#, and so on) is unimportantand the effect on the optimization algorithms is emphasized, the names ofCPLEX parameters are given as their Concert Technology variant. The CPLEXParameters Reference Manual documents the correspondence of these names to theCallable Library and the Interactive Optimizer.

    v Text that is entered at the keyboard or displayed on the screen and commandsand their options available through the Interactive Optimizer appear in thistypeface, for example, set preprocessing aggregator n .

    v Values that you must supply (for example, the value to set a parameter) alsoappear in the same typeface as the command but modified to indicate you mustsupply an appropriate value; for example, set simplex refactor i specifies thatyou must supply a value for i.

    v Matrices are denoted in two ways:– In printable material where superscripts and bold type are available, the

    product of A and its transpose is denoted like this: AAT. The superscript Tindicates the matrix transpose.

    – In computer-generated samples, such as log files, where only ASCII charactersare available, the product of A and its transpose are denoted like this: A*A’ .The asterisk (*) indicates matrix multiplication, and the prime (') indicates thematrix transpose.

    Related documentationDescribes other available documentation of the product.

    The online information files are distributed with the CPLEX libraries.

    The complete documentation set for CPLEX consists of the following material:v Getting Started: It is a good idea for new users of CPLEX to start with that

    manual. It introduces CPLEX through the Interactive Optimizer, and containstutorials for CPLEX Concert Technology for C++, Java, and .NET applications aswell as the CPLEX Callable Library.Getting Started is supplied in HTML and as an Eclipse plugin for use in IBMHelp System based on Eclipse.

    v User’s Manual: This manual explains the topics covered in the Getting Startedmanual in greater depth, with individual chapters about:– LP (Linear Programming) problems;– Network-flow problems;– QP (Quadratic Programming) problems;– QCP (Quadratically Constrained Programming), including the special case of

    second order cone programming (SOCP) problems, and– MIP (Mixed Integer Programming) problems.

    There is also detailed information about:– tuning performance,

    xviii CPLEX User’s Manual

  • – managing input and output,– generating and keeping multiple solutions in the solution pool,– using query routines,– using callbacks, and– using parallel optimizers.

    The CPLEX User’s Manual is supplied in HTML and as an Eclipse plugin foruse in the IBM Help System based on Eclipse.

    v Overview of the API offers you navigational links into the HTML referencemanual organized into categories of tasks you may want to perform in yourapplications. Each category includes a table linking to the corresponding Croutine, C++ class or method, and Java interface, class, or method to accomplishthe task. There are also indications about the name of the corresponding .NETmethod.

    v Callable Library Reference Manual: This manual supplies detailed definitionsof the routines, macros, and functions in the CPLEX C application programminginterface (API). It is available online as HTML and as an Eclipse plugin for usein the IBM Help System based on Eclipse. The routines are organized intogroups, such as optim.cplex.callable.optimizers , optim.callable.debug , oroptim.cplex.callable.callbacks , to help you locate routines by their purpose.As part of that online manual, you can also access other reference material:– CPLEX Error Codes documents error codes by name in the group

    optim.cplex.errorcodes . You can also access error codes by number in theOverview of the API through the link Interpreting Error Codes.

    – CPLEX Solution Quality Codes documents solution quality codes by name inthe group optim.cplex.solutionquality.

    – CPLEX Solution Status Codes documents solution status codes by name in thegroup optim.cplex.solutionstatus. You can also access solution status codesby number in the Overview of the API through the link Interpreting SolutionStatus Codes.

    v CPLEX C++ API Reference Manual: This manual supplies detailed definitionsof the classes, macros, and functions in the CPLEX C++ applicationprogramming interface (API). It is available online as HTML and as an Eclipseplugin for use in the IBM Help System based on Eclipse.

    v CPLEX Java API Reference Manual: This manual supplies detailed definitionsof the Concert Technology interfaces and CPLEX Java classes. It is availableonline as HTML and as an Eclipse plugin for use in the IBM Help System basedon Eclipse.

    v CPLEX .NET Reference Manual: This manual documents the .NET API ofConcert Technology for CPLEX. It is available online as HTML and as an Eclipseplugin for use in the IBM Help System based on Eclipse.

    v CPLEX Python API Reference Manual: This manual documents the Python APIof CPLEX. It is available online as HTML and as an Eclipse plugin for use in theIBM Help System based on Eclipse.

    v CPLEX Parameters Reference Manual: This manual lists the parameters ofCPLEX with their names in the Callable Library, in Concert Technology, and inthe Interactive Optimizer. It also shows their default settings with explanationsof the effect of other settings. Normally, the default settings of CPLEX solve awide range of mathematical programming problems without intervention onyour part, but these parameters are available for fine tuning in special cases.

    v CPLEX File Formats Reference Manual: This manual documents the file formatsrecognized and supported by CPLEX.

    Meet CPLEX xix

  • v CPLEX Interactive Optimizer Commands: This manual lists the commands ofthe Interactive Optimizer, along with their options and links to examples of theiruse in the CPLEX User’s Manual.

    Online servicesDescribes the optimization forum.

    CPLEX supports an online forum for discussion of topics in optimization,mathematical programming, and CPLEX. These forums are accessible through theInternet at http://www.ibm.com/developerworks/forums.

    Further readingRecommends further reading about related topics.

    In case you want to know more about optimization and mathematical or linearprogramming, here is a brief selection of printed resources:

    Williams, H. P. Model Building in Mathematical Programming, fourth edition.New York: John Wiley & Sons, 1999. This textbook includes many examples of howto design mathematical models, including linear programming formulations. (Howyou formulate your model is at least as important as what CPLEX does with it.) Italso offers a description of the branch & bound algorithm. In fact, Williams’s bookinspired some of the models delivered with CPLEX.

    Chvatal, Vasek, Linear Programming, New York: W.H. Freeman and Company,1983. This standard textbook for undergraduate students introduces both theoryand practice of linear programming.

    Wolsey, Laurence A., Integer Programming, New York: John Wiley & Sons, 1998.This book explains branch and cut, including cutting planes, in detail.

    Nemhauser, George L. and Laurence A. Wolsey, Integer and CombinatorialOptimization, New York: John Wiley & Sons, 1999. A reprint of the 1988 edition,this book is a widely cited and comprehensive reference about integerprogramming.

    Gill, Philip E., Walter Murray, and Margaret H. Wright, Practical Optimization.New York: Academic Press, 1982 reprint edition. This book covers, among othertopics, quadratic programming.

    For more information about ill-conditioning and numerical difficulties, see alsothese references:v Higham, Nicholas J., Accuracy and Stability of Numerical Algorithms, Society

    for Industrial and Applied Mathematics (SIAM), 2002.v Duff, Iain S., A. M. Erisman, John Ker Reid, Direct Methods for Sparse Matrices

    Clarendon Press, 1989.v Gill, Philip E., Walter Murray, Margaret H. Wright, Practical Optimization,

    Academic Press, 1981.v Golub, Gene Howard, Charles F. Van Loan, Matrix Computations, The Johns

    Hopkins University Press, 1983.

    xx CPLEX User’s Manual

  • Part 1. Languages and APIs

    This part of the manual collects topics about each of the application programminginterfaces (APIs) available for IBM ILOG CPLEX. It is not necessary to read eachof these topics thoroughly. In fact, most users will concentrate only on the topicabout the API that they plan to use, whether C, C++, Java, or .NET.

    © Copyright IBM Corp. 1987, 2015 1

  • 2 CPLEX User’s Manual

  • Chapter 1. Concert Technology for C++ users

    Explores the features CPLEX offers to users of C++ to solve mathematicalprogramming problems.

    OverviewHighlights the design, architecture, modeling facilities for C++ users of CPLEX.

    This topic explains the design of the library, explains modeling techniques, andoffers an example of programming with Concert Technology in C++. It alsoprovides information about controlling parameters in a C++ application. It showshow to write C++ applications using CPLEX Concert Technology for C++ users. Italso includes information about compiling and linking your applications.

    Architecture of a CPLEX C++ applicationDescribes the architecture of a conventional CPLEX application in C++.

    Figure 1 on page 4 shows a program using CPLEX Concert Technology to solveoptimization problems. The optimization part of the user’s application program iscaptured in a set of interacting C++ objects that the application creates andcontrols. These objects can be divided into two categories:v Modeling objects are used to define the optimization problem. Generally an

    application creates several modeling objects to specify the optimizationproblems. Those objects are grouped into an IloModel object representing thecomplete optimization problem.

    v Solving objects in an instance of IloCplex are used to solve models created withthe modeling objects. An instance of IloCplex reads a model and extracts itsdata to the appropriate representation for the CPLEX optimizers. Then theIloCplex object is ready to solve the model it extracted. After it solves a model,it can be queried for solution information.

    © Copyright IBM Corp. 1987, 2015 3

  • Compiling and linkingTells where to find instructions to compile and link a C++ application usingCPLEX.

    Compilation and linking instructions are provided with the files that come in thestandard distribution of CPLEX for your computer platform. Check thereadme.html file for details.

    Creating a C++ application with Concert TechnologyOutlines steps to create a C++ application with CPLEX.

    About this task

    These are the steps most applications are likely to entail.

    Procedure1. First, create a model of your problem with the modeling facilities of Concert

    Technology. “Modeling an optimization problem with Concert Technology” onpage 5 offers an introduction to creating a model.

    2. When the model is ready to be solved, hand it over to CPLEX for solving.“Solving the model” on page 9 explains how to do so. It includes a survey ofthe IloCplex interface for controlling the optimization. Individual controls arediscussed in the chapters explaining the individual optimizers.

    3. After CPLEX solves the model, “Accessing solution information” on page 14,shows you how to access and interpret results from the optimization.

    Figure 1. A view of Concert Technology for C++ users

    4 CPLEX User’s Manual

  • 4. After analyzing the results, you may want to make changes to the model andstudy their effect. “Modifying a model” on page 17 explains how to makechanges and how CPLEX deals with them.

    5. “Handling errors” on page 20, discusses the error handling and debuggingsupport provided by Concert Technology and CPLEX.

    6. “Example: optimizing the diet problem in C++” on page 21 presents acomplete program.

    Results

    Not covered in this chapter are advanced features, such as the use of goals orcallbacks for querying data about an ongoing optimization and for controlling theoptimization itself. Goals, callbacks, and other advanced features are discussed inPart 7, “Advanced programming techniques,” on page 451.

    Modeling an optimization problem with Concert TechnologyIntroduces classes of the C++ API of Concert Technology for modelingoptimization problems to be solved by IloCplex.

    OverviewHighlights the C++ classes for models in CPLEX.

    A Concert Technology model consists of a set of C++ objects. Each variable, eachconstraint, each special ordered set (SOS), and the objective function in a model areall represented by objects of the appropriate Concert Technology class. Theseobjects are known as modeling objects. They are summarized in the table Table 2on page 9.

    Creating the environment: IloEnvDescribes the C++ class IloEnv.

    Before you create modeling objects, you must construct an object of the classIloEnv . This object known as the environment. It is constructed with thestatement:IloEnv env;

    That statement is usually the first Concert Technology statement in an application.At the end, you must close the environment by calling:env.end();

    That statement is usually the last Concert Technology statement in an application.The end method must be called because, like most Concert Technology classes, theclass IloEnv is a handle class. That is, an IloEnv object is really only a pointer toan implementation object. Implementation objects are destroyed by calling the endmethod. Failure to call the end method can result in memory leaks.

    Users familiar with the CPLEX Callable Library are cautioned not to confuse theConcert Technology environment object with the CPLEX environment object oftype CPXENVptr, used to set CPLEX parameters. Such an object is not needed withConcert Technology, as parameters are handled directly by each instance of theclass IloCplex. In other words, the environment in Concert Technology alwaysrefers to the object of class IloEnv required for all other Concert Technologyobjects.

    Chapter 1. Concert Technology for C++ users 5

  • Defining variables and expressions: IloNumVarDescribes the C++ class IloNumVar.

    Probably the first modeling class you will need is IloNumVar . Objects of this classrepresent decision variables in a model. They are defined by the lower and upperbound for the variable, and a type which can be one of ILOFLOAT , ILOINT , orILOBOOL for continuous, integer, or Boolean variables, respectively. The followingconstructor creates an integer variable with bounds -1 and 10:IloNumVar myIntVar(env, -1, 10, ILOINT);

    The class IloNumVar provides methods that allow querying of the data needed tospecify a variable. However, only bounds can be modified. Concert Technologyprovides a modeling object class IloConversion to change the type of a variable.This conversion allows you to use the same variable with different types indifferent models.

    Variables are usually used to build up expressions, which in turn are used todefine the objective or constraints of the optimization problem. An expression canbe explicitly written, as in1*x[1] + 2*x[2] + 3*x[3]

    where x is assumed to be an array of variables (IloNumVarArray ). Expressions canalso be created piece by piece, with a loop:IloExpr expr(env);for (int i = 0; i < x.getSize(); ++i)

    expr += data[i] * x[i];

    Whenever possible, build your expressions in terms of data that is either integer ordouble-precision (64-bit) floating point. Single-precision (32-bit) floating point datashould be avoided, as it can result in unnecessarily ill conditioned problems. Formore information, refer to “Numeric difficulties” on page 146.

    While Concert Technology supports very general expressions, only linear,quadratic, piecewise-linear, and logical expressions can be used in models to besolved with IloCplex . For more about each of those possibilities, see these topics:v Chapter 10, “Solving LPs: simplex optimizers,” on page 133 and Chapter 11,

    “Solving LPs: barrier optimizer,” on page 157 both discuss linear expressions.v Chapter 13, “Solving problems with a quadratic objective (QP),” on page 185

    discusses quadratic expressions in an objective function.v Chapter 14, “Solving problems with quadratic constraints (QCP),” on page 197

    discusses quadratic expressions in quadratically constrained programmingproblems (QCPs), including the special case of second order cone programming(SOCP) problems.

    v Chapter 20, “Using piecewise linear functions in optimization: a transportexample,” on page 311 introduces piecewise-linear expressions through atransportation example.

    v Chapter 22, “Logical constraints in optimization,” on page 325 introduces logicalconstraints handled by CPLEX. Topics following it offer examples.

    When you have finished using an expression (that is, you created a constraint withit) you need to delete it by calling its method end , for example:expr.end();

    6 CPLEX User’s Manual

  • Declaring the objective: IloObjectiveDescribes the C++ class IloObjective.

    Objects of class IloObjective represent objective functions in optimization models.IloCplex may only handle models with at most one objective function, though themodeling API provided by Concert Technology does not impose this restriction. Anobjective function is specified by creating an instance of IloObjective . Forexample:IloObjective obj(env,

    1*x[1] + 2*x[2] + 3*x[3],IloObjective::Minimize);

    defines the objective to minimize the expression 1*x[1] + 2*x[2] + 3*x[3].

    Adding constraints: IloConstraint and IloRangeDescribes the C++ classes for constraints and ranges.

    Similarly, objects of the class IloConstraint represents constraints in your model.Most constraints will belong to the subclass IloRange , derived fromIloConstraint, and thus inherit its constructors and methods. IloRange representconstraints of the form lower bound ≤ expression ≤ upper bound . In otherwords, an instance of IloRange is a convenient way to express a ranged constraint,that is, a constraint with explicit upper or lower bounds. Any floating-point valueor +IloInfinity or -IloInfinity can be used for the bounds. For example:IloRange r1(env, 3.0, x[1] + x[2], 3.0);

    defines the constraint x[1] + x[2] == 3.0 .

    Formulating a problem: IloModelDescribes the C++ class IloModel.

    To formulate a full optimization problem, you need to create the objects that arepart of it and add them to an instance of IloModel, the class that representsoptimization problems. For example, these lines:IloModel model(env);model.add(obj);model.add(r1);

    define a model consisting of the objective obj , constraint r1 , and all the variablesthey use. Notice that variables need not be added to a model explicitly, as they areimplicitly considered if any of the other modeling objects in the model use them.(However, you may explicitly add variables to a model, for example, if youconsider a variable a part of the problem even though it does not appear in aconstraint or objective function.)

    For convenience, Concert Technology provides the functions IloMinimize andIloMaximize to define minimization and maximization objective functions. Also,operators = are overloaded to create IloRange constraints. Thesefeatures allow you to rewrite that example in a compact and readable way, likethis:IloModel model(env);model.add(IloMinimize(env, 1*x[1] + 2*x[2] + 3*x[3]);model.add(x[1] + x[2] == 3.0);

    Chapter 1. Concert Technology for C++ users 7

  • With this notation, you need not create the C++ variables obj and r1 explicitly (asoriginally in the example). Instead, they are expressed through the variables in thissecond example.

    The class IloModel is itself a class of modeling objects. Thus, one model can beadded to another. A possible use of this feature is to capture different scenarios indifferent models, all of which are extensions of a core model. The core model couldbe represented as an IloModel object itself and added to the IloModel objects thatrepresent the individual scenarios.

    Managing dataDescribes C++ classes to manage data.

    Usually the data of an optimization problem must be collected before or during thecreation of the Concert Technology representation of the model. Though, inprinciple, modeling does not depend on how the data is generated andrepresented, this task may be facilitated by the array classes or set classes, suchasIloNumSet, provided by Concert Technology.

    For example, objects of class IloNumArray can be used to store numeric data inarrays. Elements of the class IloNumArray can be accessed like elements of standardC++ arrays, but the class also offers a wealth of additional features. For example,Concert Technology arrays are extensible; in other words, they transparently adaptto the required size when new elements are added using the method add .Conversely, elements can be removed from anywhere in the array with the methodremove . Concert Technology arrays also provide debugging support whencompiled in debug mode by using assert statements to make sure that no elementbeyond the array bounds is accessed. Input and output operators (that is,operator >) are provided for arrays. For example, the code:

    IloNumArray data(env, 3, 1.0, 2.0, 3.0);cout data;

    The “Example: optimizing the diet problem in C++” on page 21 takes advantage ofthis function and reads the problem data from a file.

    Finally, Concert Technology provides the template class IloArray to create arrayclasses for your own type X. This technique can be used to generatemultidimensional arrays. All the functions mentioned here are supported forIloArray classes except for input/output, which depends on the input and outputoperator being defined for type X.

    8 CPLEX User’s Manual

  • Solving the modelDescribes facilities for solving a model in the C++ API.

    OverviewIntroduces the C++ class IloCplex.

    CPLEX generally does not need to be involved while you create your model.However, after the model is set up, it is time to create your cplex object, that is, aninstance of the class IloCplex, to be used to solve the model. IloCplex is a classderived from IloAlgorithm. There are other Concert Technology algorithm classes,also derived from IloAlgorithm, as documented in the CPLEX C++ API ReferenceManual. Some models might also be solved by using other algorithms, such as theclass IloCP for constraint programming, or by using a hybrid algorithm consistingof both CP Optimizer and CPLEX. Some models, on the other hand, cannot besolved with CPLEX.

    The makeup of the model determines whether or not CPLEX can solve it. Moreprecisely, in order to be handled by IloCplex objects, a model may only consist ofmodeling objects of the classes listed in Table 2.

    Instances of IloConstraint extracted by CPLEX can be created in a variety ofways. Most often, they can be generated by means of overloaded C++ operators,such as == , = , in the form expression1 operator expression2 . Instancesof both IloConstraint and IloRange generated in that way may be built fromeither linear or quadratic expressions. Constraints and ranges may also includepiecewise linear terms. (Other sections of this manual, not specific to C++, showyou how to use quadratic expressions: Chapter 13, “Solving problems with aquadratic objective (QP),” on page 185 and Chapter 14, “Solving problems withquadratic constraints (QCP),” on page 197. Likewise, Chapter 20, “Using piecewiselinear functions in optimization: a transport example,” on page 311 shows you howto apply piecewise linear terms in a C++ application.)

    For more detail about solving problems with IloCplex , see the following sectionsof this manual.

    Table 2. Concert Technology modeling objects in C++

    To model: Use:

    numeric variables objects of the class IloNumVar , as long asthey are not constructed with a list offeasible values

    semi-continuous variables objects of the class IloSemiContVar

    linear objective function an object of the class IloObjective withlinear or piecewise linear expressions

    quadratic objective function an object of the class IloObjective withquadratic expressions

    Chapter 1. Concert Technology for C++ users 9

  • Table 2. Concert Technology modeling objects in C++ (continued)

    To model: Use:

    linear constraintsobjects of the class IloRange

    (lower bound

  • cplex.extract(model);

    This method copies the data from the model into the appropriate efficient datastructures, which CPLEX uses for solving the problem. It does so by extractingeach of the modeling objects added to the model and each of the objects referencedby them. For every extracted modeling object, corresponding data structures arecreated internally in the cplex object. For readers familiar with the sparse matrixrepresentation used internally by CPLEX, a variable becomes a column and aconstraint becomes a row. As discussed later, these data structures aresynchronized with the modeling objects even if the modeling objects are modified.

    If you consider a variable to be part of your model, even though it is not (initially)used in any constraint, you should add this variable explicitly to the model. Thispractice makes sure that the variable will be extracted. This practice may also beimportant if you query solution information for the variable, since solutioninformation is available only for modeling objects that are known to CPLEXbecause they have been extracted from a model.

    If you feel uncertain about whether or not an object will be extracted, you can addit to the model to be sure. Even if an object is added multiple times, it will beextracted only once and thus will not slow the solution process down.

    Since the sequence of creating the cplex object and extracting the model to it issuch a common one, IloCplex provides the shortcut:IloCplex cplex(model);

    This shortcut is completely equivalent to separate calls and makes sure that theenvironment used for the cplex object will be the same as that used for the modelwhen it is extracted, as required by Concert Technology. The shortcut uses theenvironment from the model to construct the cplex object before extraction.

    Invoking a solverDescribes the method that invokes a solver in the C++ API.

    After the model is extracted to the cplex object, you are ready to solve it by calling

    solve();

    For most problems this is all that is needed for solving the model. Nonetheless,CPLEX offers a variety of controls that allow you to tailor the solution process foryour specific needs.

    Choosing an optimizerDescribes the optimizers available in the C++ API.

    Solving the extracted model with CPLEX involves solving one or a series ofcontinuous relaxations:v Only one continuous relaxation needs to be solved if the extracted model is

    continuous itself, that is, if it does not contain integer variables, Booleanvariables, semi-continuous or semi-integer variables, logical constraints, specialordered sets (SOS), or piecewise linear functions. Chapter 10, “Solving LPs:simplex optimizers,” on page 133 and Chapter 11, “Solving LPs: barrieroptimizer,” on page 157 discuss the algorithms available for solving LPs.Similarly, Chapter 13, “Solving problems with a quadratic objective (QP),” onpage 185, discusses the algorithms available for solving QPs. Chapter 14,

    Chapter 1. Concert Technology for C++ users 11

  • “Solving problems with quadratic constraints (QCP),” on page 197 re-introducesthe barrier optimizer in the context of quadratically constrained programmingproblems (QCPs). Chapter 20, “Using piecewise linear functions in optimization:a transport example,” on page 311 introduces piecewise-linear functions througha transportation example. Chapter 22, “Logical constraints in optimization,” onpage 325 introduces logical constraints, and chapters following it offer examples.

    v In all other cases, the extracted problem that CPLEX sees is indeed a MIP and,in general, a series of continuous relaxations needs to be solved. The methodcplex.isMIP returns IloTrue in such a case. Chapter 15, “Solving mixed integerprogramming problems (MIP),” on page 217 discusses the algorithms applied.

    The optimizer option used for solving the first continuous relaxation (whether it isthe only one or just the first in a series of problems) is controlled by the rootalgorithm parameter:cplex.setParam(IloCplex::RootAlg, alg);

    where alg is a member of the nested enumeration IloCplex_Algorithm.

    As a nested enumeration, the fully qualified names that must be used in theprogram are IloCplex::Primal, IloCplex::Dual, and so on. Table 3 displays themeaning of the optimizer options defined by IloCplex::Algorithm.

    Tip:

    The choice Sifting is not available for QP models. Only the Barrier option isavailable for QCP models. Table 4 summarizes these options.

    Table 3. Optimizer options in IloCplex::AlgorithmAutoAlg let CPLEX decide which algorithm to usePrimal use the primal simplex algorithmDual use the dual simplex algorithmNetwork use the primal network simplex algorithm on

    an embedded network followed by the dualsimplex algorithm for LPs and the primalsimplex algorithm for QPs on the entireproblem

    Barrier use the barrier algorithm. The type ofcrossover performed after the barrieralgorithm is set by the parameterIloCplex::BarCrossAlg .

    Sifting use the sifting algorithmConcurrent use multiple algorithms concurrently on a

    multiprocessor system

    Table 4. Algorithm available at root by problem type

    Value Algorithm TypeLP?

    MILP?

    QP?

    MIQP?

    QCP?

    MIQCP?

    0 IloCplex::AutoAlgyes yes yes

    1 IloCplex::Primal yes yes not available

    2 IloCplex::Dual yes yes not available

    3 IloCplex::Networkyes yes not available

    4 IloCplex::Barrieryes yes yes

    12 CPLEX User’s Manual

  • Table 4. Algorithm available at root by problem type (continued)

    Value Algorithm TypeLP?

    MILP?

    QP?

    MIQP?

    QCP?

    MIQCP?

    5 IloCplex::Siftingyes not available not available

    6 IloCplex::Concurrentyes yes not available

    If the extracted model requires the solution of more than one continuousrelaxation, the algorithm for solving the first one at the root is controlled by theRootAlg parameter. The algorithm at all other nodes except the root is controlledby the NodeAlg parameter:cplex.setParam(IloCplex::NodeAlg, alg)

    Table 5 summarizes the options available at nodes.

    Table 5. Algorithm types for NodeAlg

    Value Algorithm Type MILP? MIQP? MIQCP?

    0 IloCplex::Auto yes yes yes

    1 IloCplex::Primal yes yes not available

    2 IloCplex::Dual yes yes not available

    3 IloCplex::Networkyes not available not available

    4 IloCplex::Barrieryes yes yes

    5 IloCplex::Siftingyes not available not available

    Controlling the optimizersDescribes parameters that control the optimizers in the C++ API.

    Though CPLEX defaults will prove sufficient to solve most problems, CPLEX offersa variety of parameters to control various algorithmic choices. CPLEX parameterscan assume values of type bool, num, int, and string. IloCplex provides fourcategories of parameters that are listed in the nested enumeration types:v IloCplex_BoolParamv IloCplex_IntParamv IloCplex_NumParamv IloCplex_StringParam

    To access the current value of a parameter that interests you from ConcertTechnology, use the method getParam. To access the default value of a parameter,use the method getDefault. Use the methods getMin and getMax to access theminimum and maximum values of num and int type parameters.

    Some integer par


Recommended