can i cancel the "drools incremental score calculation"?

15 views
Skip to first unread message

chen jinhua

unread,
Dec 7, 2021, 7:34:44 AM12/7/21
to OptaPlanner development
Hi, everytime!

in my project, I need to calculate the score at 0/0/0 every time. In drools, I write like the following, my goal is to stop the solving processing when total-mytarget >=0.

slot{
x,
y,
PlanningVariable
son()
}

son(){
x,y
}

solution {
score ,
slotList
sonList(),
scoremanger.....
}
slot's x and y is changed according to son's "x" and "y".


global HardMediumSoftScoreHolder scoreHolder;

rule "test"
when
$total:Integer() from accumulate(Slot($x:getX(),$y:Son().getY()),
init(int total =0;),
action(total+=$x*$y;),
result(total))
then
scoreHolder.addSoftConstraintMatch(kcontext,$total-mytarget);
end

in my code and running situation, in the same function:

when I call the solution.getScore(), it returns the score which is calculated incrementally for example 0/0/80. 0/0/80 meets my goal that's ok. And then, i call the "ScoreExplanation<Solution, HardMediumSoftScore> scoreExplanation = scoreManager.explainScore(solution); " . The score of the solution is changed, and the score is 0/0/-140 now. After calculating, I found that the "0/0/-140" is right. 

although the score is changed to 0/0/-140,  the processing is stopped because of the appearance of 0/0/80. 

Therefore, I think I have 2 ways to solve this problem, one is to clear the score before is sub or add; two is to calculate the solution score globally every time instead of incremental.

Lukáš Petrovický

unread,
Dec 9, 2021, 2:33:31 AM12/9/21
to optapla...@googlegroups.com
Hey there,

if the solver is giving you a different score than the ScoreManager, that is a strong indication that you have a score corruption in your constraints. I suggest you run the solver with <environmentMode>FULL_ASSET</> to prove or disprove that.

Regards!

--
You received this message because you are subscribed to the Google Groups "OptaPlanner development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optaplanner-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/optaplanner-dev/0ab650c8-5a96-4971-9280-7cd1cf0aeb38n%40googlegroups.com.


--

Lukáš Petrovický

He/Him/His

Principal Software Engineer, Business Automation

lukas.pe...@redhat.com    IM: triceo/lpetrovi

My work week is Monday to Thursday.

Lukáš Petrovický

unread,
Dec 9, 2021, 2:34:11 AM12/9/21
to optapla...@googlegroups.com
My apologies for the typo, it was supposed to be <environmentMode>FULL_ASSERT</>.

chen jinhua

unread,
Dec 9, 2021, 2:55:28 AM12/9/21
to optapla...@googlegroups.com
thanks for Lukáš’s reply, i will try later and feedback.😂

Lukáš Petrovický <lpet...@redhat.com> 于2021年12月9日周四 下午3:34写道:
Reply all
Reply to author
Forward
0 new messages