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
------------------------------
Original Message:
Sent: Mon April 17, 2023 11:29 AM
From: Paul Rubin
Subject: Copying cplex model
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
------------------------------