In essence, you need to grow an algorithm. What does the traffic light: switches colors and waits for each of them for some time.
So the intersection has a horizontal road and a vertical one. Step by Step:
- Let it all start with the fact that horizontal sweaters are green, and vertical - red. Green lit T1 time.
- Then yellow turns on in horizontal (vertical light is still red). It burns T2 time.
- Red at horizontal, yellow at vertical. T3.
- Red at horizontal, green at vertical. T4.
- Red at horizontal, yellow at vertical. T5.
- Yellow in horizontal, red in vertical. T6.
Total, the algorithm is encoded by a tuple (T1, T2, T3, T4, T5, T6), i.e. DNA from six genes.
Now we need to define three parameters of the algorithm:
- Fitness function. Suppose we need to skip the maximum of machines per unit of time. Which of the algorithms it is higher, and that is cool.
- Mutation. Here the random gene changes a little.
- Crossbreeding We give birth to a son (the algorithm is masculine), his genes will be randomly selected from parents.
Now the simulation:
- Initially, we have N random algorithms.
- We start a cycle in which we determine the effectiveness of each algorithm (or only new ones).
- We eliminate, and slyly - the worse the algorithm, the greater the likelihood of its exclusion. However, it should not be 0 or 1.
- We cross, mutate (again, probability).
This is one of the solutions.