http://qs1969.pair.com?node_id=432869


in reply to Looking for help with AI::Genetic and classroom scheduling

Yeah I did my dissertation on this subject - using Perl. Without getting into all the intricate details, a really nice representation is to use a 3D array. $array[ROOM_NUMBER][WEEKDAY][TIMESLOT] = CLASS You are susceptable to the label replacement problem (i.e. classes can be booked more than once, or not at all), but that can be easily fixed by a genetic repair operator which just books them again in the next available slot. To give you an example - take the room capacity violation, it's a hard contraint, the pseudo code may look something like this:
Procedure room_capacity_violation For R in 0 .. totalRooms For D in 0 .. totalDays For H in 0 .. totalHours If (chromosome[R][D][H] != 0) If (chromosome[R][D][H]->CLASS_SIZE > room[R]->CLASSROOM_SIZE) + count := count + 1 End If End If End For End For End For Return(count) End room_capacity_violation
So you return the count which represents how many times that hard constraint has been violated. This allows you to perform selection based on the best individuals (those who violate the contraints least) - or whatever selection method you use, because sometimes it's good to keep some traits in your population for the sakes of genetic diversity. One benefit that comes from this encoding method is that one contraint is alreadt assured; it is impossible to double book a room. I hope that is of some help (direct or otherwise).