0

I tried to get the duals of constraints

This is the code, implemented in 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]);
        }
    }

when solving this LP problem by different methods of cplex like Barrier, Primal, Dual, Network I got completely different Dual values and different solutions at the end. why this is like this? Is it because I have equality constraints in my problem? how can I be sure that true values are passing through cplex?

any help is really appreciated.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
math2014
  • 55
  • 7
  • 1
    This looks like a column generation master coming from some sort of vehicle routing applications. These masters are highly degenerate, so David's answer below is spot on. I would suggest that you use Simplex, because as you add new columns you will not need to reoptimize from scratch (which is true for barrier). For such models, I had some good results trying the [sifting](https://www.ibm.com/support/knowledgecenter/SS9UKU_12.6.1/com.ibm.cplex.zos.help/CPLEX/UsrMan/topics/cont_optim/simplex/10_sifting.html) optimizer in the past. – Ioannis May 19 '17 at 13:01
  • @ Ioannis : Thanks for helpfull comment, what do you mean by using simplex?! – math2014 May 21 '17 at 11:04
  • Simplex is the default algorithm for Linear Programming that CPLEX uses. There are variants such as dual Simplex, primal Simplex and network Simplex, which hinge on the same principle but take advantage of the primal, dual or network structure respectively. [CPLEX uses by default the dual Simplex method](http://www-01.ibm.com/support/docview.wss?uid=swg21399934) but that can be changed. – Ioannis May 22 '17 at 08:16

1 Answers1

1

You likely have multiple optimal dual solutions: solutions that are all feasible and have the same objective value equal to the optimal objective value. This can happen with or without equally constraints, and even if there is a unique optimal primal solution.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
  • Thanks, yes it can be true, but another problem that I have is that some times some routes with zero value in the model ,their reduced cost is positive when calculating! – math2014 May 21 '17 at 12:24