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](http://www.ampl.com/) 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](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 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](http://en.wikipedia.org/wiki/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](http://users.iems.northwestern.edu/~4er/WRITINGS/extmodcp.pdf)] was published. * CP solvers connected to AMPL: - [IBM/ILOG CP Optimizer](http://www-01.ibm.com/software/integration/optimization/cplex-cp-optimizer/) (ilogcp) - [Gecode](http://www.gecode.org/)
AMPL Solver Library ------------------- AMPL Solver Library (ASL) is an open source library for connecting solvers to AMPL. * Available from: - Netlib: [http://www.netlib.org/ampl/](http://www.netlib.org/ampl/) - GitHub: [https://github.com/vitaut/ampl](https://github.com/vitaut/ampl) * Includes drivers for several solvers: - CPLEX - Gurobi - MINOS
...
AMPL Solver Interfaces ---------------------- * C interface: - described in [Hooking Your Solver to AMPL](http://www.ampl.com/hooking.html) - 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](https://github.com/vitaut/ampl/tree/master/solvers/ilogcp) and [gecode](https://github.com/vitaut/ampl/tree/master/solvers/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: [https://github.com/vitaut/ampl](https://github.com/vitaut/ampl) * C++ Solver API: solvers/util * Gecode AMPL solver: solvers/gecode * IlogCP AMPL solver: solvers/ilogcp