Help to implement my 1st planner
by André Rezende Fróes de Moraes
Hello everyone, i'm trying to implement drools planner for my paper and it
is proving very hard taking in consideration that i never user it before.
I was able to reproduce the examples, even though i got very confused, but
i undestood some things, but i'm really lost of how to implement my own
project/rule.
My paper is about service, I don't really know how to define it, but i'll
try to explain.
A given company receive several requests of maintence, repair, etc, all the
time, and it have a number of people to solve that, these technicians. It's
something like the nurse roaster but waaaay to simpler.
An issue can pop at any minute, it have a starting time and an estimated
time to be acomplished.
The technician have work for a fixed amount of time, but he have the start
time and the end time of work, that I want to use to assign the issue.
I've created the class Technician
Technician
----------------------------
import java.util.Date;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("Technician")
public class Technician extends AbstractPersistable {
private int engId;
private int workTime;
private Date startWorkTime;
private Date endWorkTime;
private Technician technician;
public Technician(int engId, int workTime, Date startWorkTime,
Date endWorkTime) {
super();
this.engId = engId;
this.workTime = workTime;
this.startWorkTime = startWorkTime;
this.endWorkTime = endWorkTime;
}
public int getEngId() {
return engId;
}
public void setEngId(int engId) {
this.engId = engId;
}
public Date getStartWorkTime() {
return startWorkTime;
}
public int getWorkTime() {
return workTime;
}
public void setWorkTime(int workTime) {
this.workTime = workTime;
}
public void setStartWorkTime(Date startWorkTime) {
this.startWorkTime = startWorkTime;
}
public Date getEndWorkTime() {
return endWorkTime;
}
public void setEndWorkTime(Date endWorkTime) {
this.endWorkTime = endWorkTime;
}
public Technician getTechnician() {
return technician;
}
public void setTechnician(Technician technician) {
this.technician = technician;
}
}
------------------------------------
Issue class
------------------------------------
import java.util.Date;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("CloudComputer")
public class Issue extends AbstractPersistable {
private Date startTime;
private Date estimatedTime;
public Issue(Date startTime, Date estimatedTime) {
super();
this.startTime = startTime;
this.estimatedTime = estimatedTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEstimatedTime() {
return estimatedTime;
}
public void setEstimatedTime(Date estimatedTime) {
this.estimatedTime = estimatedTime;
}
}
--------------------------------
and here i got lost. I'm trying to schedule the technician to these issues
based on the estimated time and in the time left of technician.
I accept any kind of help or comment, I need it for next monday, i'll be
tunned everytime on this trying to make it happen.
Thanks for your time
Aijin Nakanishi
11 years, 10 months
[Error: incompatible types in statement: boolean (compared from: class be.axi.planner.domain.Task)]
by Michiel Vermandel
I am using Drools Planner 5.5.0.Final.
During the running of a unit test I sometimes get a crash with stack-trace shown beneath.
It does not happen all the time, just now and then.
But if it happens the process terminates and no solution is reached.
Any ideas on this?
The stack-trace does not show a lot on which rule is failing...
[Error: incompatible types in statement: boolean (compared from: class be.axi.planner.domain.Task)]
[Near : {... this == lead ....}]
^
[Line: 1, Column: 1]
at org.mvel2.ast.BinaryOperation.<init>(BinaryOperation.java:84)
at org.mvel2.util.CompilerTools.finalizePayload(CompilerTools.java:118)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:287)
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.NamedEntryPoint.insert(NamedEntryPoint.java:311)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at org.drools.planner.core.score.director.drools.DroolsScoreDirector.afterEntityAdded(DroolsScoreDirector.java:103)
at org.drools.planner.core.heuristic.selector.variable.PlanningVariableWalker.moveIterator(PlanningVariableWalker.java:145)
at org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.decideNextStep(DefaultGreedyDecider.java:74)
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 be.axi.planner.app.InspectionSchedule.solve(InspectionSchedule.java:192)
at be.axi.planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:288)
at be.axi.planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:298)
at be.axi.planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:315)
at be.axi.planner.TaskGroupingTest.communitySuccess02(TaskGroupingTest.java:289)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
11 years, 10 months
Can SolverFactory receive the plain xml?
by André Fróes
Can I provide the plain xml code to a SolverFactory?
SolverFactory solverFactory = new XmlSolverFactory(<<xmlHere>>);
I know that I can provide the path to a config file.
11 years, 10 months
how to get field names from Rule using drools 5.5
by jeetendray
Hi,
Here is my DRL structure, and I want to pull field names such as
proposalName and proposalId from below DRL using Drools 5.5 API. Earlier I
used to do that using OrConstraints and LiteralConstraints of Drools 4.0.7
but seems like these files are no longer available with drools 5.5.
package drools
import drools.ProposalLight
rule Proposal bugdet rule
when
$obj : ProposalLight(proposalName.equals("Jeet") || proposalId ==
121)
then
$obj.addFailedRule("Proposal bugdet rule");
end;
Any help would be highly appreciated.
Thanks,
Jeetendra.
--
View this message in context: http://drools.46999.n3.nabble.com/how-to-get-field-names-from-Rule-using-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 10 months
best rule for grouping planning entities?
by Michiel Vermandel
Hi,
I need to group a number of entities together and I'm not sure if my rule is optimal.
My planning entities represent maintenance tasks on airplanes.
Every planning entity is a discreet task (check tires, refuel, check engines...) but the maintenance of an airplane exists of a number of these tasks and they need to be grouped together.
Every task has a duration depending on its type (checking engine takes longer than checking tires).
The optimal solution is that all tasks of a maintenance are in the smallest amount of time (time between start of first task till end of last task).
Though, the smaller the better, at least all tasks should be sequential (without gaps between the tasks).
Dependencies on the tasks are availability of the plain, availability of the technicians...
(The rules beneath only check that the tasks are chained together, not (yet) that the time span is minimal => I thought to make a soft-constraint for that).
First I had this rule:
rule "tasksInSameMaintenanceJobMustBeChained"
when
$task : Task( $jobId: jobId )
not ( Task( jobId== $jobId, id != $task.id, ($task.startPeriodId-1) <= endPeriodId && ($task.endPeriodId+1) >= startPeriodId ) )
then // we have a gap!
insertLogical(new IntConstraintOccurrence("tasksInSameMaintenanceJobMustBeChained", ConstraintType.NEGATIVE_HARD, Importance.chainedPeriod, $jobId, $task));
end
After adding this rule I started struggling with what I believe is to be a score trap.
After advice from Geoffrey and reading some more, I thought my rule suffered from having a penalty which did not change depending on the amount of spread of the tasks.
So I rewrote the task to:
(I have now put all MaintenanceJobs into the working memory and I created a Class TaskSet() which is capable of calculating the nr of periods between all tasks of a job = gapCount)
rule "tasksInSameMaintenanceJobMustBeChained"
when
$job: MaintenanceJob()
$taskset : TaskSet( gapCount > 0 )
from accumulate( $task : Task(jobId== $job.id),
init( TaskSet taskset = new TaskSet(); ),
action( taskset.addTask( $task ); ),
reverse( taskset.removeTask( $task ); ),
result( taskset ) );
then
insertLogical(new IntConstraintOccurrence("tasksInSameMaintenanceJobMustBeChained", ConstraintType.NEGATIVE_HARD, Importance.chainedPeriod * $taskset.getGapCount(), $job, $taskset));
end
I see a difference in score but still not optimal and terminated on time limit reached.
1) Is this rule as good as it can be? Or am I creating some issue here?
A Task (planning entity) has 3 different planning variables.
2) When I analyze the Trace logging I see that during the first steps the 3 variables are switched during moves, but then after a while only one of the 3 variables gets changed and the other variables of all tasks remain as they are.
Should I conclude something out of that?
This is my local search config:
<localSearch>
<termination>
<terminationCompositionStyle>OR</terminationCompositionStyle>
<maximumSecondsSpend>3600</maximumSecondsSpend>
<scoreAttained>0hard/0soft</scoreAttained>
</termination>
<unionMoveSelector>
<changeMoveSelector>
<valueSelector>
<!-- ** -->
<planningVariableName>role</planningVariableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<valueSelector>
<!-- entity var technician:who will execute the task -->
<planningVariableName>technician</planningVariableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<valueSelector>
<!-- entity var period: when will the plane get maintenance -->
<planningVariableName>period</planningVariableName>
</valueSelector>
</changeMoveSelector>
<swapMoveSelector>
</swapMoveSelector>
</unionMoveSelector>
<acceptor>
<!-- 3 => small amount of planning entities in unit test -->
<planningEntityTabuSize>3</planningEntityTabuSize>
</acceptor>
<forager>
<minimalAcceptedSelection>1000</minimalAcceptedSelection>
</forager>
</localSearch>
(**) entity var role: every maintenance job has one lead task (role == lead),
all other tasks in that job must have role = member. The technician
assigned to the lead task will file the maintenance report.
One of the constraints (checked in other rule) is that no technician should be lead-technician twice in a row on two sequential maintenance jobs.
Thanks in advance.
Michiel
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
11 years, 10 months
CustomSolverPhaseCommand throws The entity ... was never added to this ScoreDirector.
by Michiel Vermandel
Hi,
I am trying to use a CustomSolverPhaseCommand (SolutionInitializer) to analyze what happens if I start with a given configuration.
I get java.lang.IllegalArgumentException: The entity ({T= Inspect B747-XA2.I#0 [1->3] null null}) was never
added to this ScoreDirector.
If I keep the constructionHeuristic phase before the SolutionInitializer then it works, but if I remove the constructionHeuristic phase and thus start with my SolutionInitializerthen I get the exception.
I reduced my SolutionInitializer to a minmal but the issue remains.
What am I doing wrong?
This is my SolutionInitializer:
package planner.solution;
import org.drools.planner.core.phase.custom.CustomSolverPhaseCommand;
import org.drools.planner.core.score.Score;
import org.drools.planner.core.score.director.ScoreDirector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import planner.app.InspectionSchedule;
import planner.domain.Task;
public class SolutionInitializer implements CustomSolverPhaseCommand {
private Logger logger = LoggerFactory.getLogger(this.getClass());
public void changeWorkingSolution(ScoreDirector scoreDirector) {
InspectionSchedule schedule = (InspectionSchedule) scoreDirector.getWorkingSolution();
Task task = schedule.getTasks().get(0);
scoreDirector.beforeVariableChanged(task, "period");
task.setPeriod(schedule.getPeriods().get(0));
scoreDirector.afterVariableChanged(task, "period");
score = scoreDirector.calculateScore();
logger.debug("Score after custom: " + score);
}
}
planning configuration:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<environmentMode>DEBUG</environmentMode>
<!-- Domain model configuration -->
<solutionClass>be.axi.planner.app.InspectionSchedule</solutionClass>
<planningEntityClass>be.axi.planner.domain.Task</planningEntityClass>
<!-- Score configuration -->
<scoreDirectorFactory>
<scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>
<scoreDrl>/inspectionRules.drl</scoreDrl>
</scoreDirectorFactory>
<customSolverPhase>
<customSolverPhaseCommandClass>be.axi.planner.solution.SolutionInitializer</customSolverPhaseCommandClass>
</customSolverPhase>
<localSearch>
<termination>
<terminationCompositionStyle>OR</terminationCompositionStyle>
<maximumSecondsSpend>3600</maximumSecondsSpend>
<scoreAttained>0hard/0soft</scoreAttained>
</termination>
<unionMoveSelector>
<changeMoveSelector>
<valueSelector>
<planningVariableName>type</planningVariableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<valueSelector>
<planningVariableName>spector</planningVariableName>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<valueSelector>
<planningVariableName>period</planningVariableName>
</valueSelector>
</changeMoveSelector>
</unionMoveSelector>
<acceptor>
<planningEntityTabuSize>7</planningEntityTabuSize>
</acceptor>
<forager>
<minimalAcceptedSelection>1000</minimalAcceptedSelection>
</forager>
</localSearch>
</solver>
Stack trace:
java.lang.IllegalArgumentException: The entity ({T= Inspect B747-XA2.I#0 [1->3] null null}) was never added to this ScoreDirector.
at org.drools.planner.core.score.director.drools.DroolsScoreDirector.afterVariableChanged(DroolsScoreDirector.java:125)
at planner.solution.SolutionInitializer.changeWorkingSolution(SolutionInitializer2.java:24)
at org.drools.planner.core.phase.custom.DefaultCustomSolverPhase.solve(DefaultCustomSolverPhase.java:58)
at org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:155)
at planner.app.InspectionSchedule.solve(InspectionSchedule.java:192)
at planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:288)
at planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:298)
at planner.testcore.AbstractPlanningTestClass.solve(AbstractPlanningTestClass.java:315)
at planner.TaskGroupingTest.communitySuccess02(TaskGroupingTest.java:289)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Thanks,
Michiel
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
11 years, 10 months
Constraints over Lists
by Phani Saripalli
Hi, I have a query reg. writing constraints over lists.
Precisely heres what I m doing
//Imports
import java.util.List;
import java.util.Set;
import java.util.Arrays;
import java.util.ArrayList;
//My methods - functions
function boolean isDefined(Object ob) {
return ob != null;
}
function boolean neqq(List l1, List l2) {
return l1 != l2;
}
//List declaration
declare Project
@typesafe (false)
list1 : List
list2 : List
end
//Initial declaration rule
rule " Config rule "
agenda-group "Group Config"
dialect "mvel"
no-loop true
lock-on-active true
when
P : Project()
then
modify(P) {
list1 = new java.util.ArrayList(java.util.Arrays.asList(10, 15, 20, 25)),
list2 = new java.util.ArrayList(java.util.Arrays.asList(11, 2, 3, 4, 5,
10, 9, 8, 7))
};
update(P);
end
//Rule-constraint
rule "listEq1"
agenda-group "Group 2"
dialect "mvel"
no-loop true
lock-on-active true
when
P : Project( isDefined(P.list1)
&& neqq(P.list1, new java.util.ArrayList(java.util.Arrays.asList(1, 2, 3)))
)
then
System.out.println("Lists are not equal - 1");
end
//Rule - constraint 2
rule "listEq2"
agenda-group "Group 2"
dialect "mvel"
no-loop true
lock-on-active true
when
P : Project( isDefined(P.list1) && isDefined(P.list2)
&& neqq(P.list1, P.list2)
)
then
System.out.println("Lists are not equal - 2");
end
******************
If I remove the rule "listEq1", everything works fine, other it raises
several exceptions like
- Exception executing consequence for rule " Config rule "
- cannot invoke method asList
- cannot invoke method neqq
Can anyone tell me whats going on here, whats the reason for this.
Many thanks :)
Phani
--
View this message in context: http://drools.46999.n3.nabble.com/Constraints-over-Lists-tp4021715.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 10 months