Ask Your Question

Revision history [back]

Output results of sage MixedIntegerLinearProgram solution are not as expected

For the problem below

#!/usr/bin/sage -python

from sage.all import *
import sys

problem = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")
y = problem.new_variable(real=True, name='y')

constraints_1 = [(0.0, 6769.0),
                 (8260.0, 6812.0),
                 (12390.0, 7105.0),
                 (16520.0, 7448.0),
                 (20650.0, 7924.0),
                 (24780.0, 8289.0),
                 (28910.0, 8630.0),
                 (33040.0, 9000.0)]
sos_var_1 = problem.new_variable(name='sos2_var')
eq1_1 = 0.0
eq1_2 = 0.0
eq1_3 = 0.0
for i in range(len(constraints_1)):
    eq1_1 += sos_var_1[i]*constraints_1[i][0]
    eq1_2 += sos_var_1[i]*constraints_1[i][1]
    eq1_3 += sos_var_1[i]
problem.add_constraint(eq1_1 == 23450)
problem.add_constraint(eq1_2 == y[0])
problem.add_constraint(eq1_3 == 1)

problem.set_objective(y[0])
print problem.solve()

I am expecting the result to be 8136 but I am getting

8099.05084746

Can anyone help or explain why this is happening?