Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Insert a heuristic solution within the callback function

    Posted 10/06/20 08:24 PM
    Hi,

    I will be referring BendersATSP2 for my question.

    Suppose I use generic callback where I only use separation at integer solutions. So my context mask only contains the following without IloCplex.Callback.Context.Id.Relaxation:

    long contextmask = IloCplex.Callback.Context.Id.Candidate | IloCplex.Callback.Context.Id.ThreadUp | IloCplex.Callback.Context.Id.ThreadDown; ​
    Then, when I enter into BendersATSPCallback method and call "separate" method with

    IloRange violated = worker.separate(x, xSol).​

    Once I get into "separate" method, I would like to insert a heuristic solution to update the current incumbent upper bound based on a certain criteria. I was wondering how I can accomplish it inside "separate" method.

    ------------------------------
    Ser Giovio
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Insert a heuristic solution within the callback function

    Posted 10/07/20 04:14 AM
    Edited by System Admin 01/20/23 04:45 PM
    Here are a number of things you may want to know:
    - General documentation about what can be done with a Generic callback is at https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/progr_adv/callbacks/whatToDoCallbacks.html.
    - ThreadUp and ThreadDown are not meant to be used a contexts to actually influence CPLEX behavior, but to setup the datastructures that you may need in your callback because it will be called in a multi-threading setup. Please refer to https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/progr_adv/callbacks/contextCallbacks.html.
    - That page specifically mentions that injecting solutions is not supported in these two contexts. So you should probably make sure that separate is not called with these contexts.
    - Example iloadmipex9, available in your CPLEX installation, uses the method postHeuristicSolution (https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refcppcplex/html/classes/Callback_Context.html#method_postHeuristicSolution) and will probably be interesting for you to look at.

    ------------------------------
    Xavier
    ------------------------------



  • 3.  RE: Insert a heuristic solution within the callback function

    Posted 10/07/20 01:10 PM
    Edited by System Admin 01/20/23 04:23 PM
    Hi Xavier,

    Thanks for the reply.

    1) Except the last link you sent, the rest of the links seem broken. I am receiving the following error even if I change the browser that I use.

    ```

    The requested page does not exist or might have moved.


    If you accessed this page by using a bookmark or external URL, the bookmark or links might need to be updated. In this case, use the Table of Contents or the Search bar to find the content.


    If you accessed this page from the Table of Contents or Search Bar, please report the broken link to IBM Knowledge Center Support who will alert the appropriate content group.
    ```


    2) Yes, I am aware of that ThreadUp and ThreadDown have nothing to do with the solutions. . Since I was referring the example of BendersATSP2, I just wanted to stick to the original code sample to make more question clearer. 


    3) I guess the example that you mention corresponds to AdMIPex9 in Java folder. So looking at the example, all I need to do is somehow arranging my code to be able to use context.postHeuristicSolution inside the invoke method.  I can just attach IloCplex.Callback.Context.Id.Candidate as an incumbent solution to my contextmask. Then, I can go ahead and generate a Benders cut and use context.postHeuristicSolution after it. Is my understanding correct? If so, could you please give me a small example how I can insert solutions for two sets of variables. For the sake of simplicity let's call them X[] and Y[]. If I produce a set of solutions as x and y, how can I use these solutions ascontext.postHeuristicSolution(_vars, x, 0, cols, objrel, IloCplex.Callback.Context.SolutionStrategy.CheckFeasible);



    ------------------------------
    Ser Giovio
    ------------------------------



  • 4.  RE: Insert a heuristic solution within the callback function

    Posted 10/07/20 05:41 PM
    I'm unable to parse the sentence "I can just attach IloCplex.Callback.Context.Id.Candidate as an incumbent solution to my contextmask. " You can invoke postHeuristicSolution() on the context object while in the candidate context, if that is what you are asking. As far as having two vectors of variables, you just need to concatenate those vectors into a single variable vector, and concatenate the proposed values into a single value vector, setting the starting index (presumably 0) and length (length of the combined vector) accordingly.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 5.  RE: Insert a heuristic solution within the callback function

    Posted 10/07/20 10:21 PM
    "You can invoke postHeuristicSolution() on the context object while in the candidate context, if that is what you are asking. " Yes, that what I was trying to say. So I do not need to change anything in the main method. If I only care about the incumbent solution, I can use IloCplex.Callback.Context.Id.Candidate
    and when I am in the invoke method, I can just use postHeuristicSolution().

    "As far as having two vectors of variables, you just need to concatenate those vectors into a single variable vector, and concatenate the proposed values into a single value vector, setting the starting index (presumably 0) and length (length of the combined vector) accordingly."  If I parse both X and Y into a single array Z, how does CPLEX would know which values of for X and which values are for Y? As an example, say I will pass a solution as X=[0,1,2] Y =[2,6,7]. Now, If I create a vector Z = [0,1,2,2,6,7] and put into postHeuristicSolution(),how does CPLEX know that 0,1,2 are for variable X and 2,6,7 are for variable Y?


    ------------------------------
    Ser Giovio
    ------------------------------



  • 6.  RE: Insert a heuristic solution within the callback function
    Best Answer

    Posted 10/07/20 11:08 PM
    It matches the vector of variables and the vector of values position by position. So (using the Java API) you do something like the following:

    IloNumVar[] x = ...;
    IloNumVar[] y = ...;
    IloNumVar[] vars = new IloNumVar[6];
    for (int i = 0; i < 3; i++) {
      vars[i] = x[i];
      vars[i + 3] = y[i];
    }
    double[] vals = new double[] {0, 1, 2, 2, 6, 7};

    and then pass vars and vals in as the first two arguments of postHeuristicSolution().

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------