Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  benders c++ API code

    Posted 05/25/16 11:29 PM

    Originally posted by: Selectedbetter


    At first, we learned how to write benders code from the atsp.cpp.

    But, for our question, we not only need to getRay() but also to getValues() in the worker problem. So, the atsp.cpp can't help more.

    Then, we try to write the optimal part for worker problem, but the result is wrong.

    PS: When we don't add the optimal part and only use the unbounded,  the result is logical but not optimal for the whole problem.

    if ( cplex.getStatus() == IloAlgorithm::Unbounded )
    {
            IloNumVarArray var(env);
            IloNumArray val(env);

            cplex.getRay(val,var); 

           .........

    }

    else if(cplex.getStatus() == IloAlgorithm::Optimal)
    {
           IloNumArray R(env,RNumVars);
           cplex.getValues(R,r);//  r is the dual variable

           .........

    }

    What' more, the computing time is too long for our problem. About 5 minutes in the cplex and 1 hour in the C++API for the same example.(We calculate our problem in two ways, that is directly calculating in cplex and benders in C++API)

     

    And now, we don't know how to do and which part to correct.

    Is there any other benders C++ code that can give us? We can compare it with our code.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: benders c++ API code

    Posted 05/26/16 04:43 AM

    Originally posted by: Selectedbetter


    if our problem is:

     initial master 

    min c x + eta
    A x >= b
    x >= 0, integer

    Dual subproblem

    max u (q - T x*)+v (q - T x*)
    u Q <= d

    v  Q <= d
    u >= 0
    v >= 0

    Then, in our code, we write:

     IloInt separate(.......)

    {

        ........

     

        cplex.solve();

     

    if ( cplex.getStatus() == IloAlgorithm::Unbounded )
    {
            IloNumVarArray var(env);
            IloNumArray val(env);

            cplex.getRay(val,var);      

            for (w = 0; w < val.getSize(); ++w) 
            {
                IloInt *index_p = (IloInt*) var[w].getObject();
                IloInt index = *index_p;

                if (index<uNumVars)
                {
                    cutLhs+=val[w]*(q - T x);
                }

                else if(index>=uNumVars && index<(uNumVars+vNumVars))
                {
                   cutLhs+=val[w]*(q - T x);
                }

            var.end();
            val.end();
            violatedCutFound = 1;

     

    }

    else if(cplex.getStatus() == IloAlgorithm::Optimal)
    {
           IloNumArray U(env,uNumVars);

           IloNumArray V(env,vNumVars);
           cplex.getValues(U,u);

           cplex.getValues(V,v);

           cutLhs+=U*(q - T x);

           cutLhs+=V*(q - T x);

           violatedCutFound = 2;

    }

    return violatedCutFound ;

    }

    And by the value of violatedCutFound:

     

    ILOLAZYCONSTRAINTCALLBACK(......)

    {

      

        IloInt sepStat = separate(......); 

        if (sepStat = 1)
        {
            add(cutLhs <=0).end();
        }
        else if(sepStat = 2)
        {
            add(cutLhs <= eta).end();
        }

    }

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization