MixedIntegerLinearProgram strange behavior
This is a reedition of my initial question
I find missleading the following comportment (I have add name="w") according the suggestion of dsejas
%display latex p =
MixedIntegerLinearProgram(maximization=False,
solver = "GLPK")
w = p.new_variable(integer=True,
nonnegative=True,name="w")
p.add_constraint(w[0] + w[1] + w[2] - 14*w[3] == 1)
p.add_constraint(w[1] + 2w[2] - 8w[3] == 0)
p.add_constraint(2w[2] - 3w[3] == 0)
p.add_constraint(w[0] - w[1] - w[2] >= 0)
p.add_constraint(w[3] >= 1)
p.set_objective(w[2]+ 5*w[3])
p.show()
but look at what is shown. The $x_i$'s are in the display. Then I have typpeset :
b = p.get_backend()
b.solver_parameter("simplex_or_intopt", "simplex_only")
b.solver_parameter("verbosity_simplex", "GLP_MSG_ALL")
ans = p.solve()
ans
followed by
val=p.get_values(w)
val
and finally
val0=p.get_values(w[2])
val0
Look at w[2]'s value. It is not an integer value.
Could you please put each command in it own line ?
I agree with tmontiel. Your code should be formatted. Also, are you using implicit multiplication? Your code seems to be missing some asterisks.
Concerning the $w$ vs $x$ problem, I can suggest you to use
That should allow you to have $w$ as variable instead of $x$.
As for the LaTeX output, I am afraid the
show()
method outputs a pre-formated string, so you cannot display it as LaTeX, as far as I know. However, I can suggest you to define your own function to take care of this. Depending on your skills, it should be easy for you. If it's not, please, let me know, so I can check if I can develop a small piece of code for you.dsejas I am just a beginner in Sagemath. I will appreciate if you develop the small piece of code as you just sugggest. Thanks a lot.
Hello, @Cyrille. OK, I will try to write a subroutine to output LaTeX code; it may take me some time. However, I would like to know: Do you want the problem or the solution output as LaTeX? Or do want both?
On the other hand,
p.show()
is showing $x$ as variable because of the way this command formats its output. However, you may have noticed that there are $w$'s in the description of the problem, by using thename='w'
option, as I suggested.Concerning the non-integer values, I am not completely sure how the
solver_parameter
method you used works, but you seem to have established wrong parameters there. If I remove the two lines with that method, I get integer solutions. Check my following comment (I run out of allowed characters).You can check the code I modified from your MILP problem here. I hope I got it right.