
Figure 1 - Complex Schedule
Introduction
Let me present you with the following problem. Let's say I have a company of 32 consultants. Suppose I have 5 consulting projects over a 3 month period and I want to rotate each of my consultants through all these projects in such a way so that they all end up with equal pay at the end of the project. One project pays $500/day, one project pays $400/day, one project pays $300/day, one pays $200/day and finally one pays $100/day. To simplify the problem, one consultant can work the same day and earn the sum of the two projects, but there are only 5 slots you can occupy in a day, one for each project. In other words on any given day, you can have at the most 5 consultants working the 5 projects.
How would I go about solving this problem? Well I had several thoughts on it at first. You could some how round robin your consultants. Choose the first 5 then the next 5 then the next 5 and then have then rotate their order. This doesn't work out very easily though, because the number of consultants does not divide easily into the 3 month period. You could just randomly assign them to all the slots and see if it works out. Then just keep switching them around until it evens out. This particular solution is not as easy to resolve as it seems.
So what is the easiest solution? Genetic Algorithms. Let the computer do the work through trial and error. Each time the GA will try to fill a schedule, give a fitness to the result, and the highest fitness survives. (Ain't GA's grand!) The beauty about genetic algorithms is that you never really care how the GA gets to the answer, you only care about how accurately you represent the fitness of the solution contained in each Genome. Although this solution can take a long arduous time to complete, it works. (Imagine when quantum computing comes into play, then the long arduous part goes away!)
In this article we will use a genetic algorithm called PBIL (Population based Learning) to converge on the solution. Population based learning maintains a learning vector and converges on a solution using this vector in conjunction with the fitness of the genomes.
Genome Representation
As is true with every genetic algorithm, the trick is to figure out how the genome can be a representation of a possible solution. In the case of our problem, we want the genome to represent the schedule for the entire 3 months of our 5 projects. Each gene in the genome is a consultant in a particular slot in the schedule. Since we conveniently have 32 consultants, then we can represent each consultant as a 5 digit binary number from 00000b - 11111b.
The schedule has 5 slots over a 3 month period. There are 5 working days in a week and 4 weeks in a month, so the calculation of number of slots is:
(3 months ) * (20 days/month) * (5 slots) = 300 slots.
The calculation of the number of bits in our genome is:
(5 bits/consultant) * 300 slots = 1500 bits
Now we have a representation in the genome of the entire schedule containing a consultant for each slot of the schedule over a 3 month period. For example, here is the start of a possible genome:
11000 | 00100 | 00000 | 10001 | 00111 | ....
The string above represents the first 5 consultants in the first 5 slots of the 300 slot schedule. In other words, these are all the consultants for a possible genome on day 1. If we translate to base 10, we see that this comes out to:
24 , 4 , 0 , 17 , 7
If we assigned each consultant an ID from 0-31 then consultant with ID 24 would be filling slot #1 on day 1, consultant 4 fills slot #2, consultant 0 fills slot #3, consultant 17 fills slot #4 and consultant 7 fills slot #5.
The part of the genetic algorithm that constructs the genome will continue to fill the slots all the way up until the end of the month to represent one genome or an entire schedule of consultants for the 3 month period. Since we want them all to get paid equally, we need to come up with a fitness function that will find a genome that balances the pay of all consultants for the 3 month period.
Fitness Function
The easiest way to figure out what the fitness of the problem is to ask ourselves "What is it exactly we are trying to accomplish?". What we want in this problem is for all consultants to get paid equally over the 3 month period. That means that if we add up the total billing for the period of 3 months for a consultant and compare it to another consultant, the billing should be close to the same (give or take a few hundred bucks). How can we do this comparison? One way to do the comparison is to first add up the amount billed each individual consultant in a particular genome. Then take the average billing for all consultants represented in the genome. Then sum the standard deviations (the amount each consultant's total billing varies from the average). The larger the sum of the standard deviations, the worse the fitness. Therefore we should take the reciprocal of the calculated sum in order to make a higher deviation a worse fitness.
Using this method, as the fitness of the genes get higher and higher as we run our algorithm, the consultants total billing over the 3 month period should begin to equalize.
The Code for Fitness




Sonu ChaudharyPosted Feb 25, 2016, 7:19 AM
nice article
Praveen KumarPosted Feb 22, 2013, 2:58 AM
@Yusuf...Fixed images. Can you see now.
Yusuf KaratoprakPosted Feb 21, 2013, 2:05 AM
hi Mike; i can not see pics of article.
setarePosted Mar 26, 2010, 9:21 PM
Dear Mike I need a program for sovling patient scheduling using genetic algorithm,may I ask you please help me?
Bleu SnowPosted Jan 23, 2010, 6:40 AM
hey bro.. u r not using population, crossover, mutation and generations.. so is ur program is still consider as GA?
jj thomasPosted May 31, 2007, 7:20 PM
Hi I have the same problem like hannah, the particular output is a density of o.5,0.5 .............. Need your help thanks
Hannah BananaPosted Apr 20, 2007, 10:23 AM
Hi.. When I run the code.. I do not get the above out... No generations are displayed.. just .5,.5.... Any ideas? Thanks again... cool stuff!
jonPosted Apr 19, 2007, 12:21 PM
Very cool... how would you modify the fitness function - based upon consultants requesting specific projects... say each consultant picks thier first to n choice of jobs to work on. thanks!