Connecting Constraint Solvers to AMPL ------------------------------------- Victor Zverovich, Robert Fourer
AMPL Optimization
CPAIOR 2013, Yorktown Heights, NY, USA May 18-22, 2013
Why 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.
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 was connected in 2012, JaCoP - in early 2013.
AMPL Solver Library ------------------- AMPL Solver Library (ASL) is an open-source library for connecting solvers to AMPL. * C interface: - described in [Hooking Your Solver to AMPL](http://www.ampl.com/hooking.html) - used by most non-CP solvers * [C++ interface](https://github.com/vitaut/ampl/tree/master/solvers/util): - makes connecting new solvers super easy - type-safe: no casts needed when working with expression trees - efficient: no overhead compared to the C interface - used by the gecode, ilogcp and jacop (via JNI) drivers
AMPL Solver Architecture ------------------------ * Driver library is optional but facilitates testing. * The test suite is used to verify correctness of driver implementation. * The test suite is solver independent and can be reused when connecting a new solver.
Connecting Java Solvers ------------------------ * JNI allows using ASL via the C++ API * The JaCoP driver can be used as an example * Initialization is tricky on Windows (delay loading of jvm.dll, check installation path in registry, ...)

Expression Trees

Performance Considerations --------------------------

Map AMPL expressions into the most efficient solver equivalents.

Examples:

* numberof with constant values
-> IloDistribute (ilogcp)
controlled by the usenumberof option * if *logical-expr* then 1 (else 0)
-> channel constraint (gecode)
Supporting Multiple Solvers --------------------------- * Separate hierarchies for logical and numeric expressions (ilogcp and gecode) are handled easily * Possible to deal with more complex expression hierarchies, but with more efforts * Not necessary to convert all expressions, solver will report an error when unhandled expression is encountered and exit gracefully.
Examples --------

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

Summary ------- * AMPL now supports multiple constraint programming solvers. * Connecting new solvers is super easy especially with the new C++ API. * Java solvers are supported as well.
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) * Downloads for 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 new 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)