Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Copying cplex model

    Posted 04/17/23 08:51 AM

    Hi I have a problem where i would like to branch on an IloRange splitting the range into two parts (one for each branch). To do this the makeBranch won't work (I think) as the original model will never get to the branchcallback from where it is possible to call makebranch. So what I'm thinking is to make two copies of the model, each representing one of the branches and solve it that way. However I'm not sure on how exactly to approach that. I found a link on how to copy a model but it doesn't seem to work as (IloLPMatrix)knapsack.LPMatrixIterator().next() returns null Clone an IloCplex object using the Java API .

    Is it feasible to simply recreate the model from start or is that extremely slow?

    Is there another way to copy the model?
    is there another way to call the branchcallback myself?



    ------------------------------
    Luuk van Nes
    ------------------------------



  • 2.  RE: Copying cplex model

    Posted 04/17/23 11:29 AM
    Edited by Paul Rubin 04/17/23 11:30 AM

    I assume that "knapsack" is the name of your IloCplex instance. First question: Did you build "knapsack" using IloLPMatrix or did you build it "rowwise" (defining variables, then adding constraints)? Second question: When LPMatrixIterator().next() returns null, have you first called LPMatrixIterator().hasNext() to confirm that there is another matrix to extract?




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



  • 3.  RE: Copying cplex model

    Posted 04/18/23 05:07 AM

    Okay so below i have a better example of what i want to achieve. Basically i want to select a starting time for two different items (each chosen from a list of possible starting times). These starting times should be equal for both items. To enforce this i want to branch on the range of starting times if the lp finds starting times that are unequal. The normal way of branching using cplex would not work here as far as i know as cplex won't call the branch callback is the solution found is feasible. So my idea is to copy the lp twice and change the ranges for each copy. I am currently using the modeling by columns technique. 

    (obviously for this example this is not an effective way of building the lp, this is just a simple example to show my issue)

    val example = IloCplex()
    val obje = example.addMaximize("value of items")

    val range1 = example.addRange(.0,100.0);
    val numberOfItem1 = example.addRange(.0,1.0);
    //list of item1 starting times to choose from
    val timesToStartTask1 = doubleArrayOf(10.0,20.0,30.0,70.0,85.0)
    val timeChosen1 = IloNumVarArray()

    val range2 = example.addRange(.0,100.0);
    val numberOfItem2 = example.addRange(.0,1.0);
    //list of item1 starting times to choose from
    val timesToStartTask2 = doubleArrayOf(10.0,20.0,30.0,70.0,85.0)
    val timeChosen2 = IloNumVarArray()

    for (i in 0 until timesToStartTask1.size){
    timeChosen1.add(example.boolVar(example.column(obje, 1.0)
    .and(example.column(numberOfItem1, 1.0))
    .and(example.column(range1, timesToStartTask1[i]))))
    timeChosen2.add(example.boolVar(example.column(obje, 1.0)
    .and(example.column(numberOfItem2, 1.0))
    .and(example.column(range1, timesToStartTask2[i]))))
    }

    example.solve()


    ------------------------------
    Luuk van Nes
    ------------------------------



  • 4.  RE: Copying cplex model

    Posted 04/18/23 03:22 PM

    This is quite confusing. If you want the start times for two items to be equal, why not use the same variable for both start times?

    Are you proposing to solve the original MIP model to optimality, and if the start times are different then create a copy of the model and so something with the copy? Alternatively, are you proposing to clone the model within a callback?



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