The value of a variable of an entity starts out as null during construction heuristics, even if it's not nullable.

The usual trick is to add null safe getters:

public class BedDesignation {

   // bed is planning variable
  ...
  public Departement getDepartment() {
     if (bed == null) { return null;}
     return bed.getRoom().getDepartement()
  }
}


Op 28-01-13 15:13, André Fróes schreef:
I've implemented it to see how it would work, now I got another error:

---------------

12:10:41.357 [main] INFO  o.d.p.core.solver.DefaultSolver - Solving started: time spend (302), score (null), new best score (null), random seed (0).
Exception in thread "main" Exception executing consequence for rule "requiredCpuPowerTotal" in com.swa.planner.domain.rule: java.lang.NullPointerException
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at org.drools.planner.core.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:177)
at org.drools.planner.core.solver.scope.DefaultSolverScope.calculateScore(DefaultSolverScope.java:92)
at org.drools.planner.core.phase.AbstractSolverPhaseScope.calculateScore(AbstractSolverPhaseScope.java:120)
at org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.processMove(DefaultGreedyDecider.java:136)
at org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.doMove(DefaultGreedyDecider.java:110)
at org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.decideNextStep(DefaultGreedyDecider.java:82)
at org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.solve(DefaultGreedyFitSolverPhase.java:65)
at org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:155)
at com.swa.planner.domain.CloudTest.main(CloudTest.java:65)
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at org.mvel2.util.ErrorUtil.rewriteIfNeeded(ErrorUtil.java:12)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:302)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at org.drools.base.mvel.MVELCompilationUnit.compile(MVELCompilationUnit.java:435)
at org.drools.base.mvel.MVELCompilationUnit.getCompiledExpression(MVELCompilationUnit.java:238)
at org.drools.rule.constraint.MvelConstraint.createMvelConditionEvaluator(MvelConstraint.java:206)
at org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:190)
at org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
at org.drools.common.SimpleBeliefSystem.insert(SimpleBeliefSystem.java:38)
at org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:204)
at org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:176)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:231)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:245)
at org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:210)
at org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:205)
at com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_d2d9e4332c804bacac7861ac867eb4bd.defaultConsequence(Rule_requiredCpuPowerTotal_d2d9e4332c804bacac7861ac867eb4bd.java:14)
at com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_d2d9e4332c804bacac7861ac867eb4bdDefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
at com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_d2d9e4332c804bacac7861ac867eb4bdDefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 14 more

-----------------

this one i have no clue 


2013/1/28 André Fróes <arfmoraes@gmail.com>
Hello there, i'm getting this error:

-------------------
11:26:50.394 [main] INFO  o.d.p.core.solver.DefaultSolver - Solving started: time spend (187), score (null), new best score (null), random seed (0).
Exception in thread "main" java.lang.IllegalStateException: The selectionOrder (DECREASING_DIFFICULTY) can not be used on a PlanningEntity (com.swa.planner.domain.CloudProcess) that has no support for difficulty sorting. Check the @PlanningEntity annotation.
at org.drools.planner.core.heuristic.selector.entity.PlanningEntitySelector.validate(PlanningEntitySelector.java:53)
at org.drools.planner.core.heuristic.selector.entity.PlanningEntitySelector.phaseStarted(PlanningEntitySelector.java:45)
at org.drools.planner.core.constructionheuristic.greedyFit.selector.GreedyPlanningEntitySelector.phaseStarted(GreedyPlanningEntitySelector.java:41)
at org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.phaseStarted(DefaultGreedyFitSolverPhase.java:111)
at org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.solve(DefaultGreedyFitSolverPhase.java:57)
at org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:155)
at com.swa.planner.domain.CloudTest.main(CloudTest.java:51)
-------------------------

I know why it is happening though (at least i think so), but will I have to implement the comparator to every planner I do or is there any other way to make it work?

I'm reproducing the example from the guide, when it passes the drools rules it gives that message. I didn't implement CloudComputerStrengthComparator neither CloudProcessDifficultyComparator, will I have to implement those so this example works?



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users