i have simple binary liinear programming funcjon and i want to get more than one, for example 10 best solutions from Optimisation.Result = model.minimise(). Is this posible with OjAlgo?
I knew that purpose of function is to find one, best solution but is there any chance to generate more solutions or get solutions from solver iterations?
fun linearProgrammingSolver(meal: Meal): MutableList<String> {
val mealList = meal.results
val resultList = mutableListOf<String>()
val listOfVariables= makeVariables(meal) as ImmutableList<Variable>
val model = ExpressionsBasedModel()
listOfVariables.forEach{
model.addVariable(it)
}
val calories = model.addExpression("calories")
.lower(1500)
.upper(3000)
listOfVariables.forEach {
val index = listOfVariables.indexOf(it)
calories.set(listOfVariables[index], mealList[index].nutrition.nutrients[0].amount)
}
val protein = model.addExpression("protein")
.lower(60)
listOfVariables.forEach {
val index = listOfVariables.indexOf(it)
protein.set(listOfVariables[index], mealList[index].nutrition.nutrients[1].amount)
}
val meals = model.addExpression("meals")
.level(3)
listOfVariables.forEach {
val index = listOfVariables.indexOf(it)
meals.set(listOfVariables[index], 1)
}
val result: Optimisation.Result = model.minimise()
println("state ${result.state}")
model.variables.forEach{
if(it.value.toInt() == 1){
println("model.var ${it}")
resultList.add(it.name)
}
}
println(model)
println(result)
println("list $resultList")
return resultList
}
There are two ways to interpret this question.
Get the best solution and the 9 next best solutions. This can be accomplished by looking at the optimal solution
x*(i)and, settinga(i):=x*(i)and introducing an extra constraint to the model that forbidsx*to be found again, and then resolve. Repeat this. The cut you need to add in each cycle can look like:Collect solutions the algorithm finds and report the best 10 of them. That should not be too difficult to add to the algorithm (just keep track of the best 10). This would require changing the source code of the algorithm.
An alternative is using a more advanced (but likely much more expensive) solver that has a so-called solution pool.