#include <ilcplex/ilocplex.h>
ILOSTLBEGIN
int main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloNumVarArray vars(env);
vars.add(IloNumVar(env));
vars.add(IloNumVar(env));
vars.add(IloNumVar(env));
vars.add(IloNumVar(env));
vars.add(IloNumVar(env,0.0,4000.0));
model.add(IloMaximize(env, 7*vars[0] + 14*vars[1] + 6*vars[2] + 10*vars[3] - 3*vars[4])); //목적식
model.add(vars[0] + vars[1] -3*vars[4] = 0);
model.add(vars[2] + vars[3] -4*vars[4] = 0);
model.add(3*vars[1] + 2*vars[3] + vars[4] <= 6000);
IloCplex cplex(model);
if ( !cplex.solve() ) {
env.error() << "Failed to optimize LP." << endl;
throw(-1);
}
IloNumArray vals(env);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
cplex.getValues(vals, vars);
env.out() << "Values = " << vals << endl;
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
}
다음의 코드를 실행하면,
trying to add an empty handle extractable
이라는 예외가 출력됩니다.
포뮬레이션은 분명 맞구요...
어느 부분이 잘못된 걸까요?