First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 12 years ago

kcrisman gravatar image

Apparently Sage renames the variables in the order you actually provided them! In this example it's easier to see because I've given a different coefficient to w[2] and w[3].

sage: p=MixedIntegerLinearProgram()
sage: w=p.new_variable()
sage: p.add_constraint(-w[0]+2*w[2]+3*w[3]==4)  # - for the first, 2 for the second, 3 for the third
sage: p.add_constraint(w[0]+w[1]+w[3]==3)
sage: p.set_objective(w[0]- w[1])  # so if w[1] is the last variable to arrive, it will be x_3
sage: p.show()
Maximization:
  x_0 -x_3  # and indeed it is
Constraints:
  4.0 <= -x_0 +2.0 x_1 +3.0 x_2 <= 4.0
  3.0 <= x_0 +x_2 +x_3 <= 3.0
Variables:
  x_0 is a continuous variable (min=0.0, max=+oo)
  x_1 is a continuous variable (min=0.0, max=+oo)
  x_2 is a continuous variable (min=0.0, max=+oo)
  x_3 is a continuous variable (min=0.0, max=+oo)

Now maybe that's a bug, or at least needs to be documented better.