Optaplanner with MongoDB

22 views
Skip to first unread message

Alberto Benincasa

unread,
Jan 26, 2023, 7:11:41 AM1/26/23
to OptaPlanner development
Good morning everyone!

Starting from the no longer supported web implementation of Optaplanner https://github.com/kiegroup/optaweb-employee-rostering

I only used the backend part and replaced the mysql database with a mongodb one.
everything works fine except when I run the solve. it seems that the algorithm finds the correct solution (by looking at the logs), but my database is not updated accordingly (the output of the score does not coincide with the one that, solving again the same roster, is calculated at the start of the process). Is there some way to debug this to try and get to the root of the problem?

Thank you so much

Lukáš Petrovický

unread,
Jan 26, 2023, 7:27:26 AM1/26/23
to optapla...@googlegroups.com
Alberto,

start with FULL_ASSERT. What you're describing doesn't sound like a persistence problem, it sounds like a score corruption.

--
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/0efe6cdc-6b5e-4c72-b10a-1635a668292dn%40googlegroups.com.


--

Lukáš Petrovický

OptaPlanner Project Lead

lukas.pe...@redhat.com

My work week is Monday to Thursday.
No need to respond outside of your working hours.

Alberto Benincasa

unread,
Jan 26, 2023, 10:04:44 AM1/26/23
to OptaPlanner development
Hi!

Thank for the fast reply.
Unfortunately, I think I'm missing some steps. The use case is very simple because I have two shifts (one 09-13 the other 14-18) and three employees. Only two of these have the right skills and both have a contract that cannot exceed 4 hours per day, so the best solution is to assign one shift each. Performing the solve I receive the following output

2023-01-26 15:59:36,895 INFO  [org.opt.cor.imp.sol.DefaultSolver] (pool-145-thread-1) Solving started: time spent (3), best score (0hard/-2medium/0soft), environment mode (FULL_ASSERT), move thread count (NONE), random (JDK with seed 0).
2023-01-26 15:59:36,918 INFO  [org.opt.cor.imp.con.DefaultConstructionHeuristicPhase] (pool-145-thread-1) Construction Heuristic phase (0) ended: time spent (26), best score (0hard/0medium/0soft), score calculation speed (1863/sec), step total (2).
2023-01-26 15:59:46,918 INFO  [org.opt.cor.imp.loc.DefaultLocalSearchPhase] (pool-145-thread-1) Local Search phase (1) ended: time spent (10026), best score (0hard/0medium/0soft), score calculation speed (3072/sec), step total (3715).
2023-01-26 15:59:46,918 INFO  [org.opt.cor.imp.sol.DefaultSolver] (pool-145-thread-1) Solving ended: time spent (10026), best score (0hard/0medium/0soft), score calculation speed (3068/sec), phase total (2), environment mode (FULL_ASSERT), move thread count (NONE).

So basically it seems that from Optaplanner pov it can find the right solution (0/0/0) but in mongo I just see the two shifts assigned to the same employee (hence breaking the rule of the maximum contract daily). If I try to perform the solve again, I obtain this

2023-01-26 16:02:56,364 INFO  [org.opt.cor.imp.sol.DefaultSolver] (pool-145-thread-4) Solving started: time spent (2), best score (-180hard/0medium/0soft), environment mode (FULL_ASSERT), move thread count (NONE), random (JDK with seed 0).
2023-01-26 16:02:56,365 INFO  [org.opt.cor.imp.con.DefaultConstructionHeuristicPhase] (pool-145-thread-4) Construction Heuristic phase (0) ended: time spent (3), best score (-180hard/0medium/0soft), score calculation speed (1000/sec), step total (0).
2023-01-26 16:03:06,371 INFO  [org.opt.cor.imp.loc.DefaultLocalSearchPhase] (pool-145-thread-4) Local Search phase (1) ended: time spent (10009), best score (0hard/-1medium/0soft), score calculation speed (3002/sec), step total (4406).
2023-01-26 16:03:06,371 INFO  [org.opt.cor.imp.sol.DefaultSolver] (pool-145-thread-4) Solving ended: time spent (10009), best score (0hard/-1medium/0soft), score calculation speed (3001/sec), phase total (2), environment mode (FULL_ASSERT), move thread count (NONE).

How can I use the FULL_ASSERT to check if there is something wrong?

THank you

Lukáš Petrovický

unread,
Jan 26, 2023, 10:08:55 AM1/26/23
to optapla...@googlegroups.com
Alberto,

FULL_ASSERT is used to check that the solver operates properly. If it didn't, you'd see exceptions. So, we can assume that the solver is not your problem.

However, OptaPlanner project doesn't provide any support for persisting to MongoDB. Therefore there isn't any code I can help you with - if your own persistence solution persists the solutions improperly, you'll have to find the issue on your own.

Check the solution that is leaving the solver; you'll want to listen for best solutions.
And then figure out the problem in your mapping of the best solution to your DB.

Alberto Benincasa

unread,
Jan 26, 2023, 10:12:27 AM1/26/23
to optapla...@googlegroups.com
Hi.

Thank you so much for the feedback, you gave me some very useful information

Alberto

You received this message because you are subscribed to a topic in the Google Groups "OptaPlanner development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/optaplanner-dev/gKdbzvliejk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to optaplanner-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/optaplanner-dev/CAEs6%2BmzvsLAo%2B6FBAycL4SS63pcs97fdemhEg7H43_5r6Pj9-A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages