Optaplanner fails to solve problems randomly

60 views
Skip to first unread message

Logan Clément

unread,
Apr 27, 2022, 8:37:00 AMApr 27
to OptaPlanner development
Hello everyone,

We recently re-wrote a project that used Optaplanner 7.43.1 into a Quarkus 2.8.0 project (with Optaplanner 8.19.0).

We noticed that at random times, Optaplanner fails to solve problems, throwing this error:

[ERROR] [pool-410-thread-1] [or.op.co.im.so.DefaultSolverManager] [] Solving failed for problemId (18bac18d-b240-494d-86b9-2df9ddba153b).: java.lang.IllegalStateException: The move thread with moveThreadIndex (0) has thrown an exception. Relayed here in the parent thread.
    at org.optaplanner.core.impl.heuristic.thread.OrderByMoveIndexBlockingQueue.take(OrderByMoveIndexBlockingQueue.java:147)
    at org.optaplanner.core.impl.constructionheuristic.decider.MultiThreadedConstructionHeuristicDecider.forageResult(MultiThreadedConstructionHeuristicDecider.java:193)
    at org.optaplanner.core.impl.constructionheuristic.decider.MultiThreadedConstructionHeuristicDecider.decideNextStep(MultiThreadedConstructionHeuristicDecider.java:158)
    at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:64)
    at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:209)
    at org.optaplanner.core.impl.solver.DefaultSolverJob.call(DefaultSolverJob.java:121)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
Caused by: Exception executing consequence for rule "Some rule name" in package.of.rule.in.constraint.provider: java.lang.NullPointerException
    at org.drools.wiring.statics.StaticComponentsSupplier$StaticConsequenceExceptionHandler.handleException(StaticComponentsSupplier.java:81)
    at org.drools.kiesession.agenda.DefaultAgenda.handleException(DefaultAgenda.java:935)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:460)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:101)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.kiesession.agenda.DefaultAgenda.fireLoop(DefaultAgenda.java:748)
    at org.drools.kiesession.agenda.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:695)
    at org.drools.kiesession.agenda.DefaultAgenda.fireAllRules(DefaultAgenda.java:687)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1092)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1083)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1075)
    at org.optaplanner.constraint.streams.drools.DroolsConstraintStreamScoreDirector.calculateScore(DroolsConstraintStreamScoreDirector.java:85)
    at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(AbstractScoreDirector.java:222)
    at org.optaplanner.core.impl.heuristic.thread.MoveThreadRunner.run(MoveThreadRunner.java:147)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    ... 6 more
Caused by: java.lang.NullPointerException
    at org.optaplanner.constraint.streams.drools.common.AbstractRuleContext.runConsequence(AbstractRuleContext.java:58)
    at org.optaplanner.constraint.streams.drools.common.UniRuleContext.lambda$newRuleBuilder$f02e01a4$1(UniRuleContext.java:52)
    at org.drools.model.functions.Block3$Impl.execute(Block3.java:40)
    at org.drools.modelcompiler.consequence.LambdaConsequence.evaluate(LambdaConsequence.java:76)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:454)
    ... 19 more


The same problem can run successfully without any issues if it is re-executed.

Also, we have a test suite of several tests where, for each test, we roughly:
  •  Create a problem
  •  Instantiate a planner
  •  Solve this problem then check the results.
Running all the tests can either be successful or can result in one of the tests (any of them) throw the exception above.
The rule shown in the exception can also vary.

Unfortunately, we can barely show our implementation and I'm not sure we can create a project that throws this error without revealing our code.

However, here are some details about our project:
  • Quarkus version: 2.8.0
  • Optaplanner version: 8.19.0 (we tried several versions of Optaplanner in the 8.XX branch, from 8.18.0 to 8.20.0)
  • Java version: 17
  • We are using a reproducible environment mode
  • Our rules are an implementation of the interface ConstraintProvider. We also tried with a .drl file containing the same rules, but the problem persists.
We are completely puzzled. Do you have any idea that could help us in finding what is wrong?

Many thanks in advance,
Logan

Geoffrey De Smet

unread,
Apr 27, 2022, 6:51:06 PMApr 27
to optapla...@googlegroups.com, Logan Clément

Have you ever seen it reproduce with moveThreadCount=NONE?


We noticed that at random times, Optaplanner fails to solve problems, throwing this error:

The same problem can run successfully without any issues if it is re-executed.
This is worrisome... random failures.
We had no reports of random failures in the past. We see no such things in any of our tests.

Did you also create this StackOverflow post?
  https://stackoverflow.com/questions/71971738/intermittent-npe-in-optaplanner-constraint-streams
Or is that a different project+person running into the same issue?

With kind regards,
Geoffrey De Smet

Logan --
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/9ee755ae-2426-45ef-b49e-3f1f0a768da6n%40googlegroups.com.

Logan Clément

unread,
Apr 28, 2022, 5:56:24 AMApr 28
to OptaPlanner development
Hello Geoffrey,

Thank you for your reply.
I tested with moveThreadCount=NONE and it seems that I cannot reproduce the problem.
I tried with a moveThreadCount=10 and the exception was thrown very quickly.

Also, I'm not the creator of the StackOverflow post you linked. I searched quite some time to see if someone has the same issue as we do and could not find anything. It seems that the StackOverflow post was created after my research.
Unlike this post, we are not using configurable constraint weights.

For reference, here what one of our rules looks like:
public Constraint someRule(ConstraintFactory constraintFactory) {
    return constraintFactory
        .forEachIncludingNullVars(Request.class)
        .filter(Request::hasBeenAssigned) // filter entities with a PlanningVariable
        .penalizeLong(
            RULE_NAME,
            ONE_SOFT,
            request -> {
              var penalty = some penalty computation;
              return PENALTY_CONSTANT * penalty;
            }
        );
}

To be complete, as stated before we are also using a "reproducible" environment. The planner is composed of three phases:
  • a FIRST_FIT construction phase
  • a TABU_SEARCH
  • then an HILL_CLIMBING

Because moveThreadCount=NONE seems to fix the issue without a huge performance impact for now, we will use this value.
If you need more details that might help solve this issue, don't hesitate to ask.

Many thanks for you help !
Logan

Geoffrey De Smet

unread,
Apr 29, 2022, 9:53:53 AMApr 29
to optapla...@googlegroups.com

Thank you for reporting.

We're tracking the issue here:
  https://issues.redhat.com/browse/PLANNER-2707

We'll need a reproducer to fix it.

With kind regards,
Geoffrey De Smet

Fan Zeng

unread,
Jun 9, 2022, 5:48:00 PMJun 9
to OptaPlanner development
I have encountered a similar error. It happened only once in a simple test case in hundreds of runs. Here are the details for our environment and test case

OptaPlanner: 8.20.0.Final
JDK: 17
moveThreadCount: AUTO
Number of planning entities: 5



java.lang.IllegalStateException: The move thread with moveThreadIndex (0) has thrown an exception. Relayed here in the parent thread.
    at org.optaplanner.core.impl.heuristic.thread.OrderByMoveIndexBlockingQueue.take(OrderByMoveIndexBlockingQueue.java:147)
    at org.optaplanner.core.impl.constructionheuristic.decider.MultiThreadedConstructionHeuristicDecider.forageResult(MultiThreadedConstructionHeuristicDecider.java:193)
    at org.optaplanner.core.impl.constructionheuristic.decider.MultiThreadedConstructionHeuristicDecider.decideNextStep(MultiThreadedConstructionHeuristicDecider.java:158)
    at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:64)
    at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:209)
    ... lines removed for brevity ....
Caused by: Exception executing consequence for rule "course min/max matched" in cn.unisolution.fw.courseengine.optaplanner: java.lang.NullPointerException: Cannot invoke "org.optaplanner.constraint.streams.common.inliner.WeightedScoreImpacter.impactScore(int, org.optaplanner.constraint.streams.common.inliner.JustificationsSupplier)" because "scoreImpacter" is null
    at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)

    at org.drools.kiesession.agenda.DefaultAgenda.handleException(DefaultAgenda.java:935)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:460)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:101)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.kiesession.agenda.DefaultAgenda.fireLoop(DefaultAgenda.java:748)
    at org.drools.kiesession.agenda.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:695)
    at org.drools.kiesession.agenda.DefaultAgenda.fireAllRules(DefaultAgenda.java:687)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1092)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1083)
    at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1075)
    at org.optaplanner.constraint.streams.drools.DroolsConstraintStreamScoreDirector.calculateScore(DroolsConstraintStreamScoreDirector.java:85)
    at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(AbstractScoreDirector.java:222)
    at org.optaplanner.core.impl.heuristic.thread.MoveThreadRunner.run(MoveThreadRunner.java:147)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Cannot invoke "org.optaplanner.constraint.streams.common.inliner.WeightedScoreImpacter.impactScore(int, org.optaplanner.constraint.streams.common.inliner.JustificationsSupplier)" because "scoreImpacter" is null
    at org.optaplanner.constraint.streams.drools.common.AbstractRuleContext.runConsequence(AbstractRuleContext.java:51)
    at org.optaplanner.constraint.streams.drools.common.BiRuleContext.lambda$newRuleBuilder$2e50f6b5$1(BiRuleContext.java:45)
    at org.drools.model.functions.Block4$Impl.execute(Block4.java:40)

    at org.drools.modelcompiler.consequence.LambdaConsequence.evaluate(LambdaConsequence.java:76)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:454)
    ... 17 more
Reply all
Reply to author
Forward
0 new messages