Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Indexes in Linear programming

If you look at the output of this linear program

bomb = MixedIntegerLinearProgram(maximization=True, solver = "GLPK"); x = bomb.new_variable(integer=True, nonnegative=True);

bomb.add_constraint(0.9*x[1]>=200);
bomb.add_constraint(0.9*x[0]+0.27*x[6]>= 0.9*x[1])
bomb.add_constraint(0.8*x[3]+0.24*x[8]>= 0.9*x[1])
bomb.add_constraint(0.135*x[4] + 0.9*x[10]>= 0.9*x[1])
bomb.add_constraint(0.25*x[5] + 0.9*x[11]>= 0.9*x[1])
bomb.add_constraint(x[0]+x[1]+x[2]+x[3]+x[4]+x[5]<=800);
bomb.add_constraint(x[6]+0*x[7]+x[8]+x[9]+x[10]+x[11]<=500);
bomb.set_objective(0.9*x[1])
bomb.show()

you will see that Sagemath doesn't respect the index of the $x[i]$. It enumerate the variables in the order of encounter. This is terribly perturbating. Is there a way to impose the respect of the indexes ?

Indexes in Linear programming

If you look at the output of this linear program

bomb = MixedIntegerLinearProgram(maximization=True, solver = "GLPK");
x = bomb.new_variable(integer=True, nonnegative=True);

nonnegative=True);
bomb.add_constraint(0.9*x[1]>=200);
bomb.add_constraint(0.9*x[0]+0.27*x[6]>= 0.9*x[1])
bomb.add_constraint(0.8*x[3]+0.24*x[8]>= 0.9*x[1])
bomb.add_constraint(0.135*x[4] + 0.9*x[10]>= 0.9*x[1])
bomb.add_constraint(0.25*x[5] + 0.9*x[11]>= 0.9*x[1])
bomb.add_constraint(x[0]+x[1]+x[2]+x[3]+x[4]+x[5]<=800);
bomb.add_constraint(x[6]+0*x[7]+x[8]+x[9]+x[10]+x[11]<=500);
bomb.set_objective(0.9*x[1])
bomb.show()

you will see that Sagemath doesn't respect the index of the $x[i]$. It enumerate the variables in the order of encounter. This is terribly perturbating. Is there a way to impose the respect of the indexes ? ?