Reputation: 41
I'm facing a problem of score corruption with my solution. It happens when I calculate in drools the soft score of my entities in FULL_ASSERT mode. In PRODUCTION mode the score corruption doesn't happened.
I tried to calculate a ratio that involve the current date. Basically something like (now - start_date_of_my_entity ) * priority_of_my_entity. The result of this is the score for the entity.
I tried something to fix this : in the drools file I have a global variable named "now" that is initialized by a rule named "init". That rule has a salience of 1000 in order to be sure that rule is the first rule executed. But this doesn't works either. When I run my solution, everything works fine until the variable "now" reach a time like XX:YY:ZZ+1. At this time the score corruption appears.
There is the stack trace :
10:19:00,007 INFO XXXXXXXXXXXXXXXXXX:153 - Score corruption: the workingScore (0hard/0medium/-188soft) is not the uncorruptedScore (0hard/0medium/-198soft) after completedAction (Entity(Customer1-19531312-50min)-Agent(19463312-TEST) => Agent(19463312-TEST)):
The corrupted scoreDirector has 3 ConstraintMatch(s) which are in excess (and should not be there):
com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@105d99aa, Agent(19463312-TEST)]=-63
com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-50
com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-75
The corrupted scoreDirector has 3 ConstraintMatch(s) which are missing:
com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@23739ca6, Agent(19463312-TEST)]=-63
com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-55
com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-80
Check your score constraints.
10:19:00,007 INFO BasicPlumbingTermination:59 - Terminating solver early.
java.lang.IllegalStateException: Score corruption: the workingScore (0hard/0medium/-188soft) is not the uncorruptedScore (0hard/0medium/-198soft) after completedAction (Entity(Customer1-19531312-50min)-Agent(19463312-TEST) => Agent(19463312-TEST)):
The corrupted scoreDirector has 3 ConstraintMatch(s) which are in excess (and should not be there):
com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@105d99aa, Agent(19463312-TEST)]=-63
com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-50
com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-75
The corrupted scoreDirector has 3 ConstraintMatch(s) which are missing:
com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@23739ca6, Agent(19463312-TEST)]=-63
com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-55
com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-80
Check your score constraints.
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.assertWorkingScoreFromScratch(AbstractScoreDirector.java:308)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.assertWorkingScoreFromScratch(DefaultSolverScope.java:118)
at org.optaplanner.core.impl.phase.scope.AbstractPhaseScope.assertWorkingScoreFromScratch(AbstractPhaseScope.java:131)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.processMove(LocalSearchDecider.java:164)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.doMove(LocalSearchDecider.java:149)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.decideNextStep(LocalSearchDecider.java:121)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:66)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:193)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:157)
I think that the problem come from the fact that when I jump from one minute to another, the score is not the same. For example for the entity starting at 08:10:00 and priority 5 :
It seems that the score is calculated at 08:00:59 and at 08h01:00 a score verification is done
In addition I see that the move is from the current agent to the current agent. Is this ok ?
In addition the stack trace involved another rule "agentRatio". I think it's because this rule is based on the current time to calculate the score. So same problem for this rule.
Can you help me solve this please ?
EDIT : after trying a couple of potential solution, I'm still stuck with this problem. A thing I could try is to add a problem fact that will represent time and do the time based calculation with this instead. But this solution does not please me.
Upvotes: 1
Views: 381
Reputation: 1460
I´m facing the same problem, in my case it starts happen when I moved a score calculation logic from Drools file to my java code, something like:
scoreHolder.addSoftConstraintMatch(kcontext,<complex expression>);
to
scoreHolder.addSoftConstraintMatch(kcontext,$myVariable.calculate());
According to this link I could not do it.
Upvotes: 0