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@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@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:

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

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


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




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


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