Ask Your Question

zbowen's profile - activity

2014-06-29 14:52:02 +0200 received badge  Popular Question (source)
2014-06-29 14:52:02 +0200 received badge  Notable Question (source)
2014-06-29 14:52:02 +0200 received badge  Famous Question (source)
2014-02-19 06:45:52 +0200 asked a question MixedIntegerLinearProgram method .get_values() returns "IndexError: list index out of range"

I'm writing an MLP to solve a scheduling problem for a set of jobs. I have several variable types, including family 's_ij', which is a boolean indicating if time i occurs before or after time j. My program works, and returns feasible solutions. I'm trying to see the assigned values for each variable, and while I can see the start time for each job, and some other families of booleans, when I try to display the values for the 's_ij' variables, I get an "IndexError". This is weird, since I'm letting the MILP package do all the work here. Here are relevant sections of the code, as well as the output:

from itertools import product
...
J = range(len(JOBS))
I = range(2*len(JOBS))
IXJ_copy = product(I, J)
...
for pair in IXJ_copy:
i = pair[0]
j = pair[1]
if i == len(I) - 1:
    scheduling_mlp.add_constraint(s[(i, j)] <= 0)
else:
    scheduling_mlp.add_constraint(M*(1-s[(i, j)]) + b[i+1] - t[j] - EPSILON >= 0)
    scheduling_mlp.add_constraint(M*s[(i, j)] + t[j] - b[i+1] >= 0)
scheduling_mlp.add_constraint(M*e[(i, j)] + b[i] - t[j] - T(j) >= 0)
scheduling_mlp.add_constraint(M*(1-e[(i, j)]) + t[j] + T(j) - b[i] - EPSILON >= 0)
scheduling_mlp.add_constraint(M*(1-u[(i, j)]) + s[(i, j)] + e[(i, j)] >= 2)
scheduling_mlp.add_constraint(-M*(u[(i, j)]) + s[(i, j)] + e[(i, j)] <= 1)
...
print("s:")
start = scheduling_mlp.get_values(s)
print(start)

Returns

Traceback (most recent call last):
  File "lp_solver.py", line 186, in <module>
    start = scheduling_mlp.get_values(s)
  File "mip.pyx", line 1161, in sage.numerical.mip.MixedIntegerLinearProgram.get_values (sage/numerical/mip.c:7098)
IndexError: list index out of range

As I said, when I run the code, I get feasible solutions back. I have the case handling in place while defining my constraints to prevent b[i+1] from going out of range. I'm able to get_values and print all other variables. Any ideas what's going wrong here?