An open source algebraic modelling language implemented as a C++ class library.

FLOPC++ is an open source C++ class library for algebraic modelling of linear optimization problems (LP/MIP). Using FLOPC++, linear optimization models can be specified in a declarative style, similar to algebraic modelling languages such as GAMS and AMPL, within a C++ program. As a result the traditional strengths of algebraic modelling languages are preserved, while embedding linear optimization models in software applications is facilitated.

FLOPC++ is published under the Common Public License version 1.0 . The source code can be downloaded as a gzipped tar ball here:

DOWNLOAD==> flopc_Wed_Aug_13_21-26-22_CEST_2003.tgz <==DOWNLOAD

To achieve solver independence, FLOPC++ uses the COIN Open Solver Interface (OSI) (a uniform API for calling math programming solvers), and may be linked to any solver with an OSI interface (currently CLP, CPLEX, dylp, GLPK, OSL, SOPLEX, VOL and XPRESS-MP).

FLOPC++ can be used as a substitute for traditional modelling languages, when modelling linear optimization problems, but its principal strength lies in the fact that the modelling facilities are combined with a powerful general purpose programming language. This combination is essential for implementing efficient algorithms (using linear optimization for subproblems), integrating optimization models in user applications, etc.

Read more about the benefits of integrating modelling facilities within C++ in "A presentation of FLOPC++".


Mini Tutorial


Some prior knowledge of algebraic modelling languages is assumed. (A fast way to get that, is to read "A Quick Tour of GAMS".)

Let´s have a look at a simple FLOPC++ model to see what it is all about:

#include "flopc.hpp"
using namespace flopc;

main() {
    enum  {seattle, sandiego, numS}; 
    enum  {newyork, chicago, topeka,numD};

    MP_set S(numS);          // Sources 
    MP_set D(numD);          // Destinations 
    MP_subset<2> Link(S,D);  // Transportation links (sparse subset of S*D)

    Link.insert(seattle,newyork);
    Link.insert(seattle,chicago);
    Link.insert(sandiego,chicago);
    Link.insert(sandiego,topeka);

    MP_data SUPPLY(S);
    MP_data DEMAND(D);

    SUPPLY(seattle)=350;  SUPPLY(sandiego)=600;
    DEMAND(newyork)=325;  DEMAND(chicago)=300;  DEMAND(topeka)=275;
    
    MP_data COST(Link);

    COST(Link(seattle,newyork)) = 2.5;  
    COST(Link(seattle,chicago)) = 1.7;  
    COST(Link(sandiego,chicago))= 1.8;  
    COST(Link(sandiego,topeka)) = 1.4;

    COST(Link) = 90 * COST(Link) / 1000.0;
    
    MP_variable x(Link);

    MP_constraint supply(S);
    MP_constraint demand(D);  

    supply(S) =  sum( Link(S,D), x(Link) ) <= SUPPLY(S);
    demand(D) =  sum( Link(S,D), x(Link) ) >= DEMAND(D);
    
    minimize( sum(Link, COST(Link)*x(Link)) );
    
    x.display("Optimal solution:");
}

It is possible to define several independent models (MP_model), but to simplify the formulation of small models a default model (MP_model::default_model) can be used implicitly, as in the example above.

Consider the formulation of the two constraints:

    supply(S) =  sum( Link(S,D), x(Link) ) <= SUPPLY(S);
    demand(D) =  sum( Link(S,D), x(Link) ) >= DEMAND(D);
In the first summation over the "sparse" set Link(S,D) the dummy index S is bound by the constraint being defined, whereas in the similar summation in the second constraint the other dummy index D is bound. This handy notation for "slices" of sparse compound sets is similar to AMPL.

Note that sets can be used as dummy indices, just like in GAMS. Alternatively explicit dummy indices can be used, if preferred:

    MP_constraint supply(S);
    MP_constraint demand(D);  

    MP_index i,j;

    supply(i) =  sum( Link(i,j), x(Link) ) <= SUPPLY(i);
    demand(j) =  sum( Link(i,j), x(Link) ) >= DEMAND(j);

While this tutorial is still incomplete, you are invited to study the example models below to learn how to use FLOPC++


Examples


Most of the examples are FLOPC++ formulations of GAMS models found in the GAMS model library.

Currently the following example FLOPC++ models are available:

In these examples the IBM OSL solver (free for academic use) has been used for the MIP problems. Therefore you need to have the IBM OSL (and its OSI interface) installed to be able to compile the examples without change. Otherwise you can simply select another solver, say CPLEX, like this:

    
    MP_model::default_model.setSolver(new OsiCpxSolverInterface);
    

Feedback


Any kind of feedback (bug reports, comments, suggestions, contribution of example models etc.) is very welcome. Just send me an email at thh@mat.ua.pt


[Mini Tutorial] [Examples] [Download] [Feedback] [Top]