Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory = shadow proxies problems?

2011-12-07 Thread guyramirez
Adding to your analysis:
when looking at the Building ConstraintOccurrence summary for the presumed
working memory we can see what is wrong (the cause includes the collection
of matching ShiftAssignment to IntervalRequirement). Also keep in mind that
there is only one instance of a ShiftAssignment (starting at 100 and going
from 1 to 4 in duration), versus 4 instances of IntervalRequirement
(interval # from 100 to 103):

2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
101, position id: 1, staffingRequired: 2, [ShiftAssignment: emp. id: 10 [st:
100, dur: 1]]]=1) 

Here it matched wrongly the ShiftAssignment. Nothink should have been
matched since the ShiftAssignment covers only interval 100. Weight should
have been 2 instead of 1.



2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
100, position id: 1, staffingRequired: 2, [ShiftAssignment: emp. id: 10 [st:
100, dur: 1], ShiftAssignment: emp. id: 10 [st: 100, dur: 1]]]=0) 

Here that's the oddest. The ShiftAssignment should be matched, however the
cause shows that it matched *twice* the same and only one ShiftAdjustment.
Weight should have been 1 instead of 0.

Maybe this odd behavior would ring some bells?

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3567517.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory = shadow proxies problems?

2011-12-07 Thread guyramirez
Yes I am getting the same results with your recommended rule.

Also I wrote a Drools program that does not use Planner but instead performs
the initial insert of the ShiftAdjustment, then the 3 updates with the
firing of the rules at each insert/update, all in sequence, with the display
of the score after each firing (so no use of the Solution class). And I get
exactly the same erroneous results.

I agree with you, it could be in the hashCode and/or equals methods. I will
check them again against the examples. I have done it so many times already.
:)

 It's odd indeed that the tmp working memory is incorrect, instead of the 
real one. 
The real working memory is created everytime from scratch to check against
the presumed score, right? Somehow the update of a fact (planning entity in
this case) does not yield the same result as a retract and then insert (or
plain insert in the case of the real working memory).

We looked at the planning entity code earlier. Here is some code for the
IntervalRequirement class that is being used to match against the
ShiftAssignment:

public class IntervalRequirement implements ComparableIntervalRequirement
{
private int dayAppliesTo;
private int interval;
private int intervalMinutes;
private Position position;
private int staffingRequired;

@Override
public int compareTo(IntervalRequirement other) {
return this.interval - other.interval;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof IntervalRequirement) {
IntervalRequirement other = (IntervalRequirement) o;
return new EqualsBuilder()
.append(this.interval, other.interval)
.append(this.position, other.position)
.append(this.staffingRequired, other.staffingRequired)
.isEquals();
} else {
return false;
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.append(getClass())
.append(this.interval)
.append(this.position)
   
.append(this.staffingRequired)
.toHashCode();
}
...
}

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3567779.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory = shadow proxies problems?

2011-12-06 Thread guyramirez
Patrik: thx for your feedback. Did you get the chance to run your rule using
Expert only without Planner? I just did that (wrote a test program to change
my planning entity values and update the StatefulKnowledgeSession few times
in row) and I came up with the same currupted result.

Geoffrey: thx for looking at my stuff. I still have the same issue with the
rule modified not to use collect (that's how it was actually written
originally. I later used Collect to be able to add the collection itself as
a cause to the logical insert, thinking that would solve my issue).

I am still wondering: the nurse example is far more complicated that what I
am trying to accomplish with my simple test case, and still it runs fine.

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3566474.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory = shadow proxies problems?

2011-12-05 Thread guyramirez
Still the same issue, starting with the construction heuristic phase. Please
let me know if you need more explanations in what I am trying to do.

Here is the error. Please note that there is only one planning entity
(ShiftAssignment) object instance in this test.

Total Staffing required: 8
2011-12-05 22:21:49,627 [main] INFO  Solver started: time spend (0), score
(null), new best score (null), random seed (0).
ShiftAssignment: emp. id: 10 [st: 100, dur: 3]
ShiftAssignment: emp. id: 10 [st: 100, dur: 2]
ShiftAssignment: emp. id: 10 [st: 100, dur: 4]
ShiftAssignment: emp. id: 10 [st: 100, dur: 1]
2011-12-05 22:21:49,678 [main] TRACE Building ConstraintOccurrence summary
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
101, position id: 1, staffingRequired: 2, [ShiftAssignment: emp. id: 10 [st:
100, dur: 1]]]=1)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
103, position id: 1, staffingRequired: 2, []]=2)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
102, position id: 1, staffingRequired: 2, []]=2)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
100, position id: 1, staffingRequired: 2, [ShiftAssignment: emp. id: 10 [st:
100, dur: 1], ShiftAssignment: emp. id: 10 [st: 100, dur: 1]]]=0)
2011-12-05 22:21:49,678 [main] TRACE Building ConstraintOccurrence summary
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
101, position id: 1, staffingRequired: 2, []]=2)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
103, position id: 1, staffingRequired: 2, []]=2)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
100, position id: 1, staffingRequired: 2, [ShiftAssignment: emp. id: 10 [st:
100, dur: 1]]]=1)
2011-12-05 22:21:49,678 [main] TRACE Adding ConstraintOccurrence
(intervalRequirementCovered/NEGATIVE_HARD:[IntervalRequirement: interval:
102, position id: 1, staffingRequired: 2, []]=2)
Exception in thread main java.lang.IllegalStateException: The
presumedScore (-5hard/-1soft) is corrupted because it is not the realScore 
(-7hard/-1soft).
Presumed workingMemory:
  Score rule (intervalRequirementCovered) has count (4) and weight total
(5).
Real workingMemory:
  Score rule (intervalRequirementCovered) has count (4) and weight total
(7).

at
org.drools.planner.core.solution.director.DefaultSolutionDirector.assertWorkingScore(DefaultSolutionDirector.java:157)
at
org.drools.planner.core.solver.DefaultSolverScope.assertWorkingScore(DefaultSolverScope.java:105)
at
org.drools.planner.core.phase.AbstractSolverPhaseScope.assertWorkingScore(AbstractSolverPhaseScope.java:132)
at
org.drools.planner.core.constructionheuristic.greedyFit.decider.DefaultGreedyDecider.decideNextStep(DefaultGreedyDecider.java:65)
at
org.drools.planner.core.constructionheuristic.greedyFit.DefaultGreedyFitSolverPhase.solve(DefaultGreedyFitSolverPhase.java:62)
at
org.drools.planner.core.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:166)
at
org.drools.planner.core.solver.DefaultSolver.solve(DefaultSolver.java:138)
at 
com.lfsoscience.planner.LfsoPlannerMain.execute(LfsoPlannerMain.java:36)
at com.lfsoscience.planner.LfsoPlannerMain.main(LfsoPlannerMain.java:27)



The drl:
rule intervalRequirementCovered
when
$intervalReq : IntervalRequirement($interval : interval, 
$position :
position, $staffingRequired : staffingRequired)
$matchingShiftAssignments : ArrayList( size = $staffingRequired )
from 
collect ( ShiftAssignment(shiftStartTime = $interval,
shiftEndTime  $interval, position == $position) )
then 
#actions
insertLogical(new 
IntConstraintOccurrence(intervalRequirementCovered,
ConstraintType.NEGATIVE_HARD,
$staffingRequired - 
$matchingShiftAssignments.size(),
$intervalReq, 
$matchingShiftAssignments));
end
rule hardConstraintsBroken
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight), sum($weight)
)
then
scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());
end
rule 

Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory = shadow proxies problems?

2011-12-02 Thread guyramirez
 WorkingMemory.getClass().getPackage().getSystem*Domain() or something 
similar
 which should output something like drools-core-5.3.0.Final.jar

I got:
this.workingMemory.getClass().getPackage()
 (java.lang.Package) package org.drools.reteoo, Drools :: Core, version
5.3.0.Final


 - In Drools Expert, there are 2 classes named WorkingMemory and also 2 
 named FactHandle.
 Planner 5.3 is still using those in the org.drools (which are the older 
 ones), not those in org.drools.runtime.rule (which are the newer ones).
 Do a global search for import org.drools.runtime.rule. That should 
give no results.

I got no results back but I ran the search in JBoss Studio against the
binaries. Not sure this search should work.
Yes I can see the two classed when I search for the types in the IDE.

Anything else I could check?

I have been playing with the hashCode implementations of the facts and
planning entity but still no luck. I am assuming Expert is very dependant of
the hash code results. For an update of a fact in the working memory, would
Expert expect the hash to change between the original fact and the new
updated one?

Guy 

 

 

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3556532.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory

2011-12-01 Thread guyramirez
 Verify that IntervalRequirement doesn't change during planning. 
It does not change as IntervalRequirement is immutable.

 Are you using drools-planner-core 5.3.0.Final with drools-core 5.3.0.Final
 and drools-compiler 5.3.0.Final? 
Yes using 5.3.0.Final from the Planner 5.3 download location.

After your suggestions, here my complete drl (you will probably recognize
some of your own code :)):

rule intervalRequirementCovered
when
$intervalReq : IntervalRequirement($interval : interval, 
$position :
position, $staffingRequired : staffingRequired)
$matchingShiftAssignmentsCount : Number(intValue()  
$staffingRequired)
from accumulate(
$matchingShiftAssignments : ShiftAssignment(shiftStartTime =
$interval
, 
shiftEndTime  $interval, position == $position)
, 
count($matchingShiftAssignments)
)
then 
#actions
insertLogical(new 
IntConstraintOccurrence(intervalRequirementCovered,
ConstraintType.NEGATIVE_HARD,

$matchingShiftAssignmentsCount.intValue() - $staffingRequired,
$intervalReq));
end


rule hardConstraintsBroken
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight), sum($weight)
)
then
scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());
end


Unfortunately still having the same issue, that is, updates on my planning
entity are not reflected in the engine. Drools Experts mentions the
following when updating facts:
The update() method can only be used with objects that have shadow proxies
turned on.
Not sure how to check about those shadow proxies, but is it something worth
looking into?

Thanks,
Guy

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3553818.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory

2011-11-30 Thread guyramirez
Thank you for the pointers.

My understanding is that since it is failing on the construction heuristic
(move/unmove not used at this point) then the issue would be in the score
rule?

Here is my only score rule (ShiftAssignment is the only planning entity with
shiftStartTime/shiftEndTime changing). Maybe something would jump at you:

rule intervalRequirementCovered
when
$intervalReq : IntervalRequirement($interval : interval, 
$position :
position, $staffingRequired : staffingRequired)
$matchingShiftAssignmentsCount : Number() from accumulate(
$matchingShiftAssignments : ShiftAssignment(shiftStartTime =
$interval, shiftEndTime  $interval, position == $position),
count($matchingShiftAssignments)
)
then 
insertLogical(new 
IntConstraintOccurrence(intervalRequirementCovered,
ConstraintType.NEGATIVE_HARD,

Math.min($matchingShiftAssignmentsCount.intValue() - $staffingRequired,
0), $intervalReq, $position));
end

Thanks,
Guy

--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3550542.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Planner 5.3.Final - presumedScore is corrupted when using update on the rules working memory

2011-11-29 Thread guyramirez
I am looking into Planner for a schedule assignment business case.

I created a move factory, got the local search phase set up and quicly ran
into a presumedScore is corrupted because it is not the realScore error.
As a work around, I changed my Move::doMove(..) implementation to retract
then insert rather than update the new updated planning entity and the
issue went away.

Then I worked on setting a construction heuristic and I again ran into the
same error. By applying a local code patch to the
PlanningValueWalker::changeWorkingValue(..) method to also retract and
insert rather than update also fixed the issue.

I also tried to correctly implement the hashCode() and equals(..) methods on
my planning entity (as mentioned in Drools Expert documentation) as well as
use the default implementation of those methods (as in the nurse rostering
example) with the same unsuccessful results.

I must mention than I am able to run the nurse rostering example without any
issues.

Could someone maybe point me to the right direction on why update does not
work for me? I can provide detailed information if needed.

Thanks,
Guy




--
View this message in context: 
http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corrupted-when-using-update-on-the-rules-working-memory-tp3546932p3546932.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users