Connecting Constraint Solvers to AMPL ------------------------------------- Victor Zverovich, Robert Fourer
AMPL Optimization
CPAIOR 2013, Yorktown Heights, NY, USA May 18-22, 2013
Why AMPL? --------- * [AMPL]( 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]( alone) - the most popular input format on [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](] * 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](] * Initially [IBM/ILOG 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]( - used by most non-CP solvers * [C++ interface]( - 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.


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


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: []( * Trial version of AMPL with IBM/ILOG CP: []( * Downloads for open-source AMPL solvers and libraries including Gecode: []( * AMPL models by Hakan Kjellerstrand including 100 new CP models: []( * Source code for ilogcp, gecode and jacop interfaces on GitHub: [](