populatebyrow
method, and thus no command line arguments are needed to select a construction method.
main
routine, the arrays cstat
and rstat
set the status of the initial basis.
cplex.getStatuses
()
.
The main program starts by declaring the environment and terminates by calling method end()
for the environment. The code in between is encapsulated in a try block that catches all Concert Technology exceptions and prints them to the C++ error stream cerr
. All other exceptions are caught as well, and a simple error message is issued. Next the model object and the cplex
object are constructed. The function populatebycolumn()
builds the problem object and, as we noted earlier, cplex.getStatuses()
copies the advanced starting basis.
The complete program, ilolpex6.cpp
, appears here or online in the standard distribution
#include <ilcplex/ilocplex.h> ILOSTLBEGIN static void populatebycolumn (IloModel model, IloNumVarArray var, IloRangeArray rng); int main (int argc, char **argv) { IloEnv env; try { IloModel model(env, "example"); IloNumVarArray var(env); IloRangeArray rng(env); populatebycolumn (model, var, rng); IloCplex cplex(model); IloCplex::BasisStatusArray cstat(env), rstat(env); cstat.add(IloCplex::AtUpper); cstat.add(IloCplex::Basic); cstat.add(IloCplex::Basic); rstat.add(IloCplex::AtLower); rstat.add(IloCplex::AtLower); cplex.setStatuses(cstat, var, rstat, rng); cplex.solve(); cplex.out() << "Solution status = " << cplex.getStatus() << endl; cplex.out() << "Solution value = " << cplex.getObjValue() << endl; cplex.out() << "Iteration count = " << cplex.getNiterations() << endl; IloNumArray vals(env); cplex.getValues(vals, var); env.out() << "Values = " << vals << endl; cplex.getSlacks(vals, rng); env.out() << "Slacks = " << vals << endl; cplex.getDuals(vals, rng); env.out() << "Duals = " << vals << endl; cplex.getReducedCosts(vals, var); env.out() << "Reduced Costs = " << vals << endl; cplex.exportModel("lpex6.lp"); } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main static void populatebycolumn (IloModel model, IloNumVarArray x, IloRangeArray c) { IloEnv env = model.getEnv(); IloObjective obj = IloMaximize(env); c.add(IloRange(env, -IloInfinity, 20.0)); c.add(IloRange(env, -IloInfinity, 30.0)); x.add(IloNumVar(obj(1.0) + c[0](-1.0) + c[1]( 1.0), 35.0, 40.0)); x.add(obj(2.0) + c[0]( 1.0) + c[1](-3.0)); x.add(obj(3.0) + c[0]( 1.0) + c[1]( 1.0)); model.add(obj); model.add(c); } // END populatebycolumn |