P
P
Popou2021-12-17 05:52:09
Python
Popou, 2021-12-17 05:52:09

Genetic Algorithm, How to write a fitness function?

I'm not asking for a code, I'm asking for directions.

I wanted to write a GA for scheduling university lessons, but I constantly stumble upon a false minimum, increasing the mutation rate does not help, everything else works (I use Accord.Genetic), so it's about my understanding of the fitness function. The conditions there are not difficult: teachers choose an hour in which they cannot work for one reason or another, some groups do not study in certain pairs (for example, my group does not study in 5, 6, 7.8 pairs, but a friend is exactly the opposite ), and the last condition - the group has a set of compulsory disciplines for the week, like 3 mathematics, 3 German. Of course, there should be no conflicts.

I used two options, but both will enter a false minimum

1) the fitness function has a range of values ​​from 0 to 1, the criteria that are evaluated and their range, 48 is the number of possible pairs (6 days * 8):

  • Extra Lessons =[0..1] (48- Number of Extras )/48
  • Lack of Lessons = [0..1] ( Sum of Needed Lessons - Sum of Missing Lessons )/ Sum of Needed Lessons
  • Inconvenient time for the group =[0..1] (48- NumberPairsInInconvenientTime ) /48
  • Uncomfortable Time for Teachers = [0..1] ( Number of CouplesThey Teach - Number of CouplesAt UncomfortableTime )/ Number of CouplesThey Teach
  • Conflict Pairs for Teachers = [0..1] ( Number of Pairs They Teach - Number of Conflict Pairs )/ Number of Pairs They Teach

Then the arithmetic mean is taken and here is the result of the fitness function. For you to understand, I even tried to round 0.1865456 to 0.1 so that the algorithm would not be so much "afraid" of making mistakes, I even made it so that the only possible values ​​were [0, 0.5, 1] ​​and this did not help ..... .......

The second option uses all the same evaluation criteria, but now the range is not limited (within the framework of double, of course) and now these are penalties, if they are equal to zero, then this is good. And also at the end does not take the arithmetic mean, but simply their sum. And again I fall into a false minimum!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan., 2021-12-17
@Popou

You have all the parameters described so that in the ideal case the value of each of them will be equal to 1.
For example:
Conflict pairs for teachers = [0..1] (Number of Couples They teach - Number of Conflict Couples )/Number of Couples They teach Number of Conflict Couples
= 0, parameter value = 1.
As a result, you need to claim the maximum and not the minimum from your function.
Maybe rewrite the description of the parameters in reverse, so that the target value tends to 0?
For example:
Conflict Pairs for Teachers = [0..1] Number of Conflict Pairs/Number of Pairs They Teach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question