%% Strips in prolog. November 2006. Tim Finin. finin@umbc.edu % LIBRARIES -- load our local dbug utility :- ensure_loaded(dbug). /* ********************************************************************** strips/3 is the top level predicate for strips strips(+GoalState, +InitialState, -PlanSteps) e.g. strips([on(a,b)],[ontable(a),ontable(b),...], Plan) calls strips/6, the internal strips predicate, and reverse it's plan, so that the steps go from first to last *********************************************************************** */ strips(Goal, InitState, Plan):- strips(Goal, InitState, [], [], _, RevPlan), reverse(RevPlan, Plan). /* ********************************************************************** strips/6 also keeps track of the plan stack and produces an extended plan and modifided state on each iteraction. strips(+GoalList, +State, +Plan, +PlanStack, -NewState, -NewPlan ) *********************************************************************** */ % This clause recognizes that we are done when each goal in Goals is also % in the current State. strips(Goals, State, Plan, PlanStack, State, Plan) :- subset(Goals,State), !, % Depth is the Depth of recursion, only used in printing. length(PlanStack, L), Depth is L*5, dbug("~n~*cStips planning done with:",[Depth,32]), dbug("~n~*c goal: ~p",[Depth,32,Goals]), dbug("~n~*c state: ~p",[Depth,32,State]), dbug("~n~*c current plan: ~p",[Depth,32,Plan]), dbug("~n~*c plan stack: ~p",[Depth,32,PlanStack]). % this is the basic recursive step strips(Goals, State, Plan, PlanStack, NewState, NewPlan):- % is this potential plan too long already? length(Plan,PlanLength), length(PlanStack, PlanStackLength), Steps is PlanLength+PlanStackLength, stripsMaxPlanLength(MaxPlanLength), Steps