[AMPL 25002] Suggestion on Constraints

hi im trying to do an automated class scheduling . can you give me suggestion on how can i constraint the assignment of rooms to their predefined buildings only? also avoid assigning in between lunchbreak

set CODE;

set ROOMS;

set DAYS ordered := {“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”};

set TIME ordered := {“8:00am - 9:00am”, “9:00am - 10:00am”, “10:00am 11:00am”, “11:00am - 12:00nn”, “1:00pm - 2:00pm”, “2:00pm - 3:00pm”, “3:00pm - 4:00pm”, “4:00pm - 5:00pm”};

param program{CODE} symbolic;

param section{CODE} symbolic;

param course_num{CODE} symbolic;

param course_title{CODE} symbolic;

param room{CODE} symbolic;

param lec{CODE} >= 0;

param lab{CODE} >= 0;

param teaching_load{CODE} >= 0;

param building{CODE} symbolic;

param buildings{ROOMS} symbolic;

param floor{ROOMS} symbolic;

param type{ROOMS} symbolic;

param lecture{ROOMS} binary;

param laboratory{ROOMS} binary;

Read data from Excel

load amplxl.dll;

table overall IN “amplxl” “timetable.xlsx” “overall”:

CODE ← [CODE], program, section, course_num, course_title, room, lec, lab, teaching_load, building;

table rooms IN “amplxl” “timetable.xlsx” “rooms”:

ROOMS ← [ROOMS], buildings, floor, type, lecture, laboratory;

table b IN “amplxl” “timetable.xlsx” “buildings”:


read table overall;

read table rooms;

read table b;

var assignment{CODE, ROOMS, DAYS, TIME} binary;

var room_assigned{CODE, ROOMS} binary;


subject to required_hours_per_course{c in CODE}:

sum{r in ROOMS, d in DAYS, t in TIME} assignment[c, r, d, t] = lec[c] + lab[c];

subject to no_conflicts {r in ROOMS, d in DAYS, t in TIME}:

sum {c in CODE} assignment[c, r, d, t] <= 1;

subject to single_assignroom_per_slot{c in CODE, d in DAYS, t in TIME}:

sum{r in ROOMS} assignment[c, r, d, t] <= 1;

subject to same_room_per_code {c in CODE}:

sum{r in ROOMS} room_assigned[c, r] = 0 or sum{r in ROOMS} room_assigned[c, r] = card(ROOMS);

Your question has been moved to our new user forum at discuss.ampl.com, and a response has been posted. To see the response, use this link:


To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)