【正文】
。 } 2022/8/21 史忠植 高級人工智能 46 ILOG Schedule Schedule CtSchedule class Global object: time original tineMin time horizon timeMax 2022/8/21 史忠植 高級人工智能 47 ILOG Schedule Resources CtResource CtDiscreteResource CtUnaryResource CtDiscreteEnergy CtStateResource 2022/8/21 史忠植 高級人工智能 48 ILOG Schedule Activities CtActivity class CtIntervalActivity An activity is defined by its start time, end time and duration Activities require, provide, consume and produce resources 2022/8/21 史忠植 高級人工智能 49 Scheduling Problem Prices paid as tasks begin $1000 per day Availability: Day 0:$20220, Day 15: +$9000 2022/8/21 史忠植 高級人工智能 50 Constraints // To create a schedule with origin 0 and given horizon. CtSchedule* schedule = new CtSchedule(0, horizon)。 // To create an activity with the given duration. CtIntervalActivity* act = new CtIntervalActivity(schedule, duration)。 //To post a precedence constraint between act1 and act2. act2startsAfterEnd(act1,0)。 2022/8/21 史忠植 高級人工智能 51 Constraints //To create a total budget of limited capacity (here 29000). CtDiscreteResource* res = new CtDiscreteResource(schedule, CtRequiredResource, capacity)。 // To state that only cap (here 20220) is available prior to a // given date (here 15). ressetCapacityMax(0,date,cap)。 // To state that an activity act consumes c units of res. actconsumes(res, c)。 2022/8/21 史忠植 高級人工智能 52 Algorithm Program CtBoolean IsUnScheduled(CtActivity* act){ // Return true if act does not have a fixed start time. if (actgetStartVariable()isBound()) return CtFalse。 else return CtTrue。 } 2022/8/21 史忠植 高級人工智能 53 Algorithm Program CtBoolean IsMoreUrgent(CtActivity* act1, CtActivity* act2){ // Returns true if act1 is more urgent than act2. // Returns true if act2 is unbound (==0) if (act2 == 0) return CtTrue。 else if (act1getStartMax() act2getStartMax()) return CtTrue。 else return CtFalse。 } 2022/8/21 史忠植 高級人工智能 54 Algorithm Program CtActivity* SelectActivity(CtSchedule* schedule){ // Returns the unscheduled activity with the smallest latest // statrt time. Returns 0 if all activities are scheduled. CtActivity* bestActivity = 0。 //Creates an iterator to iterate on all activities. CtActivityIterator* iterator(schedule)。 CtActivity* newActivity。 while((newactivity)) if((IsUnScheduled(newActivity)) amp。amp。 (IsMoreUgent(newActivity, bestActivity))) bestactivity = newActivity。 return bestActivity。 } 2022/8/21 史忠植 高級人工智能 55 Algorithm Program void SolveProblem(CtSchedule* schedule){ // Solve the problem assuming constraints have been posted. CtActivity* act = SelectActivity(schedule)。 while (act !=0) { actsetStartTime(actgetStartMin())。 act = SelectActivity(schedule)。 } } 2022/8/21 史忠植 高級人工智能 56 Optimal Solution to the Scheduling Problem