Suggestions on model

Because required_hours_per_code is an = constraint, it requires every class code to be fully assigned. Thus either all codes will be assigned, or the solver will report “no feasible solution” and probably it will not return any useful solution.

Here’s a sketch of a possible alternative approach, which you can adapt to your specific needs.

To compute an initial solution that makes as many assignments as possible, change required_hours_per_code to a <= constraint, and adding an objective function to maximize the number of successful assignments (the sum of all the assignment variables).

After the solver returns a solution, use AMPL’s fix command to fix all of the assignments that have been made:

fix {c in CODE, r in ROOMS, d in DAYS, t in TIME: 
   assignment[c,r,d,t] = 1} assignment[c,r,d,t];

Then drop the constraints involving room_assigned, change required_hours_per_code to an = constraint, and solve again:

drop building_constraint;
drop available_slots;
redeclare subject to required_hours_per_code{c in CODE}:
    sum{r in ROOMS, d in DAYS, t in TIME} assignment[c, r, d, t] = lec[c] + lab[c];
solve;