I have previously worked with the MOEA Framework, which knows the concept of constraints. That is, a solution to a problem might have a good fitness, but is infeasible. For instance, when working with the knapsack problem, a particular combination of items may lead to a high profit, but their weight exceeds the knapsack's capacity. A corresponding fitness function would include lines like:
// Set the fitness (=> profit) of the solution (=> knapsack).
solution.setObjective(0, profit)
// Set the constrain (=> 0.0 if OK, , otherwise the distance to the boundary).
solution.setConstraint(0, (weight <= capacity) ? 0.0 : weight - capacity)
Another example in case of a multi-objective knapsack problem would be the constraint that a knapsack is not allowed to use items which are already used in another knapsack.
Has Jenetics something similar? Or how could I encode constraints as part of the fitness function (or somewhere else)?
As of Jenetic v5.0.0, both
phenotypeValidator
andgenotypeValidator
have been removed, but it is now possible to define aConstraint
(see also user guide, section 2.5):One can also implement
Constraint
'srepair
method to try to repair given individuals.Please note (see this answer):