【正文】
act = SelectActivity(schedule)。 } 2022/8/21 史忠植 高級(jí)人工智能 55 Algorithm Program void SolveProblem(CtSchedule* schedule){ // Solve the problem assuming constraints have been posted. CtActivity* act = SelectActivity(schedule)。 (IsMoreUgent(newActivity, bestActivity))) bestactivity = newActivity。 while((newactivity)) if((IsUnScheduled(newActivity)) amp。 //Creates an iterator to iterate on all activities. CtActivityIterator* iterator(schedule)。 else return CtFalse。 } 2022/8/21 史忠植 高級(jí)人工智能 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。 2022/8/21 史忠植 高級(jí)人工智能 52 Algorithm Program CtBoolean IsUnScheduled(CtActivity* act){ // Return true if act does not have a fixed start time. if (actgetStartVariable()isBound()) return CtFalse。 // To state that only cap (here 20220) is available prior to a // given date (here 15). ressetCapacityMax(0,date,cap)。 //To post a precedence constraint between act1 and act2. act2startsAfterEnd(act1,0)。 } 2022/8/21 史忠植 高級(jí)人工智能 46 ILOG Schedule Schedule CtSchedule class Global object: time original tineMin time horizon timeMax 2022/8/21 史忠植 高級(jí)人工智能 47 ILOG Schedule Resources CtResource CtDiscreteResource CtUnaryResource CtDiscreteEnergy CtStateResource 2022/8/21 史忠植 高級(jí)人工智能 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 史忠植 高級(jí)人工智能 49 Scheduling Problem Prices paid as tasks begin $1000 per day Availability: Day 0:$20220, Day 15: +$9000 2022/8/21 史忠植 高級(jí)人工智能 50 Constraints // To create a schedule with origin 0 and given horizon. CtSchedule* schedule = new CtSchedule(0, horizon)。 Search 2022/8/21 史忠植 高級(jí)人工智能 45 ILOG SOLVER CTGOALn: how to execute CTGOAL1(CtInstantiate, CtIntVar* x){ CtInt a = xchooseValue()。 Basic constraints: =, ?, ?, , , +, , *, /, subset, superset, union, intersection, member, boolean or, boolean and, boolean not, boolean xor, CtTell((x==0) || (y==0))。 6 Allocate memories for global variables. 2022/8/21 史忠植 高級(jí)人工智能 40 COPS 7 Interprte the program with the internal structures. 8 Constraint works are built up for Unsolved 9 constraints and variables. 10 while some constraints in the constraint works are triggered, 11 inteprete the triggered constraints. 12 } 2022/8/21 史忠植 高級(jí)人工智能 41 COPS Interpreter: 1 { 2 switch (constraint type) 3 case Constant: 4 return Constant: 5 case global variable: 6 interprete global variable: 7 case local variable or argument: 8 interprete local variable or argument: 9 case object