Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Callback to access LP solution procedure after every simplex iteration

  • 1.  Callback to access LP solution procedure after every simplex iteration

    Posted 09/15/16 11:37 AM

    Originally posted by: JimDan


    Dear all,

     

    I am solving an LP via C callable library. I am trying to access information pertaining to the primal simplex after each simplex iteration.

    First, I have a routine that sets as the starting basis all artificial variables with high cost. Each such variable has a single +1 entry in the constraint matrix corresponding to each constraint. Artificial variables are indexed original_var and above. ncol is the total number of variables including artificial variables.


        

     void setoriginalbasis(){
       for (int i = 0; i < ncol; i++) {
            if (i < original_var)
                    cb.cstat[i] = CPX_AT_LOWER;
            else
                    cb.cstat[i] = CPX_BASIC;
        }
        for (int i = 0; i < nrow; i++)
            cb.rstat[i] = CPX_BASIC;
        int retval = CPXcopybase(env, lp, cb.cstat, cb.rstat);
    }
    
    
    Then, I have
    

    CPXsetlpcallbackfunc(env, callback, NULL);

     

    Then, I have a user defined call back function as below:

    static int CPXPUBLIC callback(CPXCENVptr env, void *cbdata, int wherefrom, void *cbhandle) {
            std::cout << "Into Callback" << std::endl;
            CPXLPptr lp;
            CPXgetcallbackinfo(env, cbdata, wherefrom, CPX_CALLBACK_INFO_USER_PROBLEM, &lp);
            int ncol = CPXgetnumcols(env, lp);
            int newcstat[MAXCOL];
            int retval = CPXgetbase(env, lp, newcstat, NULL);//However, when I access newcstat here, 
                                                           //there is no change iteration to iteration
    
                       CPXgetcallbackinfo(env, cbdata, wherefrom, CPX_CALLBACK_INFO_PRIMAL_OBJ, &objval);
    

                   //other stuff

    }

     

    When I examine newcstat the last line in callback is executed, it has the same stuff that I originally set in setoriginalbasis. This is even though objval (which stores the objective function value after each iteration keeps changing.

     

    Is there any different function I need to use to access which variables are currently basic?

     

    Thanks.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Callback to access LP solution procedure after every simplex iteration

    Posted 09/16/16 09:17 AM

    Originally posted by: RWunderling


    That is not supported.  The only function you can call within an lp callback is CPXgetclallbackinfo()

    http://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.3/ilog.odms.cplex.help/refcallablelibrary/cpxapi/getcallbackinfo.html

     

    The reason is that other functions expect all data internal structures to be setup for a final solution, which is not done during the course of the algorithm for performance reason.

     

    Roland


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Callback to access LP solution procedure after every simplex iteration

    Posted 09/16/16 12:37 PM

    Originally posted by: JimDan


    Roland,

     

    Thanks.

    I have the following work around for now.

     

    CPXsetintparam(env, CPX_PARAM_ITLIM, 1);
    status = CPXsetlpcallbackfunc(env, callback, NULL);
    while (true) {
            CPXPrimopt(env, lp)
            if (CPXgetstat(env, lp) != 10) {
                break;
            }
    }
    

     

    This is sufficing for my purposes for now.


    #CPLEXOptimizers
    #DecisionOptimization