Printing indices of 3-dimensional variable in PuLP for scheduling
<p>I am working with SolverStudio (Excel add-in) and PuLP (Python-based optimization language) to create a tool that assigns students to working places.</p>

<p>This is the variable whose indices I want to print:</p>

<p><code># Decision variable, =1 if student s is assigned to working place w on day d; 0 otherwise
Assignment = LpVariable.dicts("Assignment",(Students,Working_places,Days),0,1,LpBinary)</code></p>

<p>For each working place and day, I want to output the name of the student who is assigned there, in order to create a schedule.</p>

<p>My current approach is:</p>

<pre><code>for w in Working_places:
    for d in Days:
        for s in Students:
            if Assignment[s][w][d] == 1:
                Schedule[w,d] = Name[s]
</code></pre>

<p><code>Schedule[w,d]</code> is an empty 2d parameter defined in SolverStudio and <code>Name[s]</code> contains the names of the students. </p>

<p>I placed the code sequence at different positions of the model. It doesn't make a difference, whether it is before or after the <code>prob.solve()</code> statement.</p>

<p>Currently, <code>Schedule[w,d]</code> is being filled completely with the name of the last student in the list of students.</p>

<p>I observed that the if-clause is completely ignored. I can remove it and the same output is generated.</p>

<p>Is there a different way to tell Python "for each working place and day, print the assigned student"?</p>

<p>Thank you very much in advance!</p>

<p>Found the mistake myself in the meantime:</p>

<p><code>for w in Working_places:
    for d in Days:
        for s in Students:
            if Assignment[s][w][d].varValue == 1:
                Schedule[w,d] = Name[s]</code></p>

python optimization scheduling pulp