-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary Variable returning value 0.502.... #14
Comments
Hello, I think there are some things missing from the code above. For example what is the symbol Mz? Do you mean M? In the expression var w = Array.tabulate(numI)(_0.1) there is an operator missing between the placemarker _ and 0.1. There are other similar cases. Please check the code again and send me a revised version. Thank you |
Oh I'm sorry it got lost in Markdown styling. Here is the correct version: implicit val problem = LQProblem(SolverLib.ojalgo) // Data (filled randomly) //Variables // Optimal Function // Constraints |
Hello, The problem is that you define an LQProblem instead of an MIProblem. LQProblem objects are intended for linear programming and use continuous variables, while MIProblem objects represent mixed-integer programming problems and can handle both continuous and integer variables. Nevertheless, maybe these two objects should be merged in order to make the API simpler, or some warning should notify the user for defining float variables in an LQProblem enviroment. I will try to fix this, but for now please just change the first line of your code into: implicit val problem = MIProblem(SolverLib.ojalgo) this should work. :) |
Thanks a lot. :) |
implicit val problem = LQProblem(SolverLib.ojalgo)
// Data (filled randomly)
val numI = 5
val I = 0 until numI
val numJ = 5
val J = 0 until numJ
var q = Array.tabulate(numI)(x=>(x+1)0.2)
var w = Array.tabulate(numI)(_0.1)
var to = Array.tabulate(numI,numJ)((x,y)=>x+y)
var r = Array.tabulate(numI,numJ)((x,y)=>0.1x+0.2y)
var c = Array.tabulate(numI,numJ)((x,y)=>x+2*y)
var B = 50
var T = Array.tabulate(numJ)(x => (x+2)*3)
var M = 1000
//Variables
val x = Array.tabulate(numI,numJ)((i,j) => MPIntVar(s"x($i,$j)", 0 to 1))
val y = Array.tabulate(numI)(i=>MPFloatVar(s"y$i"))
val z = Array.tabulate(numI)(i=>MPIntVar(s"z$i", 0 to 1))
// Optimal Function
maximize(sum(I,J){ (i,j) => w(i)*y(i) })
// Constraints
for ( j <- J ) {
add(sum(I)(i => to(i)(j)x(i)(j))<:=T(j))
}
for ( i <- I ) {
add(y(i) <:= q(i) + Mz(i))
add(y(i) <:= sum(J)(j => c(i)(j)x(i)(j)) + M(1-z(i)))
add(sum(J)(j => x(i)(j)) <:= z(i))
}
add(sum(I,J){(i,j) => c(i)(j)*x(i)(j)} <:= B)
The above code has x and z as binary variables and I am getting values of 0.502 and 1
The text was updated successfully, but these errors were encountered: