Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-1730

ConstraintStream Drools: ClassCastException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 7.31.0.Final
    • None
    • None
    • None
    • 2019 Week 47-49 (from Nov 18)
    • 3
    • NEW
    • NEW

      public class Santa2019ConstraintProvider implements ConstraintProvider {
      
          @Override
          public Constraint[] defineConstraints(ConstraintFactory factory) {
              return new Constraint[] {
                  minimumDayCapacity(factory),
                  maximumDayCapacity(factory),
              };
          }
      
          private Constraint minimumDayCapacity(ConstraintFactory factory) {
              // TODO If a day has no family assigned, it should get a penalty of 125 (currently doesn't happen)
              return factory.from(Family.class)
                      .groupBy(Family::getDay, sum(Family::getSize))
                      .filter((day, size) -> size < 125)
                      .penalizeLong("Minimum day capacity", HardSoftLongScore.ONE_HARD,
                              (day, size) -> 125 - size);
          }
      
          private Constraint maximumDayCapacity(ConstraintFactory factory) {
              return factory.from(Family.class)
                      .groupBy(Family::getDay, sum(Family::getSize))
                      .filter((day, size) -> size > 300)
                      .penalizeLong("Maximum day capacity", HardSoftLongScore.ONE_HARD,
                              (day, size) -> size - 300);
          }
      
      }
      
      Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Solving failed.
      	at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.done(SolverAndPersistenceFrame.java:382)
      	at javax.swing.SwingWorker$5.run(SwingWorker.java:737)
      	at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832)
      	at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
      	at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:842)
      	at javax.swing.Timer.fireActionPerformed(Timer.java:313)
      	at javax.swing.Timer$DoPostEvent.run(Timer.java:245)
      	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
      	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
      	at java.awt.EventQueue.access$500(EventQueue.java:97)
      	at java.awt.EventQueue$3.run(EventQueue.java:709)
      	at java.awt.EventQueue$3.run(EventQueue.java:703)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
      	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
      	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
      	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
      Caused by: java.lang.RuntimeException: java.lang.ClassCastException: org.optaplannerdelirium.santa2019.domain.Family cannot be cast to java.lang.Integer
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.evaluate(ConstraintEvaluator.java:78)
      	at org.drools.modelcompiler.constraints.LambdaConstraint.isAllowed(LambdaConstraint.java:115)
      	at org.drools.core.phreak.PhreakFromNode.isAllowed(PhreakFromNode.java:266)
      	at org.drools.core.phreak.PhreakFromNode.doLeftInserts(PhreakFromNode.java:120)
      	at org.drools.core.phreak.PhreakFromNode.doNode(PhreakFromNode.java:68)
      	at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:393)
      	at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:339)
      	at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:175)
      	at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:133)
      	at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:213)
      	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
      	at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
      	at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
      	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
      	at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
      	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1337)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1328)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312)
      	at org.optaplanner.core.impl.score.stream.drools.DroolsConstraintSession.calculateScore(DroolsConstraintSession.java:60)
      	at org.optaplanner.core.impl.score.director.stream.ConstraintStreamScoreDirector.calculateScore(ConstraintStreamScoreDirector.java:70)
      	at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(AbstractScoreDirector.java:188)
      	at org.optaplanner.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider.doMove(ConstructionHeuristicDecider.java:126)
      	at org.optaplanner.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider.decideNextStep(ConstructionHeuristicDecider.java:100)
      	at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:74)
      	at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:88)
      	at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:191)
      	at org.optaplanner.examples.common.business.SolutionBusiness.solve(SolutionBusiness.java:334)
      	at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:370)
      	at javax.swing.SwingWorker$1.call(SwingWorker.java:295)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at javax.swing.SwingWorker.run(SwingWorker.java:334)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.ClassCastException: org.optaplannerdelirium.santa2019.domain.Family cannot be cast to java.lang.Integer
      	at org.optaplanner.core.impl.score.stream.drools.bi.DroolsBiCondition.lambda$andFilter$8848e7ce$1(DroolsBiCondition.java:52)
      	at org.drools.model.functions.Predicate3$Impl.test(Predicate3.java:23)
      	at org.drools.model.constraints.SingleConstraint3.lambda$getPredicate$8a56b796$1(SingleConstraint3.java:46)
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.evaluate(ConstraintEvaluator.java:74)
      	... 34 more
      

              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: