Constraint Programming in AMPL ============================== Victor Zverovich
AMPL Optimization
CP Solvers: Modeling, Applications, Integration, and Standardization
CP2013, Uppsala, Sweden, September 16, 2013
About AMPL ---------- * [AMPL](http://www.ampl.com/) is a popular modeling system - used in businesses, government agencies, and academic institutions (over 100 courses in 2012) - large community
(> 1,400 members in [AMPL Google Group](https://groups.google.com/group/ampl) alone) - the most popular input format on [NEOS](http://www.neos-server.org/neos/)
(> 200,000 or 57% submissions in 2012) * AMPL is high-level, solver-independent and efficient. * Supports a variety of solvers and problem types: linear, mixed integer, quadratic, second-order cone, nonlinear, complementarity problems and more.
AMPL Application Areas ---------------------- * Transportation (air, rail, truck) * Production planning and supply chain * Finance (investment banking, insurance) * Natural resources (electric power, gas, mining) * Telecommunications * Internet services Examples: - clothing and accessories retailer
- paper manufacturer
Solver Support -------------- * AMPL provides consistent interface to a large number of solvers. * Switching between solvers is easy. * Connecting new solvers is easy using the open-source AMPL Solver Library. * Solver-specific features are supported such as the whole set of solver options. * Features missing in a solver are often implemented in an AMPL solver driver. Examples: meaningful solution log, reformulation of missing constructs.
AMPL User Interfaces -------------------- * Classical command-line interactive environment * Eclipse-based IDEs: - AMPL IDE - AMPLDev (adds stochastic programming features) * Solver Studio for Excel * Matlab (TOMLAB) * IPython (experimental)
AMPL IDE (Beta) --------------- Based on the Eclipse platform well-known for its Java and Android IDEs. Some of the features: * Cross-platform with native look and feel on each platform * Interactive console with command history * Context-sensitive syntax highlighting * Quick links to error locations * Solution process can be interrupted by a user at any time and the best solution found so far will be available * Freely available from [http://www.ampl.com/IDE/beta.html](http://www.ampl.com/IDE/beta.html)
AMPL IDE (Beta) ---------------
Solver Studio for Excel ----------------------- * Create and edit AMPL models without leaving Excel * Solve using local solvers or in the cloud via NEOS * Integrated model and data editors * Automatic data exchange with model * Freely available from [http://solverstudio.org](http://solverstudio.org/)
Solver Studio for Excel -----------------------
AMPL IPython Plugin -------------------
AMPL IPython Plugin -------------------
Database and Spreadsheet Access ------------------------------- * Crucial for integration into real-world applications * AMPL provides streamlined database access on major platforms
* Supports any database system that has an ODBC driver
History of CP Support in AMPL ----------------------------- * 1996: first experiments with adding logic programming features to AMPL. * Fourer (1998). *Extending a General-Purpose Algebraic Modeling Language to Combinatorial Optimization: A Logic Programming Approach* [[1](http://iems.northwestern.edu/~4er/WRITINGS/loglang.pdf)] * Fourer and Gay (2001). *Hooking a Constraint Programming Solver to an Algebraic Modeling Language* * Fourer and Gay (2002). *Extending an Algebraic Modeling Language to Support Constraint Programming* [[2](http://users.iems.northwestern.edu/~4er/WRITINGS/extmodcp.pdf)] * Initially [IBM/ILOG CP Optimizer](http://www-01.ibm.com/software/integration/optimization/cplex-cp-optimizer/) was connected. * [Gecode](http://www.gecode.org/) was connected in 2012, [JaCoP](http://www.osolpro.com/jacop/index.php) - in early 2013.
Example: Transportation Model ----------------------------- An example from a multicommodity transportation model [multmip3.mod](http://www.ampl.com/BOOK/EXAMPLES/EXAMPLES2/multmip3.mod) For every origin `i` and destination `j` the total shipments
`sum {p in PROD} Trans[i,j,p]` should be either zero or between `minload` and `limit[i,j]`. MIP formulation:

var Trans {ORIG,DEST,PROD} >= 0;
var Use {ORIG,DEST} binary;
subject to Multi {i in ORIG, j in DEST}:
  sum {p in PROD} Trans[i,j,p] <= limit[i,j] * Use[i,j];
subject to Min_Ship {i in ORIG, j in DEST}:
  sum {p in PROD} Trans[i,j,p] >= minload * Use[i,j];
  
Transportation Example using CP -------------------------------

Disjunctive constraint:


subject to Multi_Min_Ship {i in ORIG, j in DEST}:
  sum {p in PROD} Trans[i,j,p] = 0 or
  minload <= sum {p in PROD} Trans[i,j,p] <= limit[i,j];

Implication:


subject to Multi_Min_Ship {i in ORIG, j in DEST}:
  sum {p in PROD} Trans[i,j,p] > 0 ==>
    minload <= sum {p in PROD} Trans[i,j,p] <= limit[i,j];

* No need for auxiliary binary variables. * The formulation is more straightforward.
Scheduling Example using CP --------------------------- Using the `count` operator:

subj to CapacityOfMachine {k in MACHINES}:
   count {j in JOBS} (MachineForJob[j] = k) <= cap[k];

Using the `numberof` operator:

subj to CapacityOfMachine {k in MACHINES}:
   numberof k in ({j in JOBS} MachineForJob[j]) <= cap[k];

  • No need for \(n^2\) binary variables.
  • All the numberof constraints can be converted into a single IloDistribute constraint in ilogcp.
Work in Progress ---------------- * Variables in subscripts * Multiple solutions * Element constraint * Restart functionality in the Gecode driver * Use constraint suffixes (attributes) for fine-grained control over some of the search options, e.g. icl in Gecode.
Summary ------- * AMPL provides a consistent and intuitive interface to multiple constraint programming solvers. * CP functionality in AMPL is production-ready and new features are actively added. * New user interfaces make model development easier. * Database access functionality facilitates integration into real-world applications.
Links ----- * AMPL Logic and Constraint Programming Extensions: [http://www.ampl.com/NEW/LOGIC/](http://www.ampl.com/NEW/LOGIC/) * Trial version of AMPL with IBM/ILOG CP: [http://www.ampl.com/trial.html](http://www.ampl.com/trial.html) * Open-source AMPL solvers and libraries including Gecode: [https://code.google.com/p/ampl/](https://code.google.com/p/ampl/) * AMPL models by Hakan Kjellerstrand including 100 CP models: [http://www.hakank.org/ampl/](http://www.hakank.org/ampl/) * Source code for ilogcp, gecode and jacop interfaces on GitHub: [https://github.com/vitaut/ampl](https://github.com/vitaut/ampl)