I\'m working on an algorithm which goal is to find a minimum set of packages to install package \"X\".
I\'ll explain better with an example:
Another (fun) way to solved this issue is to use a genetic algorithm.
Genetic Algorithm is powerful but you have to use a lot of parameters and find the better one.
Genetic Step are the following one :
a . Creation : a number of random individual, the first generation (for instance : 100)
b. mutation : mutate of low percent of them (for instance : 0,5%)
c. Rate : rate (also call fitness) all the individual.
d. Reproduction : select (using rates) pair of them and create child (for instance : 2 child)
e. Selection : select Parent and Child to create a new generation (for instance : keep 100 individual by generation)
f. Loop : Go back to step "a" and repeat all the process a number of time (for instance : 400 generation)
g. Pick : Select an individual of the last generation with a max rate. Individual will be your solution.
Here is what you have to decide :
You have to represent a possible solution (call individual) of your problem as a genetic code.
In your case, it could be a group of letter representing the node which respect constraint OR and NOT.
For instance :
[ A E B Y ], [ A C K H ], [A E Z B Y] ...
To know if an individual is a good solution, you have to rate it, in order to compare it to other individual.
In your case, it could be pretty easy : individual rate = number of node - number of individual node
For instance :
[ A E B Y ] = 8 - 4 = 4
[ A E Z B Y] = 8 - 5 = 3
[ A E B Y ] as a better rate than [ A E Z B Y ]
Thanks to individual's rate, we can select Pair of them for reproduction.
For instance by using Genetic Algorithm roulette wheel selection
Take a pair of individual an create some (for instance 2) child (other individual) from them.
For instance :
Take a node from the first one and swap it with a node of the second one.
Make some adjustment to fit "or, and" constraint.
[ A E B Y ], [ A C K H ] => [ A C E H B Y ], [ A E C K B Y]
Note : that this is not the good way to reproduct it because the child are worth than the parent. Maybe we can swap a range of node.
You have just to change genetic code of select individual.
For instance :
Delete a node
Make some adjustment to fit "or, and" constraint.
As you can see, it's not hard to implements but a lot of choice has to be done for designing it with a specific issue and to control the different parameters (percent of mutation, rate system, reproduction system, number of individual, number of generation, ...)