0

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 must chose a time slot TA_{j} for its class. Each Teacher assistant and Student have their expressed timeslots out of 8 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.

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.

jeroaranda
  • 61
  • 8
  • It's going to be a little tricky to get help without access to the data you're working with. In general though, I'd recommend looking into the Z3 solver https://github.com/Z3Prover/z3 for this sort of thing. Also, you do have an off-by-one error on your `range`s since Python excludes the top element. – Randy Jun 20 '20 at 01:30
  • thanks, dfTA.iloc[i,j] is 1 if the teacher I is able to give class at time slot j and dfS.iloc[i,j] is 1 if student i is able to take class at time slot j. They are only allowed to choose 2 contigous time slots. – jeroaranda Jun 20 '20 at 03:34
  • Python nitpicking: note that `range(0,1974)` has 1974 elements and not 1975. – Erwin Kalvelagen Jun 30 '20 at 04:44
  • A better description (and a small data set) would certainly help. – Erwin Kalvelagen Jun 30 '20 at 04:56
  • in that case second nitpick `range(0,187)` has also only 187 elements and not 188 – gelonida Jun 30 '20 at 07:00
  • Are you still chewing on this? And if so, can you say a bit more about your time slots? Are they just an indexed set of 8 options where each student & instructor has some subset of the 8 as available? – AirSquid Jul 22 '20 at 23:50
  • yes, but its going around here https://or.stackexchange.com/questions/4418/how-can-i-optimize-this-integer-programming-constraint-problem-without-running-o?noredirect=1 :) – jeroaranda Jul 23 '20 at 22:37

0 Answers0