Originally posted by: geffer
I am a new learner in addusercut and coding a very simple to experiment, but feedback is “ Not a mixed-integer problem” what's the problem?
my coding is very easy
#include <ilcplex/ilocplex.h>
ILOSTLBEGIN
void makeCuts(IloRangeArray cuts, const IloNumVarArray& vars) {
IloNumVar x21,x22,x23;
IloInt num = vars.getSize();
x21 = vars[0];
x22 = vars[1];
x23 = vars[2];
cuts.add(x21<=20);
cuts.add(x22<=20);
cuts.add(x23<=20);
}
int
main(int argc, char** argv)
{
IloEnv env;
try {
IloModel m(env);
IloCplex cplex(env);
IloObjective obj;
IloNumVarArray vars(env);
IloRangeArray rngs(env);
vars.add(IloNumVar(env, 0.0, 40.0));
vars.add(IloNumVar(env));
vars.add(IloNumVar(env));
m.add(IloMaximize(env, vars[0] + 2 * vars[1] + 3 * vars[2]));
m.add( - vars[0] + vars[1] + vars[2] <= 20);
m.add( vars[0] - 3 * vars[1] + vars[2] <= 30);
cplex.extract(m);
IloRangeArray cuts(env);
makeCuts(cuts, vars);
cplex.addUsercuts(cuts);
cuts.endElements();
cuts.end();
cplex.setParam(IloCplex::MIPInterval, 1000);
env.out() << "solving model ...\n";
cplex.solve();
env.out() << "solution status is " << cplex.getStatus() << endl;
env.out() << "solution value is " << cplex.getObjValue() << endl;
IloNumArray vals(env);
cplex.getValues(vals, vars);
env.out() << "Values = " << vals << endl;
}
catch (IloException& ex) {
cerr << "Error: " << ex << endl;
}
env.end();
return 0;
}
#CPLEXOptimizers#DecisionOptimization