Optaplanner: evaluate the solution

I am currently working on a Java project that uses Optaplanner and drools for constraint constraint issues.

The solution works just fine. But after solver gave me a solution, I want to evaluate the solution: I want to know what restrictions were violated, i.e. the rules were fired and how many times.

Is it possible and how to start from this?

+4
source share
2 answers

See the docs section Reusing Account Calculation Outside of Solver . This provides all the data you need in a simple way.

for (ConstraintMatchTotal constraintMatchTotal : guiScoreDirector.getConstraintMatchTotals()) {
    String constraintName = constraintMatchTotal.getConstraintName();
    Number weightTotal = constraintMatchTotal.getWeightTotalAsNumber();
    for (ConstraintMatch constraintMatch : constraintMatchTotal.getConstraintMatchSet()) {
        List<Object> justificationList = constraintMatch.getJustificationList();
        Number weight = constraintMatch.getWeightAsNumber();
        ...
    }
}

See Laune answer for more advanced techniques and drooling tricks.

+4

, org.kie.api.event.rule.AgendaEventListener KieSession.addEventListener(AgendaEventListener listener).

, , - .

, , - , " ", " " set - .

- , , . ,

rule abc when A() B() C() then ... end

rule not_a when not A() then ... end
rule a_not_B when A() not B() then ... end
rule ab_not_c when A() B() not C() then ... end 

, , : not_a , B C.

+1

Source: https://habr.com/ru/post/1538302/


All Articles