C++ Cplex音乐会技术
我试图得到约束的对偶 这是用C++实现的代码:C++ Cplex音乐会技术,c++,mathematical-optimization,linear-programming,cplex,ilog,C++,Mathematical Optimization,Linear Programming,Cplex,Ilog,我试图得到约束的对偶 这是用C++实现的代码: IloEnv env; IloModel MasterProblem(env); IloNumVarArray XX(env,Create_routes.size(),0,IloInfinity,ILOFLOAT); IloNumVarArray t(env,m,0,IloInfinity,ILOFLOAT); IloExpr expr(env); ////defining ojective
IloEnv env;
IloModel MasterProblem(env);
IloNumVarArray XX(env,Create_routes.size(),0,IloInfinity,ILOFLOAT);
IloNumVarArray t(env,m,0,IloInfinity,ILOFLOAT);
IloExpr expr(env);
////defining ojective of problem
IloObjective masterObj(env,expr,IloObjective::Maximize);
expr.end();
MasterProblem.add(masterObj);
IloRangeArray const1(env); //hala yeki yeki mahdudiyatha ro misazim
for (int i=0; i<n; i++){
IloExpr expr(env);
for (int j=0; j<Create_routes.size(); j++){
if (Create_routes[j]->internalnodes[i+m]==1)
expr+=XX[j];
}
const1.add(1==expr);
MasterProblem.add(const1[i]);
expr.end();
}
IloRangeArray const2(env);
IloRangeArray const4(env);//mahdudiate depohaye open shode
for (i=0; i<m; i++){
IloExpr expr(env);
for (int j=0; j<Create_routes.size(); j++){
if (Create_routes[j]->depot==i){
expr+=XX[j]*Create_routes[j]->demand_collected;
}
}
expr-=t[i]*g[i]->QF;
const2.add(0>=expr);
MasterProblem.add(const2[i]);
expr.end();
}
IloRangeArray2 const3(env,m);
for (i=0; i<m; i++){
const3[i]=IloRangeArray(env);
}
for (int f=0; f<m; f++){
for (i=0; i<n; i++){
IloExpr expr(env);
for (int j=0; j<Create_routes.size(); j++){
if ((Create_routes[j]->depot==f)&&(Create_routes[j]->internalnodes[i+m]==1)){
expr+=XX[j];
}
}
expr-=t[f];
const3[f].add(0>=expr);
MasterProblem.add(const3[f][i]);
expr.end();
}
}
IloCplex cplexM(MasterProblem);
cplexM.setParam(IloCplex::RootAlg, IloCplex::Barrier);
cplexM.setParam(IloCplex::Threads, 4);
if ( !cplexM.solve() ){
env.error() << "Failed to optimize LP." << endl;
nodee->uperbound=0;
env.end();
return;
}
else{
if (!cplexM.isPrimalFeasible()){//agar infeasible bud bia birun
nodee->uperbound=0;
return;
}
cout<<"MasterProblem Solved"<<endl;
cout<<"objective="<<cplexM.getObjValue()<<endl;
javab=cplexM.getObjValue();
}
IloNumArray duall(env,n);
IloNumArray duall1(env,m);
cplexM.getDuals(duall,const1);
cplexM.getDuals(duall1,const2);
IloNumArray2 duall2(env,m);
for (i=0; i<m; i++){
duall2[i]=IloNumArray(env,n);
for (j=0;j<n;j++){
duall2[i][j]=cplexM.getDual(const3[i][j]);
}
}
IloEnv-env;
模型主问题(env);
IloNumVarArray XX(env,Create_routes.size(),0,IloInfinity,ILOFLOAT);
IloNumVarArray t(env,m,0,iloninfinity,ILOFLOAT);
IloExpr(env);
////定义问题的目标
IloObjective masterObj(环境、表达式、IloObjective::最大化);
expr.end();
MasterProblem.add(masterObj);
阵列常数1(env)//是的,是的,是的
对于(int i=0;iQF;
const2.add(0>=expr);
主问题。添加(常数2[i]);
expr.end();
}
IloRangeArray2 const3(环境,m);
对于(i=0;i您可能有多个最优对偶解:所有解都是可行的,并且具有与最优目标值相等的相同目标值。这可以在有或没有相同约束的情况下发生,即使存在唯一的最优原始解。这看起来像是来自某种车辆的列生成主控程序le路由应用程序。这些主程序是高度退化的,因此David下面的答案是正确的。我建议您使用Simplex,因为当您添加新列时,您不需要从头开始重新优化(对于barrier来说,这是正确的)。对于这样的模型,我过去尝试过优化器,获得了一些很好的结果。@Ioannis:感谢您的帮助性评论,您使用单纯形是什么意思?!单纯形是CPLEX使用的线性规划的默认算法。有一些变体,如对偶单纯形、原始单纯形和网络单纯形,它们依赖于相同的原理,但采用adv原始、双重或网络结构各自的优点。但这是可以改变的。谢谢,是的,这可能是真的,但我遇到的另一个问题是,有时模型中的某些路线为零值,在计算时,它们的降低成本为正!