% by Roman Bartak, 2015 import planner. solve_all => all(Benches),nl, foreach(Bench in Benches) write(Bench), print(": "), once(call(Bench)) end. pddl(IFacts,GFacts) => initialize_table, Counters = [Fact : Fact in IFacts, Fact = $next(_,_)], Planes = sort([{[],Level,City,Dest} : $fuel_level(Plane,Level) in IFacts, (member($at(Plane,City),IFacts), dest(Plane,Dest,GFacts))]), Persons = sort([[City|Dest] : $at(Person,City) in IFacts, (not member($fuel_level(Person,_),IFacts), dest(Person,Dest,GFacts), Dest != City, Dest != none)]), % writeln(persons=Persons), cl_facts(Counters,[]), % plan({Persons,Planes},99999999,Plan,PlanCost), best_plan_unbounded({Persons,Planes},99999999,Plan,PlanCost), % writeln(plan=Plan), % foreach(P in Plan) writeln(P) end, writeln(cost=PlanCost). dest(Obj,Dest,GFacts), member($at(Obj,Dest),GFacts) => true. dest(_Obj,Dest,_GFacts) => Dest = none. % lower bound for the number of actions to reach goal dist2goal(Persons) = length(remove_dups([Dest : [_Dest] in Persons])) % number of flights + 2*length(Persons). % number of boardings and debarkings % finish when all people are moved and planes are in destinations final({Persons,Planes}), Persons = [], % all persons are transfered foreach({Load,_Level,City,Dest} in Planes) Load = [], (City=Dest ; Dest=none) end => true. % DEBARK person in his/her destination action({Persons,Planes},NextState,Action,ActionCost), select({Load,Level,City,PDest},Planes,Planes1), select(City,Load,Load1) => Action = $debark(City), ActionCost = 1, NextState = {Persons,insert_ordered(Planes1,{Load1,Level,City,PDest})}, dist2goal(Persons) < current_resource(). % BOARD person action({Persons,Planes},NextState,Action,ActionCost), select([City|Dest],Persons,Persons1), select({Load,Level,City,PDest},Planes,Planes1) ?=> Action = $board(City), ActionCost = 1, NextState = {Persons1,insert_ordered(Planes1,{insert_ordered(Load,Dest),Level,City,PDest})}, 1+dist2goal(Persons1) < current_resource(). % FLY to city to debark some person, to board some person or to plane destination action({Persons,Planes},NextState,Action,ActionCost), select({Load,Level,City,PDest},Planes,Planes1), next(NextLevel,Level), (member(NextCity,Load) ; (member([NextCity|_],Persons) ; PDest!=none, NextCity=PDest), NextCity!=City) ?=> Action = $fly(City,NextCity), ActionCost = 1, NextState = {Persons,insert_ordered(Planes1,{Load,NextLevel,NextCity,PDest})}, dist2goal(Persons) < current_resource(). % ZOOM to city to debark some person, to board some person or to plane destination action({Persons,Planes},NextState,Action,ActionCost), select({Load,Level,City,PDest},Planes,Planes1), next(Level1,Level), next(NextLevel,Level1), (member(NextCity,Load) ; (member([NextCity|_],Persons) ; PDest!=none, NextCity=PDest), NextCity!=City) ?=> Action = $zoom(City,NextCity), ActionCost = 1, NextState = {Persons,insert_ordered(Planes1,{Load,NextLevel,NextCity,PDest})}, dist2goal(Persons) < current_resource(). % REFUEL only if necessary action({Persons,Planes},NextState,Action,ActionCost), select({Load,Level,City,PDest},Planes,Planes1), next(Level,NextLevel) ?=> Action = $refuel(City), ActionCost = 1, NextState = {Persons,insert_ordered(Planes1,{Load,NextLevel,City,PDest})}, dist2goal(Persons) < current_resource(). % DEBARK person not in his/her destination action({Persons,Planes},NextState,Action,ActionCost), select({Load,Level,City,PDest},Planes,Planes1), select(PCity,Load,Load1), City != PCity ?=> Action = $debark(City), ActionCost = 1, NextState = {insert_ordered(Persons,[City|PCity]),insert_ordered(Planes1,{Load1,Level,City,PDest})}, dist2goal([[City|PCity]|Persons]) < current_resource(). all(Benches) => Benches=[pfile1,pfile2,pfile3,pfile4,pfile5,pfile6,pfile7,pfile8,pfile9,pfile10,pfile11,pfile12,pfile13,pfile14,pfile15,pfile16,pfile17,pfile18,pfile19,pfile20]. pfile1 => Init = $[ at(plane1,city0), fuel_level(plane1,fl1), at(person1,city0), at(person2,city2), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city1), at(person1,city0), at(person2,city2)], pddl(Init,Goal). pfile10 => Init = $[ at(plane1,city0), fuel_level(plane1,fl2), at(plane2,city4), fuel_level(plane2,fl5), at(plane3,city2), fuel_level(plane3,fl2), at(person1,city3), at(person2,city3), at(person3,city4), at(person4,city4), at(person5,city1), at(person6,city0), at(person7,city1), at(person8,city0), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city2), at(person1,city1), at(person2,city2), at(person3,city3), at(person4,city1), at(person5,city0), at(person6,city3), at(person7,city4), at(person8,city3)], pddl(Init,Goal). pfile11 => Init = $[ at(plane1,city4), fuel_level(plane1,fl4), at(plane2,city4), fuel_level(plane2,fl3), at(plane3,city1), fuel_level(plane3,fl5), at(person1,city4), at(person2,city2), at(person3,city2), at(person4,city0), at(person5,city2), at(person6,city2), at(person7,city5), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city1), at(person1,city4), at(person2,city1), at(person3,city2), at(person4,city2), at(person5,city2), at(person6,city4), at(person7,city0)], pddl(Init,Goal). pfile12 => Init = $[ at(plane1,city2), fuel_level(plane1,fl3), at(plane2,city3), fuel_level(plane2,fl6), at(plane3,city5), fuel_level(plane3,fl2), at(person1,city4), at(person2,city4), at(person3,city0), at(person4,city4), at(person5,city1), at(person6,city2), at(person7,city5), at(person8,city5), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city2), at(person2,city1), at(person3,city1), at(person4,city4), at(person5,city4), at(person6,city1), at(person7,city3), at(person8,city4)], pddl(Init,Goal). pfile13 => Init = $[ at(plane1,city4), fuel_level(plane1,fl2), at(plane2,city3), fuel_level(plane2,fl6), at(plane3,city3), fuel_level(plane3,fl6), at(person1,city1), at(person2,city2), at(person3,city1), at(person4,city4), at(person5,city5), at(person6,city1), at(person7,city0), at(person8,city2), at(person9,city1), at(person10,city5), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city4), at(person1,city4), at(person2,city5), at(person3,city4), at(person4,city0), at(person5,city2), at(person6,city3), at(person8,city0), at(person9,city3), at(person10,city4)], pddl(Init,Goal). pfile14 => Init = $[ at(plane1,city5), fuel_level(plane1,fl2), at(plane2,city2), fuel_level(plane2,fl6), at(plane3,city4), fuel_level(plane3,fl6), at(plane4,city8), fuel_level(plane4,fl3), at(plane5,city9), fuel_level(plane5,fl4), at(person1,city9), at(person2,city1), at(person3,city0), at(person4,city9), at(person5,city6), at(person6,city0), at(person7,city7), at(person8,city6), at(person9,city4), at(person10,city7), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane2,city3), at(plane4,city5), at(plane5,city8), at(person2,city8), at(person3,city2), at(person4,city7), at(person5,city1), at(person6,city6), at(person7,city5), at(person8,city1), at(person9,city5), at(person10,city9)], pddl(Init,Goal). pfile15 => Init = $[ at(plane1,city0), fuel_level(plane1,fl0), at(plane2,city3), fuel_level(plane2,fl4), at(plane3,city2), fuel_level(plane3,fl1), at(plane4,city9), fuel_level(plane4,fl1), at(plane5,city5), fuel_level(plane5,fl1), at(person1,city8), at(person2,city10), at(person3,city7), at(person4,city5), at(person5,city1), at(person6,city10), at(person7,city11), at(person8,city8), at(person9,city9), at(person10,city11), at(person11,city4), at(person12,city5), at(person13,city8), at(person14,city4), at(person15,city1), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city1), at(person2,city4), at(person3,city7), at(person4,city6), at(person5,city8), at(person6,city11), at(person7,city2), at(person8,city11), at(person10,city9), at(person11,city6), at(person12,city4), at(person13,city11), at(person14,city4), at(person15,city6)], pddl(Init,Goal). pfile16 => Init = $[ at(plane1,city6), fuel_level(plane1,fl2), at(plane2,city0), fuel_level(plane2,fl3), at(plane3,city10), fuel_level(plane3,fl5), at(plane4,city4), fuel_level(plane4,fl4), at(plane5,city1), fuel_level(plane5,fl6), at(person1,city8), at(person2,city12), at(person3,city0), at(person4,city4), at(person5,city13), at(person6,city7), at(person7,city1), at(person8,city2), at(person9,city1), at(person10,city2), at(person11,city10), at(person12,city7), at(person13,city6), at(person14,city1), at(person15,city13), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane2,city12), at(plane3,city6), at(person1,city3), at(person2,city4), at(person3,city11), at(person4,city13), at(person5,city11), at(person6,city7), at(person7,city1), at(person8,city11), at(person9,city2), at(person10,city6), at(person11,city0), at(person12,city12), at(person13,city13), at(person14,city4), at(person15,city4)], pddl(Init,Goal). pfile17 => Init = $[ at(plane1,city14), fuel_level(plane1,fl5), at(plane2,city11), fuel_level(plane2,fl0), at(plane3,city4), fuel_level(plane3,fl5), at(plane4,city11), fuel_level(plane4,fl3), at(plane5,city15), fuel_level(plane5,fl2), at(person1,city0), at(person2,city14), at(person3,city12), at(person4,city7), at(person5,city4), at(person6,city14), at(person7,city4), at(person8,city0), at(person9,city3), at(person10,city7), at(person11,city3), at(person12,city15), at(person13,city10), at(person14,city1), at(person15,city7), at(person16,city9), at(person17,city7), at(person18,city5), at(person19,city11), at(person20,city0), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city14), at(plane3,city7), at(plane5,city12), at(person1,city4), at(person2,city11), at(person3,city0), at(person4,city12), at(person5,city12), at(person6,city0), at(person7,city5), at(person8,city13), at(person9,city9), at(person10,city7), at(person11,city7), at(person12,city6), at(person13,city2), at(person14,city10), at(person15,city14), at(person16,city12), at(person17,city1), at(person18,city1), at(person19,city5), at(person20,city13)], pddl(Init,Goal). pfile18 => Init = $[ at(plane1,city11), fuel_level(plane1,fl3), at(plane2,city12), fuel_level(plane2,fl3), at(plane3,city12), fuel_level(plane3,fl0), at(plane4,city14), fuel_level(plane4,fl0), at(plane5,city14), fuel_level(plane5,fl6), at(person1,city7), at(person2,city16), at(person3,city9), at(person4,city6), at(person5,city6), at(person6,city0), at(person7,city6), at(person8,city8), at(person9,city13), at(person10,city14), at(person11,city7), at(person12,city15), at(person13,city4), at(person14,city14), at(person15,city10), at(person16,city5), at(person17,city10), at(person18,city11), at(person19,city9), at(person20,city3), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane2,city6), at(person1,city2), at(person2,city17), at(person3,city7), at(person4,city14), at(person5,city9), at(person6,city13), at(person7,city6), at(person8,city8), at(person9,city4), at(person10,city16), at(person11,city6), at(person12,city4), at(person13,city14), at(person14,city2), at(person15,city9), at(person16,city9), at(person17,city15), at(person18,city6), at(person19,city2), at(person20,city17)], pddl(Init,Goal). pfile19 => Init = $[ at(plane1,city0), fuel_level(plane1,fl1), at(plane2,city1), fuel_level(plane2,fl1), at(plane3,city16), fuel_level(plane3,fl5), at(plane4,city10), fuel_level(plane4,fl2), at(plane5,city1), fuel_level(plane5,fl1), at(person1,city19), at(person2,city3), at(person3,city6), at(person4,city16), at(person5,city13), at(person6,city6), at(person7,city0), at(person8,city3), at(person9,city13), at(person10,city16), at(person11,city2), at(person12,city6), at(person13,city8), at(person14,city0), at(person15,city8), at(person16,city19), at(person17,city9), at(person18,city0), at(person19,city1), at(person20,city12), at(person21,city8), at(person22,city15), at(person23,city4), at(person24,city6), at(person25,city17), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city11), at(plane2,city8), at(person1,city10), at(person2,city1), at(person3,city13), at(person4,city9), at(person5,city0), at(person6,city16), at(person7,city0), at(person8,city0), at(person9,city17), at(person10,city13), at(person11,city13), at(person12,city17), at(person13,city3), at(person14,city0), at(person15,city13), at(person16,city19), at(person17,city0), at(person18,city4), at(person19,city17), at(person20,city14), at(person21,city17), at(person22,city4), at(person23,city12), at(person24,city13), at(person25,city2)], pddl(Init,Goal). pfile2 => Init = $[ at(plane1,city0), fuel_level(plane1,fl2), at(person1,city2), at(person2,city1), at(person3,city2), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city2), at(person1,city1), at(person3,city2)], pddl(Init,Goal). pfile20 => Init = $[ at(plane1,city0), fuel_level(plane1,fl6), at(plane2,city6), fuel_level(plane2,fl0), at(plane3,city18), fuel_level(plane3,fl0), at(plane4,city11), fuel_level(plane4,fl6), at(plane5,city9), fuel_level(plane5,fl4), at(person1,city12), at(person2,city13), at(person3,city12), at(person4,city1), at(person5,city20), at(person6,city13), at(person7,city13), at(person8,city4), at(person9,city7), at(person10,city7), at(person11,city8), at(person12,city14), at(person13,city1), at(person14,city14), at(person15,city2), at(person16,city21), at(person17,city8), at(person18,city4), at(person19,city8), at(person20,city17), at(person21,city5), at(person22,city21), at(person23,city15), at(person24,city6), at(person25,city5), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city5), at(person2,city0), at(person3,city18), at(person4,city7), at(person5,city8), at(person6,city4), at(person7,city12), at(person8,city16), at(person9,city20), at(person10,city5), at(person11,city18), at(person12,city10), at(person13,city0), at(person14,city1), at(person15,city0), at(person16,city13), at(person17,city4), at(person18,city9), at(person19,city16), at(person20,city1), at(person21,city10), at(person22,city2), at(person23,city4), at(person24,city18), at(person25,city21)], pddl(Init,Goal). pfile3 => Init = $[ at(plane1,city0), fuel_level(plane1,fl4), at(plane2,city2), fuel_level(plane2,fl5), at(person1,city0), at(person2,city0), at(person3,city1), at(person4,city1), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane2,city2), at(person1,city1), at(person2,city0), at(person3,city0), at(person4,city1)], pddl(Init,Goal). pfile4 => Init = $[ at(plane1,city2), fuel_level(plane1,fl5), at(plane2,city2), fuel_level(plane2,fl0), at(person1,city0), at(person2,city1), at(person3,city0), at(person4,city0), at(person5,city2), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city0), at(person2,city2), at(person3,city0), at(person4,city1), at(person5,city2)], pddl(Init,Goal). pfile5 => Init = $[ at(plane1,city1), fuel_level(plane1,fl6), at(plane2,city2), fuel_level(plane2,fl0), at(person1,city3), at(person2,city0), at(person3,city0), at(person4,city1), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city2), at(person2,city3), at(person3,city3), at(person4,city3)], pddl(Init,Goal). pfile6 => Init = $[ at(plane1,city2), fuel_level(plane1,fl5), at(plane2,city1), fuel_level(plane2,fl3), at(person1,city0), at(person2,city0), at(person3,city3), at(person4,city1), at(person5,city2), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city3), at(person2,city1), at(person3,city3), at(person4,city3), at(person5,city1)], pddl(Init,Goal). pfile7 => Init = $[ at(plane1,city2), fuel_level(plane1,fl1), at(plane2,city1), fuel_level(plane2,fl1), at(person1,city3), at(person2,city3), at(person3,city3), at(person4,city1), at(person5,city3), at(person6,city0), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane2,city1), at(person1,city2), at(person3,city3), at(person4,city3), at(person5,city2), at(person6,city2)], pddl(Init,Goal). pfile8 => Init = $[ at(plane1,city0), fuel_level(plane1,fl6), at(plane2,city3), fuel_level(plane2,fl0), at(plane3,city0), fuel_level(plane3,fl3), at(person1,city1), at(person2,city0), at(person3,city2), at(person4,city0), at(person5,city3), at(person6,city4), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(plane1,city3), at(person1,city0), at(person2,city0), at(person3,city1), at(person4,city0), at(person5,city3), at(person6,city2)], pddl(Init,Goal). pfile9 => Init = $[ at(plane1,city2), fuel_level(plane1,fl5), at(plane2,city2), fuel_level(plane2,fl2), at(plane3,city1), fuel_level(plane3,fl0), at(person1,city4), at(person2,city1), at(person3,city2), at(person4,city0), at(person5,city4), at(person6,city3), at(person7,city3), next(fl0,fl1), next(fl1,fl2), next(fl2,fl3), next(fl3,fl4), next(fl4,fl5), next(fl5,fl6)], Goal = $[ at(person1,city2), at(person2,city0), at(person3,city4), at(person4,city3), at(person5,city1), at(person6,city4), at(person7,city4)], pddl(Init,Goal).