Originally posted by: savant_ning
I have a error, I don't know why it doesn't work in my model
my code shown as below:
double BLDPC::ComputeLB(int *pVec)
{
IloEnv env;
int ii, jj;
struct edge *pt;
double lowerBound =0;
GetSubMatrixRows(pVec);
GetColsInSubMatrix(pVec);
if (size_submatrixRows == 0)
return 0;
try
{
IloModel model(env);
IloNumVarArray xVar(env);
// set lower and upper bounds on the variables
for (ii = 0; ii < size_colsInSubMatrix; ii++) {
xVar.add(IloNumVar(env, 0.0, IloInfinity));
}
// create the objective function
IloExpr fobj(env);
for (ii = 0; ii < size_colsInSubMatrix; ii++) {
fobj += xVar[ii];
}
// set the model to optimize
model.add(IloMinimize(env, fobj));
// generate the inequality constraints
for (ii = 0; ii < size_submatrixRows; ii++) { // each active row produces an inequality constraint
IloExpr fcon(env);
for (jj = 0; jj < size_colsInSubMatrix; jj++) { // go through the columns involved in I(F)
pt = twcl->rowheader[subMatrixRows[ii]].right;
while (pt->col != -1) {
if (pt->col == colsInSubMatrix[jj]) {
fcon += xVar[jj];
break;
}
pt = pt->right;
}
}
model.add(fcon >= 1); // add the generated constraint into the model
fcon.end(); // reset the constraint expression
}
IloCplex cplex(model);
cplex.setOut(env.getNullStream());
cplex.setParam(IloCplex::WorkMem,2048.0);
//cplex.setParam(IloCplex::IntParam::NodeFileInd,3 );
//cplex.setParam(IloCplex::NodeSel, 3.0);
//cplex.setParam(IloCplex::VarSel, 3.0);
if (!cplex.solve()) { // call cplex.solve() to solve the model; when return IloTrue, a feasible solution is found. Otherwise, when return IloFalse, no solution is found
//printf("Failed to optimize LP.\n");
return (colNum + 1.0);
}
lowerBound = cplex.getObjValue();
// save the values of xVar's
for (ii = 0; ii < size_colsInSubMatrix; ii++) {
xVars[colsInSubMatrix[ii]] = cplex.getValue(xVar[ii]);
}
fobj.end();
}
catch (IloException&e) {
std::cerr << "Concert exception caught:" << e << std::endl;
}
catch (...) {
std::cerr << "Unknown exception caught" << std::endl;
}
env.end();
return lowerBound;
}
and I know my error is :
cplex.setParam(IloCplex::WorkMem,2048.0);
//cplex.setParam(IloCplex::IntParam::NodeFileInd,3 );
//cplex.setParam(IloCplex::NodeSel, 3.0);
//cplex.setParam(IloCplex::VarSel, 3.0);
I don't know why they doesn't work
#CPOptimizer#DecisionOptimization