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
Fixing the optaplanner guide #15702
Fixing the optaplanner guide #15702
Conversation
/cc @ge0ffrey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't compile + the guide specifically avoids fromUniquePair()
as that's more complex to use
fromUniquePair()
is sugar for from(A).join(A, ...))
but for beginners especially those that know SQL, it's better to use from+join.
@@ -446,8 +446,7 @@ public class TimeTableConstraintProvider implements ConstraintProvider { | |||
|
|||
// Select a lesson ... | |||
return constraintFactory.from(Lesson.class) | |||
// ... and pair it with another lesson ... | |||
.join(Lesson.class, | |||
.fromUniquePair(Lesson.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.from(Lesson.class).fromUniquePair(...)
will give a compile error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ge0ffrey, thank you for reviewing. I updated the class. Following the current guide on site, it is breaking on tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhuan080 Intresting, this does sound like an issue. Thank you for reporting and proposing a fix. I don't understand yet how these changes could fix a test yet.
Which test exactly? The TimeTableResourceTest
later down the guide? Or is there a ConstraintVerifier using test that I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ge0ffrey.
Yes, I have used the TimeTableResourceTest
and it fails in assertTrue(timeTable.getScore().isFeasible());
. It expect the "0hard/0soft" as return, but the code is returning "-4hard/0soft". I have checked the https://github.com/quarkusio/quarkus-quickstarts/blob/main/optaplanner-quickstart/src/main/java/org/acme/optaplanner/solver/TimeTableConstraintProvider.java and I have seen it is using .fromUniquePair
like me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ge0ffrey,
I have checked this comment said by you -->fromUniquePair() is sugar for from(A).join(A, ...)) but for beginners especially those that know SQL, it's better to use from+join.
Looking at the source code, I think it has a small difference. The .fromUniquePair is filtering the planningId. It means just the planningId < PLANNING_ID_OF_FROM will match to it. I think it will generate a return with just ordered planningId. Thus I think the set of data returned from fromUniquePair() will be less than the set of data generated by from+join. Look at this code snippet:
return this.from(fromClass).join(fromClass, joiner, Joiners.lessThan(planningIdGetter));
Let me know if my thought is correct. If so, it explains the issue I have seen in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ge0ffrey,
I have checked this comment said by you -->fromUniquePair() is sugar for from(A).join(A, ...)) but for beginners especially those that know SQL, it's better to use from+join.
Looking at the source code, I think it has a small difference. The .fromUniquePair is filtering the planningId. It means just the planningId < PLANNING_ID_OF_FROM will match to it. I think it will generate a return with just ordered planningId. Thus I think the set of data returned from fromUniquePair() will be less than the set of data generated by from+join. Look at this code snippet:
return this.from(fromClass).join(fromClass, joiner, Joiners.lessThan(planningIdGetter));
Let me know if my thought is correct. If so, it explains the issue I have seen in the tests.
@@ -446,8 +446,7 @@ public class TimeTableConstraintProvider implements ConstraintProvider { | |||
|
|||
// Select a lesson ... | |||
return constraintFactory.from(Lesson.class) | |||
// ... and pair it with another lesson ... | |||
.join(Lesson.class, | |||
.fromUniquePair(Lesson.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ge0ffrey.
Yes, I have used the TimeTableResourceTest
and it fails in assertTrue(timeTable.getScore().isFeasible());
. It expect the "0hard/0soft" as return, but the code is returning "-4hard/0soft". I have checked the https://github.com/quarkusio/quarkus-quickstarts/blob/main/optaplanner-quickstart/src/main/java/org/acme/optaplanner/solver/TimeTableConstraintProvider.java and I have seen it is using .fromUniquePair
like me.
Intresting, thank you for checking this. Yes, How long did The application.properties guarantees the solver won't stop until it reaches a feasible score (so 0 hard):
And the TimeTableResourceTest guarantees it will wait until the solver stops (unless the JUnit timeout is reached, which is also set to an hour, but than you'd get a different type of failure):
Normally, this test succeeds in a few milliseconds (small datasets) or seconds (large datasets), of course. The extremely large timings are for slow CPU's and/or use of bigger datasets. Sources: |
I have used the properties you said and all the code provided in the guide. Based on the return from |
Hi @ge0ffrey, How long did TimeTableResourceTest run for you when it failed? I have tested the Checking the https://github.com/quarkusio/quarkus-quickstarts/blob/main/optaplanner-quickstart, I have seen it use the same method I'm proposing here. The https://github.com/quarkusio/quarkus-quickstarts/blob/main/optaplanner-quickstart and guide are different in this point and is the point that is falling. In my thought, it makes sense the the Regarding the guide, it is just to help the end-user test it. It is better to use a code that runs in 5s all the time. |
@rhuan080 (sorry for the delay) That being said, for the getting started experience, from+join is clearer, so let's figure out why that doesn't do what it's suppose to do. I am not seeing what you are seeing. Shall we just jump in a quick meeting sometime to figure it out? |
@ge0ffrey updated. Thank you for helping me to understand the problem and solve it. :-) |
I think this is good to merge. Thanks @rhuan080 ! |
Signed-off-by: Rhuan Rocha <rhuan080@gmail.com>
111fb7b
to
8d5cd6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I squashed the commits, let's wait for CI and merge.
Signed-off-by: Rhuan Rocha rhuan080@gmail.com
Fixing the optaplanner guide.