ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 19 Feb 2014 05:27:18 -0600MixedIntegerLinearProgram method .get_values() returns "IndexError: list index out of range"http://ask.sagemath.org/question/11053/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?Tue, 18 Feb 2014 23:45:52 -0600http://ask.sagemath.org/question/11053/mixedintegerlinearprogram-method-get_values-returns-indexerror-list-index-out-of-range/Comment by Nathann for <p>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:</p>
<pre><code>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)
</code></pre>
<p>Returns</p>
<pre><code>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
</code></pre>
<p>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?</p>
http://ask.sagemath.org/question/11053/mixedintegerlinearprogram-method-get_values-returns-indexerror-list-index-out-of-range/?comment=16237#post-id-16237What is the type of 's', and where is it first defined ?Wed, 19 Feb 2014 05:27:18 -0600http://ask.sagemath.org/question/11053/mixedintegerlinearprogram-method-get_values-returns-indexerror-list-index-out-of-range/?comment=16237#post-id-16237