IBM CPLEX c++协调技术-不可行的解决方案



我正在使用ILP方法来解决我的一个研究问题。最初使用数学规划(.mod)制定了ILP,它工作得很好。但是,在使用concert技术编译公式化ILP的c++代码时,出现了"不可行"的错误。同样的例子。这里我使用了IBM CPLEX ILP求解器。

产生问题的代码部分列在下面。

**ILP.mod**
//declaration
dvar boolean o_st[range_op][range_cyc][range_dpu];   // 3D boolean decision variable
// Constraint
C1: forall (i in range_op)
{
sum(j in range_cyc, k in range_dpu) o_st[i][j][k] == 1;     
}
**ILP.cpp**
//declaration
Numbool3D o_st(env, n_op);             
for (int i = 0; i < n_op; i++)
{
o_st[i] = Numbool2D(env, n_cyc);
for (int j = 0; j < n_cyc; j++)
{
o_st[i][j] = IloBoolArray(env, n_dpu);
}        
}
// Constarint
IloExpr exp3(env)
for (int i = 0; i < n_op; i++)
{
for (int j = 0; j < n_cyc; j++)
{
for (int k = 0; k < n_dpu; k++)
{
exp3 += o_st[i][j][k];           
}               
}
Model.add(exp3 == 1);      
}

对于一个特定的例子,我在使用ILP时获得相同参数的输出。国防部文件。但是,在使用协调技术编译ILP.cpp文件时,求解器并没有提供解决方案。请在这方面帮助我。我遇到了一些问题,尤其是上面指定的约束。

既然你有一个在OPL中工作良好的模型,我鼓励你从c++调用这个OPL模型,你可以用OPL/c++ api

示例在CPLEX_Studio2211oplexamplesopl_interfacescpp

在mulproduct .cpp中,您将看到

int main(int argc,char* argv[]) {
IloEnv env;
int status = 127;
try {
IloOplErrorHandler handler(env,cout);
IloOplModelSource modelSource(env, DATADIR "mulprod" DIRSEP "mulprod.mod");
IloOplSettings settings(env,handler);
settings.setWithWarnings(IloFalse);
IloOplModelDefinition def(modelSource,settings);
IloCplex cplex(env);
IloOplModel opl(def,cplex);
IloOplDataSource dataSource(env, DATADIR "mulprod" DIRSEP "mulprod.dat");
opl.addDataSource(dataSource);
opl.generate();
if ( cplex.solve() ) {
cout << endl
<< "OBJECTIVE: " << fixed << setprecision(2) << opl.getCplex().getObjValue()
<< endl;
opl.postProcess();
opl.printSolution(cout);
status = 0;
} else {
cout << "No solution!" << endl;
status = 1;
}
} catch (IloOplException & e) {
cout << "### OPL exception: " << e.getMessage() << endl;
} catch( IloException & e ) {
cout << "### CONCERT exception: ";
e.print(cout);
status = 2;
} catch (...) {
cout << "### UNEXPECTED ERROR ..." << endl;
status = 3;
}
env.end();
cout << endl << "--Press <Enter> to exit--" << endl;
getchar();
return status;
}

相关内容

最新更新