The AMPL Interface to Constraint Programming Solvers ---------------------------------------------------- Victor Zverovich, Robert Fourer
AMPL Optimization

The 13th INFORMS Computing Society Conference (ICS)
January 6th - 8th, 2013, Santa Fe, New Mexico, USA
Why AMPL? --------- * [AMPL]( is a popular algebraic modeling language: - used in businesses, government agencies, and academic institutions (over 100 courses in 2012) - large community
(> 1,300 members in [AMPL Google Group]( alone) - the most popular input format on [NEOS](
(> 200,000 or 57% submissions in 2012) * AMPL supports a wide range of problem types: linear, mixed integer, quadratic, second-order cone, nonlinear, complementarity problems and more.
Constraint Programming in AMPL ------------------------------ * [Constraint programming]( (CP) allows natural formulation of many combinatorial optimization problems. * AMPL has supported CP since early 2000s when the paper Extending an Algebraic Modeling Language to Support Constraint Programming [[1](] was published. * CP solvers connected to AMPL: - [IBM/ILOG CP Optimizer]( (ilogcp) - [Gecode](
AMPL Solver Library ------------------- AMPL Solver Library (ASL) is an open source library for connecting solvers to AMPL. * Available from: - Netlib: []( - GitHub: []( * Includes drivers for several solvers: - CPLEX - Gurobi - MINOS
AMPL Solver Interfaces ---------------------- * C interface: - described in [Hooking Your Solver to AMPL]( - used by most solvers * C++ interface (new): - a very thin wrapper around the C interface - type-safe, no casts needed when working with expression trees - easy to use, less boilerplate code - efficient - used by [ilogcp]( and [gecode](
Performance -----------
Time is in milliseconds.
Solver Workflow --------------- 1. Get a problem instance in AMPL form 2. Process solver options 3. Convert the problem from AMPL to solver form 4. Solve the problem 5. Return solution(s)
Step 3 is the most interesting especially for a CP solver, because it has to deal with expression trees. Other steps are easy to implement.
Choice of Language ------------------ Both IBM/ILOG CP Optimizer and Gecode use C++ for their main APIs. Therefore I'll give all examples in C++ with the new interface library. However, everything discussed here is possible to do with the C API with a bit more work.

Expression Trees

Expression Visitor ------------------
Copy the great architectures.
-- Edward Tufte

Two-Level Conversion -------------------- 1. Top level - global constraints such as `alldiff` and possible optimizations for the case when expression value is not used - ilogcp: no extra work is necessary, the Concert interface does necessary processing - gecode: manual handling of `alldiff` in `ConvertFullExpr` 2. General case for nested expressions Example: s.t. c: alldiff ({j in 1..n} Row[j]+j); `alldiff (...)` - top level expression `Row[j] + j` - subexpression
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. For example, gecode doesn't support many nonlinear expressions.
Links ----- * GitHub repository: []( * C++ Solver API: solvers/util * Gecode AMPL solver: solvers/gecode * IlogCP AMPL solver: solvers/ilogcp