[rules-users] [planner] Scheduling events with varying durations - corrupted score

Geoffrey De Smet ge0ffrey.spam at gmail.com
Tue Jan 3 05:15:33 EST 2012



Op 02-01-12 22:07, nickels schreef:
> Hi, I am relatively new to the Drools space and I am working on a project
> utilizing Drools planner (5.4.0.Beta1) for use in scheduling events. I have
> a set of events of varying duration and a set of possible venues for the
> events with varying availability. I read some previous comments relating to
> similar problems and it seems that the best approach is to create time slots
> for each of the venues and then assign the events to time slots based on the
> availability similar to how the CloudBalancing example assigns tasks to
> machines. The difference is that I need to know the actual start/end time of
> each event for a given time slot during planning in order to make sure that
> an event is not scheduled at the same time as another event from a previous
> run of the solver for another schedule.
>
> Here is how the problem is modeled (simplified to the important parts):
>
> - Event (Planning entity) {venueTimeSlot, startDateTime, endDateTime,
> duration}
> - VenueTimeSlot (Planning Variable) {Venue, startDateTime, endDateTime,
> duration}
> - PreviousEvent (Constraint) {Venue, startDateTime, endDateTime}
>
> And the pertinent rules:
>
> // Rule that makes sure the time slot can fit the number of events scheduled
> in it.
> rule "minimalDurationTotal"
>      when
>          $venueTimeSlot : VenueTimeSlot($duration : duration)
>          $minimalDurationTotal : Number(intValue>  $duration) from
> accumulate(
>              Event(venueTimeSlot == $venueTimeSlot, $minimalDuration :
> totalDuration),
>              sum($minimalDuration)
>          )
>      then
>      	insertLogical(new IntConstraintOccurrence("minimalDurationTotal",
> ConstraintType.NEGATIVE_HARD, $minimalDurationTotal.intValue() - $duration,
> $venueTimeSlot));
> end
>
> // Rule that checks for any previous events that were already scheduled for
> this venue
> rule "previousEventConflict"
> 	when
>     		$e : Event($venue:venueTimeSlot.venue)
> 	   		exists PreviousEvent(venue == $venue, startDateTime<= $e.endDateTime,
> $e.startDateTime<= endDateTime)
>     	then
>     		insertLogical(new IntConstraintOccurrence("previousEventConflict",
> ConstraintType.NEGATIVE_HARD, 1, $e));
> end
>
>
> // Rule that calculates the start/end date time for the event based on the
> events in the time slot
> rule "updateEventDateTime"
>     salience 10
> 	when
> 		$e : Event()
> 		$eventList : LinkedList() from collect(
> 			Event(venueTimeSlot == $e.venueTimeSlot)
> 		)
> 	then
> 		$e.updateDateFromEventList($eventList);  -->  Loops through the events and
> sets the startDateTime
(1) That's probably bad. You'd need to signal to the working memory that 
$e has been modified, but that would make planner slower as it breaks 
delta score calculation.
Read the section "delta (incremental) score calculation" in the Planner 
manual first.

Normally, a Timeslot has a fixed starting time that doesn't change 
during planning.
When an event gets assigned to that timeslot, it's starting time is 
easy: event.getTimeslotStartingTime() -> 
event.getTimeslot().getStartingTime()
> end
>
> Ok, so this rule that updates the date time is where I am not sure about, I
> get an error about score corruption during the construction heuristic phase.
>
> java.lang.IllegalStateException: Score corruption: the presumedScore
> (0hard/0soft) is not the uncorruptedScore (-1hard/0soft):
>    The workingMemory has 0 ConstraintOccurrence(s) lacking:
>      previousEventConflict/NEGATIVE_HARD:[Event 75]=1
That means that the previousEventConflict part of a score isn't correct 
after incremental score calculation, probably because of (1)'s lack of 
WM.modify($e).
>    Check the score rules who created those ConstraintOccurrences. Verify that
> each ConstraintOccurrence's causes and weight is correct.
> Problem is I don't know what order the events were "added to the time slot"
> so every time I call the updateDateFromEventList method the list of events
> may be in a different order and therefore change the actual time they occur.
> How is it that I set the position of the event when the time slot is set by
> the construction heuristic? Or is there a better way altogether to model
> this?
>
> Any insight you can provide would be appreciated.
>
> Best Regards,
> Nick
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Scheduling-events-with-varying-durations-corrupted-score-tp3627595p3627595.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>

-- 
With kind regards,
Geoffrey De Smet





More information about the rules-users mailing list