How to test constraint streams with impact(...) result?

115 views
Skip to first unread message

Frank Förster

unread,
Jan 20, 2022, 6:09:09 AM1/20/22
to OptaPlanner development
Hi Optaplanners,
I have to use the impact() method as a constraint stream result to create soft scores because the score value is given from an external system an can be both, negative and positive - Works fine!
Unfortunately I can not unit test this stream with the ConstraintVerifier, no method impactedWith(...) is available. If I use rewardsWith() to test an impact of +1 I get an AssertionError:
   Expected reward: 1 (class java.lang.Integer)
     Actual impact: 1 (class java.lang.Integer)


Is there a way to test this or does anybody knows if it is planned to extend the verifier for impacts or to allow impact tests with rewardsWith()?

Thanks in advance,
Frank

Lukáš Petrovický

unread,
Jan 20, 2022, 6:52:45 AM1/20/22
to optapla...@googlegroups.com
Frank,

On Thu, Jan 20, 2022 at 12:09 PM Frank Förster <fft...@gmail.com> wrote:
Is there a way to test this or does anybody knows if it is planned to extend the verifier for impacts or to allow impact tests with rewardsWith()?

are you using the latest version of OptaPlanner? I vaguely recall we fixed an issue with these symptoms a couple months ago.
 
--

Lukáš Petrovický

He/Him/His

Principal Software Engineer, Business Automation

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

My work week is Monday to Thursday.

Frank Förster

unread,
Jan 20, 2022, 8:05:59 AM1/20/22
to OptaPlanner development
Hi Lukáš,
thanks for your fast reply.
Currently we work with version 8.9.1 because we have to use a JRE 8 yet.
But we plan to switch to JRE 11, and after hearing your good news about the constraint testing I will force this change to be able to update the OptaPlanner  :-)

Many thanks,
Frank

Lukáš Petrovický

unread,
Jan 20, 2022, 8:48:41 AM1/20/22
to optapla...@googlegroups.com
On Thu, Jan 20, 2022 at 2:06 PM Frank Förster <fft...@gmail.com> wrote:
But we plan to switch to JRE 11, and after hearing your good news about the constraint testing I will force this change to be able to update the OptaPlanner  :-)

Good plan. I think that with 8.9, you just missed the cut-off on that issue:
 

徐广

unread,
May 25, 2022, 9:02:05 PM5/25/22
to OptaPlanner development
Is this really fixed? I tried to test impact giving result as -3000 by penalty(3000)  and it gave a failure, and if I change to reward(3000) it succeeded. 
I am confused, so impact(-3000) = reward(3000) ? 

Julian Ma

unread,
Jan 24, 2023, 11:54:33 AMJan 24
to OptaPlanner development
Hi, I am experiencing the same behaviour (using optaplanner 8.32), is this intended?
Message has been deleted

Rob Johansen

unread,
Sep 11, 2023, 7:44:19 AMSep 11
to OptaPlanner development
(My previous post didn't work)

I found this issue independently writing tests for impact some months ago. I created a bug for it (PLANNER-2932) and have created a PR to fix it (PLANNER-2477 Fix ConstraintVerifier support for CS' impact() by triceo · Pull Request #1449 · apache/incubator-kie-optaplanner (github.com)) which should be in shortly.

FYI, this is a bug with the constraint verifier, not the impact method.

Reply all
Reply to author
Forward
0 new messages