Al Capone
Al Capone

Reputation: 17

Defining a fitness function in the genetic algorithm

I'm in the process of developing a simple application that uses the genetic algorithm for scheduling a timetable. I had a look at various examples and most of them appear to be using the algorithm to reach the initial specified solution in a various amount of generations, and not other solutions based on constraints.

For example, in main class:

FitnessFunction.setSolution("0001012002");

output:

compile:
run:
Generation: 1 Fittest: 5
Generation: 2 Fittest: 6
Generation: 3 Fittest: 7
Generation: 4 Fittest: 9
Solution found!
Generation: 4
Genes:
0001012002

I understand that I have to declare the fitness function in some way. For example 1 represents a day shift and 2 a night shift. My question is how do I add the constraint that 2 can follow 1 however, 1 cannot follow 2? Would I have to replace the initial specified solution with a series of constraints? and how would that look like in code?

Any help appreciated, thanks!

Upvotes: 0

Views: 97

Answers (0)

Related Questions