Closed ghost closed 6 years ago
Validation of solutions only takes into account mandatory constraints, not penalizing constraints. The latter only affect the evaluation. As a result, search.getBestSolutionValidation().passed()
should always return true
, since none of the local searches ever accepts an invalid neighbour (i.e. a solution that violates at least one mandatory constraint).
If, after executing an optimization algorithm, you want to check whether there are any violated penalizing constraints, and which, you can use problem.getViolatedConstraints(solution)
of GenericProblem
. This method returns a collection containing all violated constraints (both mandatory and penalizing).
So the solution you obtained is valid, since it does not violate any mandatory constraints, but it has been penalized. Thus, problem.getViolatedConstraints(solution)
should return a non-empty collection of violated penalizing constraints.
Thank you very much for your kind explanation.
Sometimes, I use penalizing constraints that must be satisfied for a solution to be valid. In some cases, this can make the search
find better solutions, because the search space is less restricted (of course there is a trade-off here with exploring infeasible solution candidates).
It seems my assumption that a valid solution can not have violated penalizing constraints was wrong, but as you described it is easy to check if there are violated penalizing constraints.
Calling
getBestSolutionEvaluation()
andgetBestSolutionValidation()
on aSearch
object after the search has finished can lead to inconsistent results when usingPenalizingValidations
.Expected behaviour: an evaluation can not be penalized if the solution is valid.
Observed behaviour:
Inspecting the state of the
Search
object further, I found that there were invalid penalties inPenalizedEvaluation bestSolutionEvaluation
, but all validations inUnanimousValidation bestSolutionValidation
were valid.Can this be due to a bug in my implementation of
validate()
?