Suggestion on Constraints

13 views
Skip to first unread message

Jessa Cancino

unread,
Mar 19, 2024, 10:00:25 PMMar 19
to AMPL Modeling Language

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":

BUILDINGS <- [BUILDINGS];

read table overall;

read table rooms;

read table b;

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

var room_assigned{CODE, ROOMS} binary;

# Constraints

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);

AMPL Google Group

unread,
Mar 20, 2024, 3:34:24 PMMar 20
to AMPL Modeling Language
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:

https://discuss.ampl.com/t/suggestions-on-model/1004/2

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


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2544897820-123126#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/eafe8b1a-e286-4d10-a3e7-301762c85d03n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages