I am trying to run this constraint problem but the memory runs out, $$S_{i}$$ are 1975 Students that need to be assigned to one of 188 teacher assistants classes, each teacher assistant has to chose a time slot $$TA_{j}$$ from out of 8. Each Teacher assistant and Student have their expressed time slots in dfTA
and dfS
data frames.
The idea is to assign a teacher assistant to each student and a time slot to each teacher assistant. Of course all students in a class must be able to take that class as well as the teacher assistant to give it.
import constraint
problem = constraint.Problem()
for i in range(0,1974):
problem.addVariable(f'S_{i}', range(0,187))
for i in range(0,187):
problem.addVariable(f'TA_{i}', range(0,8))
for S in range(0,1974):
for TA in range(0,187):
exec(f"""def timezone{S}_{TA}(s,t):
if s!=TA:
return True
if s==TA and (dfS.iloc[S,1+t]>0)*(dfTA.iloc[TA,t]>0):
return True
else:
return False
problem.addConstraint(timezone{S}_{TA}, ['S_{S}','TA_{TA}'])""")
problem.getSolutions()
If anyone knows how to solve this or optimize this it would be of great use.
Link to a Colab notebook: https://colab.research.google.com/drive/1pb9qM13S2GmpjHAWIAEUCRwYwvyF68IT?usp=sharing
And data: https://drive.google.com/drive/folders/1J6yAfXIKcn0NZrT6xtluxt71nyhuR0ak?usp=sharing