Here's one way to solve the problem with PROC OPTMODEL:
proc optmodel;
/* declare parameters and read input data set */
set <str,str> COURSE_ROOM;
num capacity {COURSE_ROOM};
num load {COURSE_ROOM};
read data HAVE into COURSE_ROOM=[course room_no] capacity=room_capacity load=room_load;
/* calculate demand per course */
set <str> COURSES init {};
num demand {COURSES} init 0;
for {<c,r> in COURSE_ROOM} do;
COURSES = COURSES union {c};
demand[c] = demand[c] + load[c,r];
end;
/* declare decision variables */
var NewRoomLoad {<c,r> in COURSE_ROOM} >= 0 <= capacity[c,r];
var IsAvailable {COURSE_ROOM} binary;
/* declare objective */
/* max NumAvailable = sum {<c,r> in COURSE_ROOM} IsAvailable[c,r];*/
max AvailableCapacity = sum {<c,r> in COURSE_ROOM} capacity[c,r] * IsAvailable[c,r];
/* declare constraints */
con RespectCapacity {<c,r> in COURSE_ROOM}:
IsAvailable[c,r] = 1 implies NewRoomLoad[c,r] = 0;
/* con RespectCapacity {<c,r> in COURSE_ROOM}:*/
/* NewRoomLoad[c,r] <= NewRoomLoad[c,r].ub * (1 - IsAvailable[c,r]);*/
con SatisfyDemand {c in COURSES}:
sum {<(c),r> in COURSE_ROOM} NewRoomLoad[c,r] = demand[c];
/* call MILP solver */
solve;
/* create output data set */
create data WANT from [COURSE ROOM_NO]={<c,r> in COURSE_ROOM}
ROOM_CAPACITY=capacity ROOM_LOAD=load NEW_ROOM_LOAD=NewRoomLoad Room_Status=(if IsAvailable[c,r] > 0.5 then 'Available' else '');
quit;
The first MAX statement (commented out) maximizes the number of available rooms. The second MAX statement maximizes the available capacity. For your sample data, both objectives yield the same available rooms:
COURSE
ROOM_NO
ROOM_CAPACITY
ROOM_LOAD
NEW_ROOM_LOAD
Room_Status
CHEM101
C101
20
7
20
CHEM101
C102
20
11
16
CHEM101
C103
10
8
0
Available
CHEM101
C104
15
10
0
Available
BIO302
HB102
22
20
19
BIO302
HB106
24
12
0
Available
BIO302
HB902
30
29
30
BIO302
W102
30
31
30
BIO302
AB102
40
27
40
If you are using a SAS version that does not support indicator constraints (IMPLIES), you can use the second (commented out) RespectCapacity constraint instead.
It might also be worth considering a secondary objective like minimizing the number of reassigned students. Also, is there any concern about the reassignments introducing schedule conflicts where the same student is enrolled in different courses that meet at the same time?
... View more