Fixing parts of multidimensional variable for another run

Hey guys,

I am somewhat of a beginner in GAMS. Therefore excuse me if the question is trivial. Still would be very thankful for your help.
I’ll try and explain the problem I have:

I want to create a timetable. Through modeling I got a binary variable X(c, r, t, s, h, d) which is 1 if class c in room r is taught by teacher t in subject s at hour h on day d and 0 else.

Now I am supposed to change the teacher assignement, while the rest of the timetable remains the same. (One could imagine new teachers arrive and you would have to rebalance the schedule). How am I supposed to use the .fx here? Alternatively, I could write a new model using something like this:

...
parameter InputNew(c, r, s, h, d);
InputNew(c, r, s, h, d) = sum(t, X.l(c, r, t, s, h, d));
...

but it does not seem too practical to do it that way. I think you could probably use loop() here, my idea was something like this, which does not work:

loop(c,
	loop(r,
		loop(s,
			loop(h,
			if ((x.l(c, r, t, s, h, d) = 1;
			X.fx(c, r, t, s, h, d) = sum(t, X.l(c, r, t, s, h, d)));
			);
		);
	);
);

Would anyone be willing to give a hint?

Best regards

You have a variable X(c, r, t, s, h, d). If you change t in this, you get a completely new time table. When you define X like this, it doesn’t mean much to say “keeping everything else constant” and some teacher will come and teach at (c,r,s,h,d). Instead, you need another variable that is part of the model that does this for you.

x1(c,r,s,h,d) (1 if some teacher teaches (c,r,s,h,d))
and x2(c,r,t, s,h,d) if teacher t teaches at (c,r,s,h,d)

if x2 is 1 for any t, x1 should be 1; 0 otherwise.

x1(c,r,s,h,d) =e= sum(t, x2(c,r,t,s,h,d))

now after each solve you can fix x1

x1.fx(c,r,s,h,d) = x1.l(c,r,s,h,d);

I assume that you need this because you are updating the time table iteratively. I don’t understand the bigger picture behind your question but this is how I would try to do this. Hope this helps.

  • Atharv

Hey,

Thank you so much for the answer! That was exactly what I was missing.

If you are interested:
Reason being that we’ll have changes of staff over the summer break and rotate the teacher assignement to each class as well. In the following semester the students are supposed to have a identical timetable (same room, same subjects, same times) but with different teachers.