Skip to content

Commit b78c30b

Browse files
committed
add documentation.yaml
1 parent 87496c0 commit b78c30b

File tree

1 file changed

+398
-0
lines changed

1 file changed

+398
-0
lines changed

documentation.yaml

Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
extensionName: ls
2+
icon: i-si-flow-parallel-duotone
3+
filesToIncludeInManual:
4+
- USING.md
5+
- CITING.md
6+
- primitives
7+
markdownTemplate: |2+
8+
9+
# LS Extension for NetLogo
10+
11+
LevelSpace is an extension for NetLogo that allows you to run several models concurrently and have them "talk" with each other. LevelSpace models are hierarchical, in that models always belong hierarchically to another model. In this documentation, we will refer to models that have loaded LevelSpace and have opened models as 'parents', and to the models they have opened as 'children' or 'child models'.
12+
13+
{{> USING.md}}
14+
15+
{{> CITING.md}}
16+
17+
## Primitives
18+
19+
{{#contents}}
20+
### {{fullCategoryName}}
21+
22+
{{#prims}}
23+
[`{{name}}`](#{{primitive.extensionName}}{{primitive.name}})
24+
{{/prims}}
25+
26+
{{/contents}}
27+
28+
{{#primitives}}
29+
{{> primTemplate}}
30+
{{/primitives}}
31+
32+
{{> LICENSE.md}}
33+
34+
primTemplate: |2
35+
36+
### `{{name}}`
37+
38+
```NetLogo
39+
{{#examples}}
40+
{{#isOptional}}({{/isOptional}}{{primitive.fullName}}{{#args}} *{{argumentPlaceholder}}*{{/args}}{{#isOptional}}){{/isOptional}}
41+
{{/examples}}
42+
```
43+
44+
{{{description}}}
45+
primitives:
46+
- alternateArguments:
47+
- type: number
48+
- name: path
49+
type: string
50+
- type: command
51+
arguments:
52+
- type: number
53+
- name: path
54+
type: string
55+
description: |2
56+
57+
Create the specified number of instances of the given model. The path can be absolute, or relative to the main model. Compared with `ls:create-interactive-models`, this primitive creates lightweight models that are hidden by default. You should use this primitive if you plan on having many instances of the given model. The models may be shown using `ls:show`; when visible, they will have a view and command center, but no other widgets, e.g. plots or monitors.
58+
59+
If given a command, LevelSpace will call the command after loading each instance of the model with the `model-id` as the argument. This allows you to easily store model ids in a variable or list when loading models, or do other initialization. For example, to store a model id in a variable, you can do:
60+
61+
```NetLogo
62+
let model-id 0
63+
(ls:create-models "My-Model.nlogox" [ [id] -> set model-id id ])
64+
```
65+
66+
Child model RNGs are seeded from the parent models RNG when they are created.
67+
Thus, if you seed the parent's model RNG before child model before child models are created, the simulation as a whole will be reproducible.
68+
Use the `ls:random-seed` primitive to seed the model system's RNGs after child models have been created.
69+
name: create-models
70+
tags:
71+
- opening-closing
72+
type: command
73+
- alternateArguments:
74+
- type: number
75+
- name: path
76+
type: string
77+
- type: command
78+
arguments:
79+
- type: number
80+
- name: path
81+
type: string
82+
description: |2
83+
84+
Like `ls:create-models`, creates the specified number of instances of the given model. Unlike `ls:create-models`, `ls:create-interactive-models` creates models that are visible by default, and have all widgets. You should use this primitive if you plan on having only a handful of instances of the given model, and would like to be able to interact with the instances through their interfaces during runtime.
85+
86+
Child model RNGs are seeded from the parent models RNG when they are created.
87+
Thus, if you seed the parent's model RNG before child model before child models are created, the simulation as a whole will be reproducible.
88+
Use the `ls:random-seed` primitive to seed the model system's RNGs after child models have been created.
89+
name: create-interactive-models
90+
tags:
91+
- opening-closing
92+
type: command
93+
- arguments:
94+
- name: model-or-list-of-models
95+
type: number/list
96+
description: |2
97+
98+
Close the model or models with the given `model-id`.
99+
name: close
100+
tags:
101+
- opening-closing
102+
type: command
103+
- description: |2
104+
105+
Close down all child models (and, recursively, their child models). You'll often want to call this in your setup procedure.
106+
107+
Note that `clear-all` does *not* close LevelSpace models.
108+
name: reset
109+
tags:
110+
- opening-closing
111+
type: command
112+
- arguments:
113+
- name: model-or-list-of-models
114+
type: number/list
115+
- name: command
116+
type: code-block
117+
- name: argument
118+
type: repeatable anything
119+
description: |2
120+
121+
Ask the given child model or list of child models to run the given command. This is the primary of doing things with child models. For example:
122+
123+
```NetLogo
124+
ls:ask model-id [ create-turtles 5 ]
125+
```
126+
127+
You can also ask a list of models to all do the same thing:
128+
129+
```NetLogo
130+
ls:ask ls:models [ create-turtles 5 ]
131+
```
132+
133+
You may supply the command with arguments, just like you would with anonymous commands:
134+
135+
```NetLogo
136+
let turtle-id 0
137+
let speed 5
138+
(ls:ask model-id [ [t s] -> ask turtle t [ fd s ] ] turtle-id speed)
139+
```
140+
141+
Note that the commands cannot access variables in the parent model directly. You must either pass information in through arguments or using `ls:let`.
142+
name: ask
143+
tags:
144+
- interaction
145+
type: command
146+
- arguments:
147+
- name: reporter
148+
type: code-block
149+
- name: model-or-list-of-models
150+
type: number/list
151+
description: |2
152+
153+
Run the given reporter in the given model and report the result.
154+
155+
`ls:of` is designed to work like NetLogo's inbuilt `of`: If you send `ls:of` a `model-id`, it will report the value of the reporter from that model. If you send it a list of model-ids, it will report a list of values of the reporter string from all models. You cannot pass arguments to `ls:of`, but you can use `ls:let`.
156+
157+
```NetLogo
158+
[ count turtles ] ls:of model-id
159+
```
160+
infix: true
161+
name: of
162+
returns: anything
163+
tags:
164+
- interaction
165+
type: reporter
166+
- arguments:
167+
- name: model-or-list-of-models
168+
type: number/list
169+
- name: reporter
170+
type: code-block
171+
- name: argument
172+
type: repeatable anything
173+
description: |2
174+
175+
Run the given reporter in the given model and report the result. This form exists to allow you to pass arguments to the reporter.
176+
177+
```NetLogo
178+
let turtle-id 0
179+
(ls:report model-id [ [a-turtle] -> [ color ] of turtle a-turtle ] turtle-id)
180+
```
181+
name: report
182+
returns: anything
183+
tags:
184+
- interaction
185+
type: reporter
186+
- arguments:
187+
- name: list-of-models
188+
type: list
189+
- name: reporter
190+
type: code-block
191+
description: |2
192+
193+
Reports a new list of models containing only those models that report `true` when they run the reporter block.
194+
195+
```NetLogo
196+
ls:models ls:with [ count turtles > 100 ]
197+
```
198+
infix: true
199+
name: with
200+
returns: list
201+
tags:
202+
- interaction
203+
type: reporter
204+
- arguments:
205+
- name: variable-name
206+
type: symbol
207+
- name: value
208+
type: anything
209+
description: |2
210+
211+
Creates a variable containing the given data that can be accessed by the child models.
212+
213+
```NetLogo
214+
ask turtles [
215+
ls:let my-color color
216+
ls:ask my-model [
217+
ask turtles [ set color my-color ]
218+
]
219+
]
220+
```
221+
222+
`ls:let` works quite similar to `let` in that the variable is only locally accessible:
223+
224+
```NetLogo
225+
ask turtles [
226+
ls:let my-color color
227+
]
228+
;; my-color is innaccessible here
229+
```
230+
231+
`ls:let` is very similar to `let`, except in a few cases.
232+
233+
- `ls:let` will overwrite previous values in the variable
234+
235+
If you do
236+
237+
```NetLogo
238+
ls:let my-var 5
239+
ls:let my-var 6
240+
```
241+
242+
`my-var` will be set equal to `6`. There is no `ls:set`.
243+
244+
- `ls:let` supports variable shadowing
245+
246+
If you do
247+
248+
```NetLogo
249+
ls:let my-var 5
250+
ask turtles [
251+
ls:let my-var 6
252+
ls:ask child-model [ show my-var ]
253+
]
254+
ls:ask child-model [ show my-var ]
255+
```
256+
257+
`child-model` will show `6` and then `5`. This is known as [variable shadowing](https://en.wikipedia.org/wiki/Variable_shadowing).
258+
259+
- The parent model cannot directly read the value of an ls variable
260+
261+
For example, this does *not* work.
262+
263+
```NetLogo
264+
ls:let my-var 5
265+
show my-var
266+
```
267+
268+
This is intentional. ls variables are meant to be used for sharing data with child models. The parent model already has access to the data.
269+
270+
Furthermore, changing the value of an ls let variable in a child model will not affect it in any other model. For example:
271+
272+
```NetLogo
273+
ls:let my-var 0
274+
ls:ask ls:models [
275+
set my-var my-var + 1
276+
show my-var
277+
]
278+
```
279+
280+
All models will print `1`.
281+
name: let
282+
tags:
283+
- interaction
284+
type: command
285+
- arguments:
286+
- name: model-or-list-of-models
287+
type: number/list
288+
- name: global-variable
289+
type: symbol
290+
- name: value
291+
type: anything
292+
description: |2
293+
294+
Sets the given global variable in child model to given value. For instance
295+
296+
```netlogo
297+
ls:assign ls:models glob1 count turtles
298+
```
299+
300+
sets the global variable `glob1` in all models to the parent's model `count turtles`.
301+
name: assign
302+
tags:
303+
- interaction
304+
type: command
305+
- description: |2
306+
307+
Report a list of model-ids for all existing models.
308+
name: models
309+
returns: list
310+
tags:
311+
- logic
312+
type: reporter
313+
- arguments:
314+
- name: model-or-list-of-models
315+
type: number/list
316+
description: |2
317+
318+
Makes all of the given models visible.
319+
name: show
320+
tags:
321+
- logic
322+
type: command
323+
- arguments:
324+
- name: model-or-list-of-models
325+
type: number/list
326+
description: |2
327+
328+
Makes all of the given models *and their descendents* visible.
329+
name: show-all
330+
tags:
331+
- logic
332+
type: command
333+
- arguments:
334+
- name: model-or-list-of-models
335+
type: number/list
336+
description: |2
337+
338+
Hide all of the given models. Hiding models is a good way of making your simulation run faster.
339+
name: hide
340+
tags:
341+
- logic
342+
type: command
343+
- arguments:
344+
- name: model-or-list-of-models
345+
type: number/list
346+
description: |2
347+
348+
Hide all of the given models *and their descendents*. Hiding models is a good way of making your simulation run faster.
349+
name: hide-all
350+
tags:
351+
- logic
352+
type: command
353+
- arguments:
354+
- name: model-or-list-of-models
355+
type: number/list
356+
description: |2
357+
358+
Report the full path, including the file name of the model. If a list of models is given, a list of paths is reported.
359+
name: path-of
360+
returns: string
361+
tags:
362+
- logic
363+
type: reporter
364+
- arguments:
365+
- name: model-or-list-of-models
366+
type: number/list
367+
description: |2
368+
369+
Reports the name of the model file. This is the name of the window in which the model appears when visible. If a list of models is given, a list of names is reported.
370+
name: name-of
371+
returns: string
372+
tags:
373+
- logic
374+
type: reporter
375+
- arguments:
376+
- name: model-or-list-of-models
377+
type: number/list
378+
description: |2
379+
380+
Report a boolean value for whether there is a model with that model-id. This is often useful when you are dynamically generating models, and want to ensure that you are not asking models that no longer exist to do stuff.
381+
name: model-exists?
382+
returns: boolean
383+
tags:
384+
- logic
385+
type: reporter
386+
- arguments:
387+
- name: seed
388+
type: number
389+
description: |2
390+
391+
Behaves exactly like NetLogo's built-in primitive `random-seed`, except that child models have their RNGs seeded based on the given seed as well (as well their child models, and their child models' child models, and so forth).
392+
This primitive should almost always be used instead of NetLogo's built-in one for seeding RNG when using LevelSpace.
393+
name: random-seed
394+
type: command
395+
tableOfContents:
396+
interaction: Commanding and Reporting
397+
logic: Logic and Control
398+
opening-closing: Opening and Closing Models

0 commit comments

Comments
 (0)