Debian Codegraph @

texmf-dist/doc/latex/aiplans/aiplans-Introduction.md

raw
1 # Instructions for Generating TikZ Diagrams Using LaTeX
2
3 You will need the following files:
4
5 - `tikzlibraryaiplans.code.tex` (library code)
6 - `main.tex` (the main document)
7 - `domain.tex` (for defining the action schemas)
8 - `plan.tex` (the plan that uses the defined actions)
9
10
11 ## Main LaTeX Document
12
13 Create a `main.tex` file that includes the domain file (such as `blocksworld_domain.tex`) and the specific plan file(s) (such as `blocksworld_plan.tex` in our example).
14
15 ```latex
16 \documentclass[border=1in]{standalone}
17 \usepackage{tikz}
18 \usetikzlibrary{aiplans}
19 \begin{document}
20 \input{domain} % Action schema specification
21 \input{plan} % The plan to display
22 \end{document}
23 ```
24
25 ## Define Action Model -- aka the Domain
26
27 In this step, you will create a `domain.tex` file where you define your action model, not unlike in HDDL. I.e., you provide action schemata (that take parameters) that you can later use with different instantiations of those parameters (you will later see an example).
28
29 Each action schema you define follows a specific pattern:
30
31 <div style="page-break-after: always;"></div>
32
33 ```latex
34 NameOfScheme /. style n args = {num of input parameters}
35 {action=
36 % number of precs/effs
37 {num of precondition lines (on the left side of action)}
38 {num of effect lines (on the right side of action)}
39 % the actual prec/eff to display
40 {sequence of precondition labels}
41 {sequence of effect labels}
42 % length of precs/effs
43 {length of preconditions}
44 {length of effects}
45 % action name to display
46 {action name}
47 % prec/eff label position
48 {precondition/effect label position: above lines or on their side}
49 {height of node}
50 }
51 ```
52
53 That is, for each action schema you provide one such definition that you can later reference in your plan with different arguments/parameters. In a Blocksworld example, you may define an action schema `stack()` with two arguments (i.e., two block constants) and then in the plan use that schema multiple times with different constants.
54
55 Note that often several actions might share several attributes such as precondition of effect length. Hence, in our example, we factored out those properties as follows:
56
57 ```latex
58 \tikzset{
59 STYLE/.style n args = {5}{
60 action={#1}{#2}{#3}{#4}{1}{1.4}{#5}{0}{6 cm}
61 }
62 }
63 ```
64
65 Note that here you could also specify any arguments that you want to apply to all actions, such as different widths, or fill coloring. For example, by simply appending `minimum width=2cm` to change our default width.
66
67 Then, when defining our action schema, each action uses this pre-defined style so that we have to define shared properties only once. In our example, all precondition lengths are 1cm and all effects have length 14 cm. Also, all preconditions/effects occur on the left/right of all actions (rather than above/below) and, finally, all actions have a height of 6 cm. Based on this factored out `STYLE`, we define our actions as follows:
68
69 ```latex
70 \tikzset{
71 PICKUP/.style n args = {1}{STYLE={3}{4}{gF,onT(#1),clr(#1)}
72 {$\neg$gF,gH(#1),$\neg$clr(#1),$\neg$onT(#1)}
73 {pickup(#1)}},
74 PUTDOWN/.style n args = {1}{STYLE={1}{4}{gH(#1)} # of precs/effs; then precs
75 {gF,$\neg$gH(#1),onT(#1),clr(#1)}
76 {putdown(#1)}},
77 STACK/.style n args = {2}{STYLE={2}{5}{gH(#1),clr(#2)} # of precs/effs; then precs
78 {gF,$\neg$gH(#1),onT{(#1,#2)},clr(#1),$\neg$clr(#2)}
79 {stack{(#1,#2)}}},
80 UNSTACK/.style n args = {2}{STYLE={3}{5}{gF,clr(#2),on(#1)}
81 {$\neg$gF,gH{(#1)},$\neg$on(#1),$\neg$clr(#1),clr(#1)}
82 {unstack{(#1,#2)}}}
83 }
84 ```
85
86 In the example above, the preconditions and effects have the following meaning:
87 - gH: gripper holds the respective object
88 - gF: the gripper is free, hence doesn't hold any object
89 - clr: the respective block is clear, i.e., no other block is above it
90 - onT: the respective block sits directly on the table
91 - on: one block (first argument) sits on the other block (second argument)
92
93 Note that you can also set action schema-specific properties, just like we have done above (with the minimum width) for *all* action schemata. You do this simply by adding the respective property to the respective action schema definition. Just make sure to add it after loading the action macro. For example, to fill all pickup actions in red, specify provide the following definition:
94
95 ```latex
96 PICKUP/.style n args = {1}{STYLE={3}{4}{gF,onT(#1),clr(#1)}
97 {$\neg$gF,gH(#1),$\neg$clr(#1),$\neg$onT(#1)}
98 {pickup(#1)},fill=red},
99 ```
100
101 Finally, note that we provide a pre-defined way to define the initial state and goal description.
102
103 ```latex
104 INIT/.style={
105 init={
106 {number of effects},
107 {effects},
108 {effects length},
109 {height of init}}}
110 GOAL/.style={
111 goal={
112 {number of preconditions},
113 {preconditions},
114 {preconditions length},
115 {height of goal}}}
116 ```
117
118 In our Blocksworld example, it would look as follows:
119
120 ```latex
121 \tikzset{
122 INIT/.style = {init={8}{gF,onT(B),onT(C),onT(D),clr(A),clr(B),clr(D),{on(A,C)}}{1.2}{8 cm}},
123 GOAL/.style = {goal={2}{{on(A,B)},{on(D,C)}}{1.2}{8 cm}}
124 }
125 ```
126
127
128 ## Specify your Plan
129
130 A plan is a simple tikzgraphic, with the difference that we now offer two special labels:
131 - nodes can use the predefined schemata (to be instantiated as seen in the example)
132 - draw commands feature a causal link command, which draw dots on the two anchors of the respective link
133
134 ```latex
135 \begin{tikzpicture}
136 \node[INIT] (init) {};
137 \node[UNSTACK={A}{C}] (unstackAC) [right=3.5cm of init] {};
138 \node[PUTDOWN={A}] (putdownA) [right=3.5cm of unstackAC] {};
139 \node[PICKUP={A}] (pickupA) [right=3.5cm of putdownA] {};
140 \node[STACK={A}{B}] (stackAB) [right=3.5cm of pickupA] {};
141 \node[PICKUP={D}] (pickupD) [right=3.5cm of stackAB] {};
142 \node[STACK={D}{C}] (stackDC) [right=3.5cm of pickupD] {};
143 \node[GOAL] (goal) [right=3.5cm of stackDC] {};
144
145 \draw [causalLink, bend left] (init-eff-1) to (unstackAC-pre-1);
146 \draw [causalLink, bend left] (init-eff-5) to (unstackAC-pre-2);
147 \draw [causalLink, bend right] (init-eff-8) to (unstackAC-pre-3);
148 \draw [causalLink, bend left] (unstackAC-eff-2) to (putdownA-pre-1);
149 \draw [causalLink, bend left] (putdownA-eff-1) to (pickupA-pre-1);
150 \draw [causalLink, bend right] (putdownA-eff-3) to (pickupA-pre-2);
151 \draw [causalLink, bend right] (putdownA-eff-4) to (pickupA-pre-3);
152 \draw [causalLink, bend left] (pickupA-eff-2) to (stackAB-pre-1);
153 \draw [causalLink, bend right] (init-eff-6) to (stackAB-pre-2);
154 \draw [causalLink, bend left] (stackAB-eff-1) to (pickupD-pre-1);
155 \draw [causalLink, bend left] (init-eff-4) to (pickupD-pre-2);
156 \draw [causalLink, bend right=20] (init-eff-7) to (pickupD-pre-3);
157 \draw [causalLink, bend left] (pickupD-eff-2) to (stackDC-pre-1);
158 \draw [causalLink, bend right=20] (unstackAC-eff-5) to (stackDC-pre-2);
159 \draw [causalLink, bend left] (stackAB-eff-3) to (goal-pre-1);
160 \draw [causalLink, bend left] (stackDC-eff-3) to (goal-pre-2);
161 \end{tikzpicture}
162 ```
163
164 You can see, among others, that the `stack` schema is drawn twice, once with arguments `A` and `B` and once with arguments `D` and `C`. Also, just like you were able to specify action schema-specific properties, you can also do that per search node. For example, although above both `stack` nodes would show all the same properties, you could, for example, define the following:
165
166 ```latex
167 \node[STACK={D}{C},fill=red] (stackDC) [right=3.5cm of pickupD] {};
168 ```
169
170 which would only fill that specific stack action in red, but not any others.
171
172 The plan is then depicted as follows:
173
174 ![The created plan from our example](example-blocksworld.png)
175
176 We also provide our example directly in compilable code.