Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Looking for help with AI::Genetic and classroom scheduling

by blokhead (Monsignor)
on Feb 20, 2005 at 05:22 UTC ( #432836=note: print w/ replies, xml ) Need Help??


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

Note: I started writing this before you posted your followup w/ code. It seems like you have a decent handle on a lot of this so far...

it seems like nearly any crossover is going to generate a schedule that immediately gets stillborn as an impossible deal.
Then don't make impossible/infeasible schedules "stillborn." Chances are you will start out with a population of impossible course schedules anyway. So if your fitness function just checks whether the schedule is feasible or not (and gives any non-feasible schedule zero fitness), you are just waiting for mutations to take you into the realm of valid schedules. That's even worse than a brute-force solution.

Your fitness function should have a good gradient over the entire search space. Some impossible schedules are more impossible than others. Take off X points for each instructor conflict, Y points for each room conflict, etc. You'll get continually closer to a valid schedule.

As for satisfying the students' course ranking, I would have each student give a satisfaction rating to each schedule. 1 point for each of his/her top 5 choices that he/she can attend (i.e, that are scheduled and don't overlap). Then take the average over all the students and add that to the fitness for the schedule (this will be an expensive fitness function to compute). Obviously weight the big room/teacher conflicts more than the student preferences (which it seems you have already done).

As for representation, my preference would be a function mapping classroom timeslots to courses (i.e, an array: course assignmed to 1st slot, course assignmed to 2nd slot, etc). This way you are always sure that all the classroom slots are filled. Then you just take off points for classes scheduled twice, or teachers with two slots at the same time. Crossover is a snap now, as you can have different population members specialize in a good schedule for the beginning/end of the week and combine them to get a really good full-week schedule.

but if someone has a better module, I'll use that instead.
I mentioned in the CB that I have written Algorithm::Evolve. You can be the judge of whether it's better (I have never looked at AI::Genetic) -- and I'm always open to suggestions. Check out the distribution's examples/ dir.

blokhead


Comment on Re: Looking for help with AI::Genetic and classroom scheduling
Re^2: Looking for help with AI::Genetic and classroom scheduling
by merlyn (Sage) on Feb 20, 2005 at 14:02 UTC
    Your fitness function should have a good gradient over the entire search space. Some impossible schedules are more impossible than others. Take off X points for each instructor conflict, Y points for each room conflict, etc. You'll get continually closer to a valid schedule.
    And that's also the "aha!" that I had when I wrote the code I pasted earlier. I was thinking too literally in terms of genetics. I would have considered "impossible" solutions as "stillborn" offspring that should never exist to roam around and mate, so I was stumped trying to figure out how to prevent such an individual from ever ending up in the gene pool.

    Once I realized that I could just put them in the "undesirable" category by dinging them for unworkabilities, the GA did the right thing, and kept mixing up the "least undesirable", and within a dozen generations, I had a breeding population that was "in the black" (all hard constraints satisified, and thus now working on optimizing the soft constraints).

    Cool.

    Well, I learned something. This is always a good thing.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://432836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-10-20 05:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (72 votes), past polls