It derives from ilomipex1.cpp
. The differences between that simpler MIP example and this one are:
setPriorities()
sets the SOS and priority order:
#include <ilcplex/ilocplex.h> ILOSTLBEGIN static void populatebyrow(IloModel model, IloNumVarArray var, IloRangeArray con); int main (void) { IloEnv env; try { IloModel model(env); IloNumVarArray var(env); IloRangeArray con(env); populatebyrow (model, var, con); IloCplex cplex(model); IloNumVarArray ordvar(env, 2, var[1], var[3]); IloNumArray ordpri(env, 2, 8.0, 7.0); cplex.setPriorities (ordvar, ordpri); cplex.setDirection(var[1], IloCplex::BranchUp); cplex.setDirection(var[3], IloCplex::BranchDown); cplex.solve(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Solution value = " << cplex.getObjValue() << endl; IloNumArray vals(env); cplex.getValues(vals, var); env.out() << "Values = " << vals << endl; cplex.getSlacks(vals, con); env.out() << "Slacks = " << vals << endl; cplex.exportModel("mipex3.lp"); } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main static void populatebyrow (IloModel model, IloNumVarArray x, IloRangeArray c) { IloEnv env = model.getEnv(); x.add(IloNumVar(env, 0.0, 40.0)); x.add(IloNumVar(env, 0.0, IloInfinity, ILOINT)); x.add(IloNumVar(env, 0.0, IloInfinity, ILOINT)); x.add(IloNumVar(env, 2.0, 3.0, ILOINT)); model.add(IloMaximize(env, x[0] + 2 * x[1] + 3 * x[2] + x[3])); c.add( - x[0] + x[1] + x[2] + 10 * x[3] <= 20); c.add( x[0] - 3 * x[1] + x[2] <= 30); c.add( x[1] - 3.5* x[3] == 0); model.add(c); model.add(IloSOS1(model.getEnv(), IloNumVarArray(model.getEnv(), 2, x[2], x[3]), IloNumArray(env, 2, 25.0, 18.0) )); } // END populatebyrow |