Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstraintVerifier rewards and penalties inverted when using impact() #473

Open
matthias-roussel-soyhuce opened this issue Dec 6, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@matthias-roussel-soyhuce
Copy link

matthias-roussel-soyhuce commented Dec 6, 2023

Describe the bug
I have a constraint that uses impact() to either penalize or reward the score based on the planning entities. Since the ConstraintVerifier does not have a specific method to test these constraints, I tried to use rewardsWith instead (in a test cases that expects a reward), as recommended in this StackOverflow answer back on Optaplanner.

However that results in a broken expectation (see below), but works when using penalizesBy() instead.

Expected behavior
I expected the test assertion using rewardsWith() to pass, and the assertion using penalizesBy() to fail.

Actual behavior
The test assertion using rewardsWith() fails with the following exception:

java.lang.AssertionError: Broken expectation.
        Constraint: rules/preference is respected (reward)
   Expected reward: 20 (class java.lang.Integer)
     Actual impact: 20 (class java.lang.Long)

[...]

and the assertion using penalizesBy() passes.

However, a multi constraint assertion with scores() passes with a score of the expected sign, i.e. negative for a penalty and positive for a reward.

To Reproduce
Create a constraint with impact() instead of reward() and a positive match weight, and test it with a ConstraintVerifier using the rewardsWith() assertion with the expected weight.

Environment

Timefold Solver Version or Git ref: 1.4.0

Output of java -version: 17.0.6-amzn

Output of uname -a or ver: Linux <computer_name> 5.15.0-89-generic #99~20.04.1-Ubuntu SMP Thu Nov 2 15:16:47 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Additional information

The same problem was described and qualified as a bug in the aforementioned StackOverflow thread (on Optaplanner 8.25.0.Final).

@matthias-roussel-soyhuce matthias-roussel-soyhuce added bug Something isn't working process/needs triage Requires initial assessment of validity, priority etc. labels Dec 6, 2023
@triceo
Copy link
Contributor

triceo commented Dec 6, 2023

@matthias-roussel-soyhuce Thank you for reporting!

You are absolutely correct that this is a known bug. Unfortunately, we are stuck with it - fixing this would break people's tests, and therefore we can not do it on 1.x. But for 2.x, whenever that is (no plans exists), this is a must-fix.

@triceo triceo added this to the v2.0.0 (Very distant future.) milestone Dec 6, 2023
@triceo triceo removed the process/needs triage Requires initial assessment of validity, priority etc. label Dec 6, 2023
@triceo triceo self-assigned this Dec 6, 2023
@ge0ffrey
Copy link
Contributor

Given that this does seem to impact (pun intended) multiple users, shall we rediscuss the deprecation approach after the holidays?
Proposal A) Replace impact() with foo() which works correctly. Deprecate impact().

@triceo triceo removed their assignment Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants