Re: [rules-users] Long pattern for Nurse Rostering
I regret, I can't reconstruct the requirements from these rules. There are too many parameters unknown to me. The idea to construct a fact for each of the 15 days seems to be OK, although I think that this need not be done in this explicit and in this somewhat circumstantial way. I suppose a ShiftType() from $pattern.getShiftTypes() would be suffucient, but then there's no information about the day offset in the ShiftType. The problem you are experiencing is that the index of an (array) list is readily available in procedural code, at least during the classic iterative access through the list (using for int i = ...). But this information is not really coupled with the element at the position. Whenever the index has a deeper meaning for the application, it ought to be part of the data, relieving the actual index from this burden. Hope this makes sense. -W On 11 August 2013 06:09, john poole jdpo...@gmail.com wrote: Thanks for the reply. The series of shifts that a Doctor works in my schedule is 15 days straight, but not the same Shift for each of those days. I ended up doing it like this, maybe it explains the requirements better. Its working, but it looks ugly. rule pattern15dayShiftAssignment when $pattern : Neuro15DaysPattern( $dayOfWeekFirst : getDayOfWeek(0), $shiftType0: getShiftType(0), $shiftType1: getShiftType(1), $shiftType2: getShiftType(2), $shiftType3: getShiftType(3), $shiftType4: getShiftType(4), $shiftType5: getShiftType(5), $shiftType6: getShiftType(6), $shiftType7: getShiftType(7), $shiftType8: getShiftType(8), $shiftType9: getShiftType(9), $shiftType10: getShiftType(10), $shiftType11: getShiftType(11), $shiftType12: getShiftType(12), $shiftType13: getShiftType(13), $shiftType14: getShiftType(14) ); then insertLogical( new PatternShiftAssignment($pattern, $shiftType1, 1) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType2, 2) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType3, 3) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType4, 4) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType5, 5) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType6, 6) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType7, 7) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType8, 8) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType9, 9) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType10, 10) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType11, 11) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType11, 11) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType12, 12) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType13, 13) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType14, 14) ); System.out.println( $pattern + + $shiftType14 ); end rule unwantedPatternNeuro15Days when $pattern : Neuro15DaysPattern($dayOfWeekFirst : getDayOfWeek(0), $shiftType0: getShiftType(0), $code : code); PatternShiftAssignment( pattern == $pattern, $shiftType : shiftType, $dayIndex: patternIndex) $shiftAssignment0 : ShiftAssignment($code == shiftDateDayIndex % 2, shiftType == $shiftType0, shiftDateDayOfWeek == $dayOfWeekFirst, $employee: employee, $shiftDateDayIndex0 : shiftDateDayIndex); $shiftassignment : ShiftAssignment( shiftType == $shiftType, shiftDateDayIndex == ($dayIndex+$shiftDateDayIndex0), $employee != employee ) then insertLogical(new IntConstraintOccurrence(unwantedPatternNeuro15Days, ConstraintType.NEGATIVE_SOFT, $pattern.getWeight(), $employee, $pattern, $dayIndex)); end -- View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432p4025444.html Sent from the Drools: User forum mailing list archive at
Re: [rules-users] Long pattern for Nurse Rostering
That does make sense. It sounds like I should be adding the facts as domain objects where the index is available instead of generating them during the solution. I was trying to reuse the existing ShiftType3DaysPattern class from the nursing example, but used more than I should have. The code I have is almost working, but it seems to create plateaus. I can give it a push by stopping the GUI, making some changes, and then restarting. So I'll add another rule to do that on it's own. I feel like I'm building a kludgy house of cards though. -- View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432p4025452.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] Long pattern for Nurse Rostering
Thanks for the reply. The series of shifts that a Doctor works in my schedule is 15 days straight, but not the same Shift for each of those days. I ended up doing it like this, maybe it explains the requirements better. Its working, but it looks ugly. rule pattern15dayShiftAssignment when $pattern : Neuro15DaysPattern( $dayOfWeekFirst : getDayOfWeek(0), $shiftType0: getShiftType(0), $shiftType1: getShiftType(1), $shiftType2: getShiftType(2), $shiftType3: getShiftType(3), $shiftType4: getShiftType(4), $shiftType5: getShiftType(5), $shiftType6: getShiftType(6), $shiftType7: getShiftType(7), $shiftType8: getShiftType(8), $shiftType9: getShiftType(9), $shiftType10: getShiftType(10), $shiftType11: getShiftType(11), $shiftType12: getShiftType(12), $shiftType13: getShiftType(13), $shiftType14: getShiftType(14) ); then insertLogical( new PatternShiftAssignment($pattern, $shiftType1, 1) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType2, 2) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType3, 3) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType4, 4) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType5, 5) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType6, 6) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType7, 7) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType8, 8) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType9, 9) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType10, 10) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType11, 11) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType11, 11) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType12, 12) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType13, 13) ); insertLogical( new PatternShiftAssignment($pattern, $shiftType14, 14) ); System.out.println( $pattern + + $shiftType14 ); end rule unwantedPatternNeuro15Days when $pattern : Neuro15DaysPattern($dayOfWeekFirst : getDayOfWeek(0), $shiftType0: getShiftType(0), $code : code); PatternShiftAssignment( pattern == $pattern, $shiftType : shiftType, $dayIndex: patternIndex) $shiftAssignment0 : ShiftAssignment($code == shiftDateDayIndex % 2, shiftType == $shiftType0, shiftDateDayOfWeek == $dayOfWeekFirst, $employee: employee, $shiftDateDayIndex0 : shiftDateDayIndex); $shiftassignment : ShiftAssignment( shiftType == $shiftType, shiftDateDayIndex == ($dayIndex+$shiftDateDayIndex0), $employee != employee ) then insertLogical(new IntConstraintOccurrence(unwantedPatternNeuro15Days, ConstraintType.NEGATIVE_SOFT, $pattern.getWeight(), $employee, $pattern, $dayIndex)); end -- View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432p4025444.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] Long pattern for Nurse Rostering
See for comments inline. On 09/08/2013, john poole jdpo...@gmail.com wrote: I'm trying to create a rule for a 15 day pattern. When the patterns uses the same shift for all 15 days, I do this: rule unWanted15DayPattern when $pattern : U15DayPattern( $numberOfDays : numberOfDays, This binding is never used. $shiftType : shiftType ) ShiftAssignment( shiftType == $shiftType, $employee : employee, $firstDayIndex : shiftDateDayIndex The constraint shiftDateDayIndex % 15 == 0 should be used here. (Principle: Avoid partial matches as early as possible.) ) ShiftDate( $firstDayIndex == dayIndex, dayIndex % 15 == 0) If the constraint is moved up: what is the purpose of this pattern? Is it necessary to make sure that there *is* a ShiftDate with a matching dayIndex? This won't work well, if there isn't, so I guess there always is a matching ShiftDate - and then the pattern is now useless. //Check for different employee working that shift in the next N days $shiftAssignment : ShiftAssignment( shiftType == $shiftType, employee != $employee, shiftDateDayIndex $firstDayIndex, shiftDateDayIndex $firstDayIndex + 15 ) then insertLogical(new IntConstraintOccurrence(unWanted15DayPattern, ConstraintType.NEGATIVE_SOFT, $pattern.getWeight(), $firstDayIndex)); end But I'm having a hard time figuring out how to do it with different shiftTypes for each day, because it means having to use a loop. Not necessarily. It depends how a U15DayPattern with more than one shiftType in these days is represented. (Or what, exactly, do you mean by different shiftTypes for each day?) A little more explanation about the data model is indicated... -W Not sure if that makes sense, but it anyone has used a long pattern that stores items in a list/array I'd love to hear how they did it. -- View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432.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 mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Long pattern for Nurse Rostering
I'm trying to create a rule for a 15 day pattern. When the patterns uses the same shift for all 15 days, I do this: rule unWanted15DayPattern when $pattern : U15DayPattern( $numberOfDays : numberOfDays, $shiftType : shiftType ) ShiftAssignment( shiftType == $shiftType, $employee : employee, $firstDayIndex : shiftDateDayIndex ) ShiftDate( $firstDayIndex == dayIndex, dayIndex % 15 == 0) //Check for different employee working that shift in the next N days $shiftAssignment : ShiftAssignment( shiftType == $shiftType, employee != $employee, shiftDateDayIndex $firstDayIndex, shiftDateDayIndex $firstDayIndex + 15 ) then insertLogical(new IntConstraintOccurrence(unWanted15DayPattern, ConstraintType.NEGATIVE_SOFT, $pattern.getWeight(), $firstDayIndex)); end But I'm having a hard time figuring out how to do it with different shiftTypes for each day, because it means having to use a loop. Not sure if that makes sense, but it anyone has used a long pattern that stores items in a list/array I'd love to hear how they did it. -- View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432.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