gpt4 book ai didi

c++ - Cplex Concert 技术 double

转载 作者:行者123 更新时间:2023-11-28 05:08:32 24 4
gpt4 key购买 nike

我试图获得约束的对偶

这是用 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 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]);
}
}

当通过不同的 cplex 方法(如 Barrier、Primal、Dual、Network)解决此 LP 问题时,我最终得到了完全不同的 Dual 值和不同的解决方案。为什么会这样?是因为我的问题有平等约束吗?我如何确定真正的值(value)正在通过 cplex?

非常感谢任何帮助。

最佳答案

您可能有多个最优对偶解决方案:所有可行且目标值与最优目标值相同的解决方案。这可能在有或没有同等约束的情况下发生,即使存在唯一的最优原始解决方案也是如此。

关于c++ - Cplex Concert 技术 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44036440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com