[Osi] OSI and GLPK

Renato Bruni bruni at diei.unipg.it
Tue Sep 8 12:07:46 EDT 2009


Hello everybody,

I need to migrate from Cplex (used by means of Concert Technology)
to an open source solver. I'm therefore looking at the OSI project,
and I would like to use it initially with GLPK solver.

I downloaded the source code for version 0.100.0 and tried to compile it,
I examined the documentation but many things are still not clear to me.
I would need something like a small user manual (not the list of all
classes) or an example of creating a small ILP model from a C++ code
(not read from file).

If possible, the model should be created dynamically, in some way similar to
Cplex Concert Technology. This means that I create something like the
container of the ILP model, then I create variables, objective function and
constraints, not all in one time but one after another, step by step from
different points of my C++ code, without the need of knowing from the
beginning how many constraints the model will have and how many variables
each constraint will have.

Something like:
create ILPmodel(M);        \\ create an ILP model called M
M.addvariables(x[10]);     \\ put in M a vector x of 10 integer variables
expr1 = ( x1 + 3 x4 );       \\ create an expression containing x1+3x4
expr1 += (x2 + x5 + x6);  \\ add x2+x5+x6 to the expression, that is now
                                        \\ x1+x2+3x4+x5+x6
M.addobj_min(expr1);     \\ create in M the minimization obj function
                                        \\ min (x1+x2+3x4+x5+x6)
expr2 = (2 x2 - 3 x4);       \\ create another expression containing 2x2-3x4
expr2 += (x1-x8 >= 10);  \\ the expression is now x1+2x2-3x4-x8>=10
M.addconstraint(expr2);   \\ create in M constraint x1+2x2-3x4-x8>=10
...........                             \\ add other constraints
M.solve(GLPK);              \\ solve the model using GLPK
M.getsolution();                \\ reads the solution

Thanks a lot for your help.
Best regards,
Renato Bruni
----------------------------------------
Renato Bruni, Ph.D.
Dep. of Computer and System Sciences
University of Roma "Sapienza"




More information about the Osi mailing list