Ask Your Question

Revision history [back]

Your program is infeasible.

  • you have constraint 0.0 <= x_0 - 1.5 x_1 - 1.5 x_3 <= 4.5. Since x_1 and x_3 are at least 1.5 and x_0 at most 4.5, you need to set x_0=4.5, x_1=x_3=1.5 to satisfy the lower bound.
  • you also have constraint x_0 + x_1 + x_2 + x_3 == 8.5 which can be satisfied only if x_2 = 8.5 - 4.5 - 1.5 - 1.5 = 1. But since you have 2.75 <= x_2 <= 4.5, this is impossible.

Without the lower bound on constraint 0.0 <= x_0 - 1.5 x_1 - 1.5 x_3 <= 4.5, you can get a solution.

Let me rewrite the code in a way I'm more familiar with:

def foo():
    F = 10
    a = 1.5
    p = MixedIntegerLinearProgram(maximization=True)
    x = p.new_variable(nonnegative=True)
    p.add_constraint(x[0], min=3/20*F, max=9/20*F)
    p.add_constraint(x[1], min=3/20*F, max=9/20*F)
    p.add_constraint(x[2], min=11/40*F, max=9/20*F)
    p.add_constraint(x[3], min=3/20*F, max=9/20*F)
    p.add_constraint(x[0] + x[1] + x[2] + x[3] == 17/20*F)
    p.add_constraint(x[0] - a*x[1] - a*x[3] <= 9/20*F)  # upper bound only
    for i in range(4):
        p.add_constraint(x[4] <= x[i])
    p.set_objective(x[4])
    p.show()
    p.solve()
    x_val = p.get_values(x)
    show(x_val)

Then you get:

sage: foo()
Maximization:
  x_4 

Constraints:
  1.5 <= x_0 <= 4.5
  1.5 <= x_1 <= 4.5
  2.75 <= x_2 <= 4.5
  1.5 <= x_3 <= 4.5
  8.5 <= x_0 + x_1 + x_2 + x_3 <= 8.5
  x_0 - 1.5 x_1 - 1.5 x_3 <= 4.5
  - x_0 + x_4 <= 0.0
  - x_1 + x_4 <= 0.0
  - x_2 + x_4 <= 0.0
  - x_3 + x_4 <= 0.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)
  x_4 is a continuous variable (min=0.0, max=+oo)
{0: 1.916666666666667,
 1: 1.916666666666667,
 2: 2.749999999999999,
 3: 1.916666666666667,
 4: 1.916666666666667}