[rules-users] Error selecting order decrease [planner] - mvel NPE eats real exception?
André Fróes
arfmoraes at gmail.com
Mon Jan 28 12:22:07 EST 2013
That was a tricky one :D
It worked, the problem was that c in upper case.
Thanks a lot for your patient Geoffrey
My best regards
2013/1/28 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
> Wrong way in your drl:
> IntConstraintOccurrence(ConstraintType == ConstraintType.SOFT,
> $weight : weight),
> Correct way in the drl (mind the case of constraintType):
> IntConstraintOccurrence(constraintType == ConstraintType.SOFT,
> $weight : weight),
>
> Op 28-01-13 17:08, André Fróes schreef:
>
> I'm sending a screenshot of my libs, all from the bundle downloaded from
> site. Also sending the full proj if u want to analyze.
>
> [image: Imagem inline 1]
>
>
> 2013/1/28 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>
>> Which mvel2 jar version?
>>
>> Provided that the mvel version is correct, it looks like the real
>> exception gets eaten...
>>
>> Caused by: java.lang.NullPointerException
>> at java.lang.String.<init>(Unknown Source)
>> at org.mvel2.util.ErrorUtil.rewriteIfNeeded(ErrorUtil.java:12)
>>
>> If that's true, we need to open a jira. Pinging Mario on this.
>>
>> In any case, the exception message should be much clearer as to what's
>> the problem is.
>>
>> Op 28-01-13 16:51, André Fróes schreef:
>>
>> 5.5.0.Final both
>>
>>
>> 2013/1/28 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>>
>>> Which version of planner (drools-planner-core) and drools (drools-core,
>>> drools-compiler)?
>>> Op 28-01-13 16:40, André Fróes schreef:
>>>
>>> I'm comparing both the example and my implementation, can't see anything
>>> different from each other except that example uses that
>>> CloudBalancingGenerator. Even the drl rule remains the same, i wrote it and
>>> then fixed the errors until reach that point.
>>>
>>>
>>> 2013/1/28 André Fróes <arfmoraes at gmail.com>
>>>
>>>> this is the full drl file:
>>>>
>>>> ------------
>>>>
>>>> package com.swa.planner.domain.rule;
>>>>
>>>> import
>>>> org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScoreHolder;
>>>> import org.drools.planner.core.score.constraint.IntConstraintOccurrence;
>>>> import org.drools.planner.core.score.constraint.ConstraintType;
>>>>
>>>> import com.swa.planner.domain.CloudBalance;
>>>> import com.swa.planner.domain.CloudComputer;
>>>> import com.swa.planner.domain.CloudProcess;
>>>>
>>>> global HardAndSoftScoreHolder scoreHolder;
>>>>
>>>> rule "requiredCpuPowerTotal"
>>>> when
>>>> $computer : CloudComputer($cpuPower : cpuPower)
>>>> $requiredCpuPowerTotal : Number(intValue > $cpuPower) from accumulate(
>>>> CloudProcess (
>>>> computer == $computer,
>>>> $requiredCpuPower : requiredCpuPower),
>>>> sum($requiredCpuPower)
>>>> )
>>>> then
>>>> insertLogical(new IntConstraintOccurrence("requiredCpuPowerTotal",
>>>> ConstraintType.NEGATIVE_HARD,
>>>> $requiredCpuPowerTotal.intValue() - $cpuPower,
>>>> $computer));
>>>> end
>>>>
>>>> rule "requiredMemoryTotal"
>>>> when
>>>> $computer : CloudComputer($memory : memory)
>>>> $requiredMemoryTotal : Number(intValue > $memory) from accumulate(
>>>> CloudProcess (
>>>> computer == $computer,
>>>> $requiredMemory : requiredMemory),
>>>> sum($requiredMemory)
>>>> )
>>>> then
>>>> insertLogical(new IntConstraintOccurrence("requiredMemoryTotal",
>>>> ConstraintType.NEGATIVE_HARD,
>>>> $requiredMemoryTotal.intValue() - $memory,
>>>> $computer));
>>>> end
>>>>
>>>> rule "requiredNetworkBandwidth"
>>>> when
>>>> $computer : CloudComputer($networkBandwidth : networkBandwidth)
>>>> $requiredNetworkBandwidthTotal : Number(intValue > $networkBandwidth)
>>>> from accumulate(
>>>> CloudProcess (
>>>> computer == $computer,
>>>> $requiredNetworkBandwidth : requiredNetworkBandwidth)
>>>> sum($requiredNetworkBandwidth)
>>>> )
>>>> then
>>>> insertLogical(new IntConstraintOccurrence("requiredNetworkBandwidth",
>>>> ConstraintType.NEGATIVE_HARD,
>>>> $requiredNetworkBandwidthTotal.intValue() - $networkBandwidth,
>>>> $computer));
>>>> end
>>>>
>>>> rule "hardConstraintBroken"
>>>> salience -1
>>>> when
>>>> $hardTotal : Number() from accumulate(
>>>> IntConstraintOccurrence(constraintType ==
>>>> ConstraintType.NEGATIVE_HARD, $weight : weight)
>>>> sum($weight)
>>>> )
>>>> then
>>>> scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
>>>> end
>>>>
>>>>
>>>> // Soft constraint
>>>>
>>>> rule "computerCost"
>>>> when
>>>> $computer : CloudComputer($cost : cost)
>>>> exists CloudProcess(computer == $computer)
>>>> then
>>>> insertLogical(new IntConstraintOccurrence("computerCost",
>>>> ConstraintType.NEGATIVE_SOFT,
>>>> $cost,
>>>> $computer));
>>>> end
>>>>
>>>> rule "softConstraintBroken"
>>>> salience -1
>>>> when
>>>> $softTotal : Number() from accumulate(
>>>> IntConstraintOccurrence(ConstraintType ==
>>>> ConstraintType.NEGATIVE_SOFT, $weight : weight)
>>>> sum($weight)
>>>> )
>>>> then
>>>> scoreHolder.setHardConstraintsBroken($softTotal.intValue());
>>>> end
>>>>
>>>>
>>>> 2013/1/28 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>>>>
>>>>> com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_0a10acbeca924206a3becab080617987.defaultConsequence(Rule_requiredCpuPowerTotal_0a10acbeca924206a3becab080617987.java:14)
>>>>>
>>>>> What's in the then side of Rule_requiredCpuPowerTotal ?
>>>>>
>>>>> Op 28-01-13 16:00, André Fróes schreef:
>>>>>
>>>>> Even adding that, the error still
>>>>>
>>>>> --------------
>>>>> 12:57:41.050 [main] INFO o.d.p.core.solver.DefaultSolver - Solving
>>>>> started: time spend (152), 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:67)
>>>>> 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_0a10acbeca924206a3becab080617987.defaultConsequence(Rule_requiredCpuPowerTotal_0a10acbeca924206a3becab080617987.java:14)
>>>>> at
>>>>> com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_0a10acbeca924206a3becab080617987DefaultConsequenceInvokerGenerated.evaluate(Unknown
>>>>> Source)
>>>>> at
>>>>> com.swa.planner.domain.rule.Rule_requiredCpuPowerTotal_0a10acbeca924206a3becab080617987DefaultConsequenceInvoker.evaluate(Unknown
>>>>> Source)
>>>>> at
>>>>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
>>>>> ... 14 more
>>>>>
>>>>> --------------
>>>>>
>>>>> I added to cloudprocess computer variable:
>>>>> --------------
>>>>> package com.swa.planner.domain;
>>>>>
>>>>> import org.drools.planner.api.domain.entity.PlanningEntity;
>>>>> import org.drools.planner.api.domain.variable.PlanningVariable;
>>>>> import org.drools.planner.api.domain.variable.ValueRange;
>>>>> import org.drools.planner.api.domain.variable.ValueRangeType;
>>>>> import org.drools.planner.examples.common.domain.AbstractPersistable;
>>>>>
>>>>> @PlanningEntity(difficultyComparatorClass =
>>>>> CloudProcessDifficultyComparator.class)
>>>>> public class CloudProcess extends AbstractPersistable{
>>>>>
>>>>> private int requiredCpuPower;
>>>>> private int requiredMemory;
>>>>> private int requiredNetworkBandwidth;
>>>>>
>>>>> private CloudComputer computer;
>>>>>
>>>>> public CloudProcess(long id, int requiredCpuPower, int
>>>>> requiredMemory,
>>>>> int requiredNetworkBandwidth) {
>>>>> super();
>>>>> setId(id);
>>>>> this.requiredCpuPower = requiredCpuPower;
>>>>> this.requiredMemory = requiredMemory;
>>>>> this.requiredNetworkBandwidth = requiredNetworkBandwidth;
>>>>> }
>>>>> public CloudProcess() { }
>>>>>
>>>>> public int getRequiredCpuPower() {
>>>>> return requiredCpuPower;
>>>>> }
>>>>>
>>>>> public void setRequiredCpuPower(int requiredCpuPower) {
>>>>> this.requiredCpuPower = requiredCpuPower;
>>>>> }
>>>>>
>>>>> public int getRequiredMemory() {
>>>>> return requiredMemory;
>>>>> }
>>>>>
>>>>> public void setRequiredMemory(int requiredMemory) {
>>>>> this.requiredMemory = requiredMemory;
>>>>> }
>>>>>
>>>>> public int getRequiredNetworkBandwidth() {
>>>>> return requiredNetworkBandwidth;
>>>>> }
>>>>>
>>>>> public void setRequiredNetworkBandwidth(int
>>>>> requiredNetworkBandwidth) {
>>>>> this.requiredNetworkBandwidth = requiredNetworkBandwidth;
>>>>> }
>>>>>
>>>>> public String getLabel() {
>>>>> return "Process " + id;
>>>>> }
>>>>> @PlanningVariable(strengthComparatorClass =
>>>>> CloudComputerStrengthComparator.class)
>>>>> @ValueRange(type = ValueRangeType.FROM_SOLUTION_PROPERTY,
>>>>> solutionProperty = "computerList")
>>>>> public CloudComputer getComputer() {
>>>>> if (computer == null) { return null; }
>>>>> return computer;
>>>>> }
>>>>>
>>>>> public void setComputer(CloudComputer computer) {
>>>>> this.computer = computer;
>>>>> }
>>>>> public CloudProcess clone(){
>>>>> CloudProcess clone = new CloudProcess();
>>>>> clone.id = id;
>>>>> clone.requiredCpuPower = requiredCpuPower;
>>>>> clone.requiredMemory = requiredMemory;
>>>>> clone.requiredNetworkBandwidth = requiredNetworkBandwidth;
>>>>> clone.computer = computer;
>>>>> return clone;
>>>>> }
>>>>> public int getRequiredMultiplicand() {
>>>>> return requiredCpuPower * requiredMemory *
>>>>> requiredNetworkBandwidth;
>>>>> }
>>>>> }
>>>>> --------------
>>>>>
>>>>> this is what i'm doing to run the example:
>>>>>
>>>>> -------------
>>>>> package com.swa.planner.domain;
>>>>>
>>>>> import java.io.ByteArrayInputStream;
>>>>> import java.util.ArrayList;
>>>>> import java.util.List;
>>>>>
>>>>> import org.drools.planner.config.SolverFactory;
>>>>> import org.drools.planner.config.XmlSolverFactory;
>>>>> import org.drools.planner.core.Solver;
>>>>>
>>>>> public class CloudTest {
>>>>> public static void main(String[] args) {
>>>>> String t = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
>>>>> + "<solver>"
>>>>> + "
>>>>> <solutionClass>com.swa.planner.domain.CloudBalance</solutionClass>"
>>>>> + "
>>>>> <planningEntityClass>com.swa.planner.domain.CloudProcess</planningEntityClass>"
>>>>> + " <scoreDirectorFactory>"
>>>>> + " <scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>"
>>>>> + "
>>>>> <scoreDrl>/com/swa/planner/domain/rule/cloudBalancingScoreRules.drl</scoreDrl>"
>>>>> + " </scoreDirectorFactory>"
>>>>> + " <termination>"
>>>>> + " <maximumSecondsSpend>120</maximumSecondsSpend>"
>>>>> + " </termination>"
>>>>> + " <constructionHeuristic>"
>>>>> + "
>>>>> <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>"
>>>>> + "
>>>>> <constructionHeuristicPickEarlyType>FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING</constructionHeuristicPickEarlyType>"
>>>>> + " </constructionHeuristic>"
>>>>> + " <localSearch>"
>>>>> + " <acceptor>"
>>>>> + " <planningEntityTabuSize>7</planningEntityTabuSize>"
>>>>> + " </acceptor>"
>>>>> + " <forager>"
>>>>> + " <minimalAcceptedSelection>1000</minimalAcceptedSelection>"
>>>>> + " </forager>"
>>>>> + " </localSearch>"
>>>>> + "</solver>";
>>>>>
>>>>> byte b[] = t.getBytes();
>>>>> ByteArrayInputStream bt = new ByteArrayInputStream(b);
>>>>> SolverFactory solverFactory = new XmlSolverFactory().configure(bt);
>>>>> Solver solver = solverFactory.buildSolver();
>>>>>
>>>>> List<CloudComputer> computerList = new ArrayList<CloudComputer>();
>>>>> computerList.add(new CloudComputer(1L, "Computador 1", 3, 2, 2,
>>>>> 110));
>>>>> computerList.add(new CloudComputer(2L, "Computador 2", 12, 8, 3,
>>>>> 400));
>>>>> computerList.add(new CloudComputer(3L, "Computador 3", 6, 6, 4,
>>>>> 300));
>>>>> computerList.add(new CloudComputer(4L, "Computador 4", 18, 12, 8,
>>>>> 1000));
>>>>> computerList.add(new CloudComputer(5L, "Computador 5", 8, 4, 6,
>>>>> 800));
>>>>> computerList.add(new CloudComputer(6L, "Computador 6", 9, 7, 9,
>>>>> 1000));
>>>>>
>>>>> List<CloudProcess> processList = new ArrayList<CloudProcess>();
>>>>> processList.add(new CloudProcess(11L, 2, 2, 2));
>>>>> processList.add(new CloudProcess(12L, 4, 4, 2));
>>>>> processList.add(new CloudProcess(13L, 1, 1, 3));
>>>>> processList.add(new CloudProcess(14L, 7, 3, 5));
>>>>> processList.add(new CloudProcess(15L, 5, 8, 3));
>>>>> processList.add(new CloudProcess(16L, 9, 2, 2));
>>>>> processList.add(new CloudProcess(17L, 6, 5, 6));
>>>>>
>>>>> CloudBalance cloudBalance = new CloudBalance();
>>>>> cloudBalance.setId(0L);
>>>>> cloudBalance.setComputerList(computerList);
>>>>> cloudBalance.setProcessList(processList);
>>>>>
>>>>> // Solve the problem
>>>>> solver.setPlanningProblem(cloudBalance);
>>>>> solver.solve();
>>>>> CloudBalance solvedCloudBalance = (CloudBalance)
>>>>> solver.getBestSolution();
>>>>>
>>>>> // Display the result
>>>>> System.out.println("\nSolved cloudBalance with 5 computers and 6
>>>>> processes:\n"
>>>>> + toDisplayString(solvedCloudBalance));
>>>>> }
>>>>>
>>>>> public static String toDisplayString(CloudBalance cloudBalance) {
>>>>> StringBuilder displayString = new StringBuilder();
>>>>> for (CloudProcess process : cloudBalance.getProcessList()) {
>>>>> CloudComputer computer = process.getComputer();
>>>>> displayString.append(" ").append(process.getLabel())
>>>>> .append(" -> ")
>>>>> .append(computer == null ? null : computer.getLabel())
>>>>> .append("\n");
>>>>> }
>>>>> return displayString.toString();
>>>>> }
>>>>> }
>>>>>
>>>>> -------------
>>>>>
>>>>>
>>>>> 2013/1/28 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>>>>>
>>>>>> 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:
>>>>>>
>>>>>> ---------------
>>>>>>
>>>>>> ...
>
> [Mensagem cortada]
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130128/8b4dc18b/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 101366 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20130128/8b4dc18b/attachment-0001.png
More information about the rules-users
mailing list