<html><body><div style="color:#000; background-color:#fff; font-family:tahoma, new york, times, serif;font-size:10pt"><div><span>I did not really start on one example. I have scrolled through several to try to figure out how to do it, then started from scratch for the POJO's and Rules. <br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span>The config file was copies from one of the examples because it contained too many things that were hard to get right in the beginning.</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span>I know that is a risk but I needed to start somewhere.</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style:
normal;"><br><span></span></div><br><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span>3) What does "The workingMemory has 2 ConstraintOccurrence(s) in excess:" really mean?</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"> - Are the constraints there more than once?</div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"> - has this something to do with the equals and hashcode (which I did implement (see below))?</div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color:
rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab"> </span><span>About the compensation action: is it already available on 5.4.0 final? Should I try that?</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span>4) I have been looking to the equals and hashcode, though found many examples that implement solutionEquals and solutionHashcode instead.</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> Currently I implemented them like
this:</span></div><br><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> @Override<br> public int hashCode() {<br> return id.hashCode(); //(*)<br> }<br><br> @Override<br> public boolean equals(Object o) {<br> if (this == o) {<br> return true;<br> }<br> if (id == null || !(o instanceof MaintenanceTask)) {<br> return false;<br> } else {<br> MaintenanceTask other = (MaintenanceTask) o;<br>
return id.equals(other.id);<br> }<br> }</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> (*) id
is a String property which is passed into the entity object through the
constructor and upon cloning it is passed from the clone source to the
clone target:</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"> <span class="tab"> </span> public MaintenanceTask clone() {<br> <span class="tab"> </span>System.out.println("Cloning task " + id);<br> <span class="tab"> </span>MaintenanceTask clone = new MaintenanceTask(job, id);<br> <span class="tab"> </span>clone.period = this.period;<br> <span class="tab"> </span>clone.technician = this.technician;<br> <span class="tab"> </span>return clone;<br> <span class="tab">
</span>}<br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> <br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> I am still confused about:<br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> - Which ones do I need to implement (equals or solutionEquals, ...)?</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif;
background-color: transparent; font-style: normal;"><span> - Should an entity and a cloned entity have the same result for both equals and hashcode? (I guess so)</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> - Should only the entity objects have such implementations? (Planning variables are never cloned, right?)<br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: tahoma,new york,times,serif; background-color: transparent; font-style: normal;"><span> </span><br></div><div> </div><div>-----------------<br>http://www.codessentials.com - Your essential software, for free!<br>Follow us at http://twitter.com/#!/Codessentials<br></div> <div style="font-family: tahoma, new york, times, serif; font-size: 10pt;"> <div style="font-family: times new roman, new
york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Geoffrey De Smet <ge0ffrey.spam@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Rules Users List <rules-users@lists.jboss.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, September 3, 2012 10:44 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] Best model for planning? technicians, airplanes and shifts => insertLogical problems<br> </font> </div> <br>
Op 03-09-12 10:21, Michiel Vermandel schreef:<br>> Hi Geoffrey,<br>><br>> Thanks for the support so far.<br>> I understand that you do not provide full support on this level.<br>> Though I have the feeling that this is really<br>> - a very basic solution setup<br>> - a beginners-mistake and since I'm looking into it now for about 3 days<br>> (since I started with planner) it seems to be not obvious to find for a<br>> beginner.<br>> So I was trying my luck in offering the code.<br>> It could be an opportunity to enrich the documentation ;-) ;-)<br><br>Good point, the score corruption problem is often a beginner problem and <br>it's a PITA. I 'll write some more docs about.<br><br>Do note that your 3 day implementation should be able to scale out to <br>10000 planes pretty easily, so hang in there :)<br>I fear you might have started copying from the wrong example nqueens (if <br>you did that) :/ Nurse rostering is a far
more similar to this kind of <br>problem. I am not sure which example to promote in the docs: the nqueens <br>is simple enough to explain things on, but it's too simple to copy from <br>for real world stuff :/ Feedback welcome.<br><br>><br>><br>> Ok,<br>><br>> 1) adding the $t2 results in the same sort of exception, only<br>> planningEntity seems different:<br>><br>> with insertLogical(new<br>> UnweightedConstraintOccurrence("tasksInSameJobMustBeInSamePeriod", $t1,<br>> $t2));<br>><br>> Exception in thread "main" java.lang.IllegalStateException: Score<br>> corruption: the workingScore (-2) is not the uncorruptedScore (0):<br>> The workingMemory has 2 ConstraintOccurrence(s) in excess:<br>> tasksInSameJobMustBeInSamePeriod/NEGATIVE_HARD:[Maintenance of<br>> Boeing 737 - PJ23.I#1 73111693, Maintenance of Boeing 737 - PJ23.I#2<br>> 427578167]<br>>
tasksInSameJobMustBeInSamePeriod/NEGATIVE_HARD:[Maintenance of<br>> Boeing 737 - PJ23.I#2 427578167, Maintenance of Boeing 737 - PJ23.I#1<br>> 73111693]<br>> Check the score rules who created those ConstraintOccurrences. Verify<br>> that each ConstraintOccurrence's causes and weight is correct.<br>> at<br>> org.drools.planner.core.score.director.AbstractScoreDirector.assertWorkingScore(AbstractScoreDirector.java:101)<br>> at<br>> org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.doMove(DefaultGreedyDecider.java:110)<br>> at<br>> org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.decideNextStep(DefaultGreedyDecider.java:78)<br>> at<br>>
org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.solve(DefaultGreedyFitSolverPhase.java:63)<br>> at<br>> org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:183)<br>> at<br>> org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:151)<br>> at<br>> be.axi.planner.domain.MaintenancePlanning.main(MaintenancePlanning.java:27)<br>><br>> with insertLogical(new<br>> UnweightedConstraintOccurrence("tasksInSameJobMustBeInSamePeriod", $t1));<br>><br>> Exception in thread "main" java.lang.IllegalStateException: Score<br>> corruption: the workingScore (-2) is not the uncorruptedScore (0):<br>> The workingMemory has 2 ConstraintOccurrence(s) in excess:<br>> tasksInSameJobMustBeInSamePeriod/NEGATIVE_HARD:[Maintenance of<br>> Airbus A350 - XJ34.I#2
778813475]<br>> tasksInSameJobMustBeInSamePeriod/NEGATIVE_HARD:[Maintenance of<br>> Airbus A350 - XJ34.I#0 225744121]<br>> Check the score rules who created those ConstraintOccurrences. Verify<br>> that each ConstraintOccurrence's causes and weight is correct.<br>> at<br>> org.drools.planner.core.score.director.AbstractScoreDirector.assertWorkingScore(AbstractScoreDirector.java:101)<br>> at<br>> org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.doMove(DefaultGreedyDecider.java:110)<br>> at<br>> org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.decideNextStep(DefaultGreedyDecider.java:78)<br>> at<br>> org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.solve(DefaultGreedyFitSolverPhase.java:63)<br>>
at<br>> org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:183)<br>> at<br>> org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:151)<br>> at<br>> be.axi.planner.domain.MaintenancePlanning.main(MaintenancePlanning.java:27)<br>><br>><br>> 2) You suggested to replace UnweightedConstraintOccurrence with<br>> IntConstraintOccurrence. I will.<br>> UnweightedConstraintOccurrence is used in the very basic Queens example<br>> though...<br><br>Yep, my mistake.<br><br>><br>> 3) Where is the best place to read about what insertLogical and<br>> IntConstraintOccurrence really do?<br>> What is the purpose of the Cause -objects, which should be passed?<br>> => where is the best place to find explanation about this?<br>> (<a href="http://docs.jboss.org/drools/release/5.4.0.Final/drools-planner-docs/html_single/"
target="_blank">http://docs.jboss.org/drools/release/5.4.0.Final/drools-planner-docs/html_single/</a><br>> doesn't really enlighten me on that part)<br><br>Look for "insertLogical" in the Drools Expert guide:<br> <br><a href="http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html_single/index.html" target="_blank">http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html_single/index.html</a><br><br>When rules do an insertLogical of an object A, it's discarded if another <br>object B in the WorkingMemory equals object A (through equals() and <br>through hashcode()). Because the ConstraintOccurrences need to be unique <br>so they aren't discarded, they ruleId, constraintType and causes are <br>used for equals()/hashcode().<br><br>Future work: "compensation action"<br>Recently, drools introduced something called "compensation action",<br>which can probably replace the use insertLogical(ConstraintOccurrence) <br>and make
the causes parameter obsolete.<br>It's also faster.<br>My first experiments look very promising, but I haven't got time yet to <br>experiment with it on all examples and make it easy for users to use.<br><br>It would allow us to do something like this in the then part of a rule:<br> hardAndSoftScoreHelper.addHardScore(-5);<br>or<br> hardAndSoftScoreHelper.addSoftScore(- $sum);<br>or<br> simpleScoreHelper.addScore(-7);<br><br>No need for causes, insertLogicals, no equals/hashcode() worries, much <br>more flexible, ...<br><br><br>4) Does your MaintenanceTask implement equals()/hashcode() other than <br>Object's original implementation?<br><br><br>><br>> Thanks in advance.<br>><br><br>yw<br><br>_______________________________________________<br>rules-users mailing list<br><a ymailto="mailto:rules-users@lists.jboss.org" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a
href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br><br> </div> </div> </div></body></html>