hdbeukel / james-core

Core module of the JAMES framework
Apache License 2.0
6 stars 5 forks source link

Inconsistency of evaluation and validation of best solution #47

Closed ghost closed 6 years ago

ghost commented 7 years ago

Calling getBestSolutionEvaluation() and getBestSolutionValidation() on a Search object after the search has finished can lead to inconsistent results when using PenalizingValidations.

Expected behaviour: an evaluation can not be penalized if the solution is valid.

Observed behaviour:

Best solution evaluation: 30351.07843137255 (unpenalized: 351.078431372549)
Best solution validation: valid

Inspecting the state of the Search object further, I found that there were invalid penalties in PenalizedEvaluation bestSolutionEvaluation, but all validations in UnanimousValidation bestSolutionValidation were valid.

Can this be due to a bug in my implementation of validate()?

hdbeukel commented 7 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.

ghost commented 7 years ago

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.