From: Mart Lubbers Date: Tue, 14 Oct 2014 10:39:59 +0000 (+0200) Subject: this weeks nonsense X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=70d61948f0589859600bb0e93abee6fc9099c362;p=ker1415-1.git this weeks nonsense --- diff --git a/report/ass1.tex b/report/ass1.tex index 2a7f53a..5343cea 100644 --- a/report/ass1.tex +++ b/report/ass1.tex @@ -63,6 +63,16 @@ connected(x, y, d) \wedge connected(y, z, d) \rightarrow \end{itemize} \subsection{Part 2: Implementation} +\subsubsection{Task 3: Translate Axioms} +\lstinputlisting[title={domain-task1.pl},language=prolog]{./src/domain-task1.pl} + +\subsubsection{Task 4: The Planning Problem in Figure 1} +\lstinputlisting[title={instance-task1.pl},language=prolog]{./src/instance-task1.pl} + +\subsubsection{Task 5: Crates go to Any Goal Location} +\subsubsection{Task 6: Inverse Problem} + +\subsection{Part 3: Extending the domain} \subsection{Evaluation} \begin{itemize} diff --git a/report/src/domaintask1.pl b/report/src/domaintask1.pl new file mode 100644 index 0000000..51161bf --- /dev/null +++ b/report/src/domaintask1.pl @@ -0,0 +1,32 @@ +% ------------------------- Domain Definition ------------------------- +% --- Cross-file definitions ------------------------------------------ +:- multifile connected/3, crate/3, agent/2. + +% --- Primitive control actions --------------------------------------- +primitive_action(move(_, _)). +primitive_action(push(_, _)). + +% --- Precondition for primitive actions ------------------------------ +poss(move(From, To), S) :- + agent(From, S), + connected(From, To, _), + not(crate(_, To, S)). +poss(push(From, Direction), S) :- + agent(From, S), + connected(From, CrateLocation, Direction), + crate(_, CrateLocation, S), + connected(CrateLocation, CrateTarget, Direction), + not(crate(_, CrateTarget, Direction)). + +% --- Successor state axioms ------------------------------------------ +agent(AgentPlek, do(A, S)) :- + A = move(_, AgentPlek); + A = push(OudeAgentPlek1, Richting), connected(OudeAgentPlek1, AgentPlek, Richting); + not(A = move(AgentPlek, _)), not(A = push(AgentPlek, _)), agent(AgentPlek, S). + +crate(Krat, Kratplek, do(A, S)) :- + A = push(AgentPlek, Richting), + connected(AgentPlek, OudeKratPlek, Richting), + connected(OudeKratPlek, Kratplek, Richting), + crate(Krat, OudeKratPlek, S); + not(A = push(AgentPlek2, Richting)), connected(AgentPlek2, Kratplek, Richting), crate(Krat, Kratplek, S). diff --git a/report/src/instancetask1.pl b/report/src/instancetask1.pl new file mode 100644 index 0000000..20e1f1e --- /dev/null +++ b/report/src/instancetask1.pl @@ -0,0 +1,38 @@ +% ------------------------- Problem Instance -------------------------- +% --- Load domain definitions from an external file ------------------- +:- [domaintask1]. + +% --- Definition of the initial state --------------------------------- +connected(loc1-1, loc2-1, north). +connected(loc1-1, loc1-2, east). +connected(loc1-2, loc2-2, north). +connected(loc1-2, loc1-3, east). +connected(loc1-3, loc2-3, north). +connected(loc1-3, loc1-4, east). +connected(loc1-4, loc2-4, north). + +connected(loc2-1, loc3-1, north). +connected(loc2-1, loc2-2, east). +connected(loc2-2, loc3-2, north). +connected(loc2-2, loc2-3, east). +connected(loc2-3, loc3-3, north). +connected(loc2-3, loc2-4, east). + +connected(loc3-1, loc3-2, north). +connected(loc3-2, loc3-3, north). + +connected(X, Y, east) :- connected(Y, X, west). +connected(X, Y, north) :- connected(Y, X, south). + +crate(crate-c, loc2-1, s0). +crate(crate-b, loc2-2, s0). +crate(crate-a, loc2-3, s0). + +target(crate-a, loc1-1). +target(crate-b, loc1-3). +target(crate-c, loc1-2). + +agent(loc3-2, s0). + +% --- Goal condition that the planner will try to reach --------------- +goal(S) :- forall(crate(Crate, Loc, S), target(Crate, Loc)). diff --git a/report/src/planner.pl b/report/src/planner.pl new file mode 100644 index 0000000..b340a92 --- /dev/null +++ b/report/src/planner.pl @@ -0,0 +1,103 @@ +% -------------= Simple planner for situation calculus =--------------- +% +% Executes an iterative deepening search, by default limited to a depth +% of 15 levels +% +% plan. will search for a plan of maximum length +% plan(M). will search for a plan of maximum length up to M +% plan(N,M). will search for a plan of mimimum length N and maximum +% length M +% +% +% Checklist for the definition of a domain and problem: +% +% - initial state initialize fluents in s0 +% +% - possibility axioms poss( (...), S ) :- +% +% - successor-state axioms ( ..., result(A,S) ) :- +% ; % or +% , % and +% not(). +% +% - goal predicate goal(S) :- +% + +% --------------------------= High Level =----------------------------- + +% default number of iterations (15) +plan :- plan(0, 15). + +% given max number of iterations +plan(MaxDepth) :- plan(0, MaxDepth). + +% given min and max number of iterations +plan(MinDepth, MaxDepth) :- + M is MaxDepth+1, write('Trying plans of length: '), + plan(Plan, MinDepth, M), nl, nl, writePlan(Plan). + + + +% same as above, to be called from shell; include additional output +% messages and halt to quit pl +planner :- planner(0, 15). +planner(MaxDepth) :- planner(0, MaxDepth). +planner(MinDepth, MaxDepth) :- + nl, plan(MinDepth, MaxDepth), nl, halt; + write('\n\nNo plan has been found!'), nl, nl, halt. + + + +% ---------------------------= Low Level =----------------------------- + +% start from depth N, up to M + +plan(P, N, M) :- + N < M, + debugoutput(write('\n\nPlans of length ')), + writef('%w %f',[N]), + seqplan(P, N, s0), !. + +plan(P, N, M) :- N < M, O is N+1, plan(P, O, M). + +seqplan( [], N, S ) :- N = 0, debugoutput(writeSituation(S)), goal(S). +seqplan( [A|L], N, S) :- N > 0, M is N-1, result(A,S,S1), seqplan(L, M, S1). + +result(E,S,result(E,S)) :- primitive_action(E), poss(E,S). + +% -----------------------= Support Function =-------------------------- + +% debugoutput will be printed only if debug(on) is defined in the KB +:- dynamic debug/1. +:- multifile debug/1. + +debug(on). +debugoutput(A) :- debug(on), A, !; true. + + +% prints a situation as a sequence of actions, starting from s0 +writeSituation(s0) :- write('\n s0'). +writeSituation(result(A,S)) :- writeSituation(S), writef(" > %w", [A]). + +% prints a plan as a list of actions, numbered + +writePlan(List) :- + debugoutput(write('\nA plan has been found:\n\n')), + writePlan(List,1). + +writePlan([],_) :- + nl. + +writePlan([Action|List], Counter) :- + writef('%3R %w\n',[Counter,Action]), + Next is Counter+1, + writePlan(List,Next). + + +% hides some (unimportant) warnings from the pl interpreter +:- style_check([-discontiguous, -singleton]). + + + +% --------------------------------------------------------------------- +% ---------------------------------------------------------------------