Libraries‎ > ‎Library‎ > ‎

Layout linked agents

BehaviourComposer: ignore everything before this.

I lay out a set of agents where the agents repel each other and the links between them act like springs.

Begin micro-behaviour

Lay out linked agents

Begin NetLogo code:
substitute-text-area-for columns: 80 rows: 5 comment ; Notes <br>; <br>; <br>; <br>;
substitute-text-area-for columns: 71 repetitions 500
substitute-text-area-for columns: 75 nodes-to-layout all-individuals
substitute-text-area-for columns: 75 links-in-layout links              
substitute-text-area-for columns: 75 spring-constant .2     
substitute-text-area-for columns: 75 spring-length 5      
substitute-text-area-for columns: 75 repulsion-constant 1 
substitute-text-area-for columns: 76 rows: 7 setup-code ; place for code to set things up (if needed)
comment
no-display
setup-code
repeat repetitions
[layout-spring 
     nodes-to-layout 
     links-in-layout
     spring-constant ; a measure of the "tautness" of the spring
     spring-length ; the "zero-force" length or the natural length of the springs
     repulsion-constant] ; a measure of repulsion between the nodes
display
End NetLogo code

Variants

All the text areas can be edited. If you want to limit the agents involved edit the first box. E.g. To only layout sheep replace it with all-individuals with [kind = "Sheep"]. To limit the layout to a subset of the links replace the contents of the second text area.

Related Micro-behaviours

LAYOUT-CIRCLE lays agents out in circles. LAYOUT-GRID lays out the agents in a rectangular grid.

SET-RANDOM-POSITION sets an agent's heading to a random value. SET-RANDOM-UNOCCUPIED-POSITION also finds a random position but only if it is unoccupied.

How this works

This uses the NetLogo layout-spring primitive to place the agents. It repeats calls to layout-spring since each time the constraints are solved bringing the configuration of agents closer to the ideal solution.

History

This was implemented by Ken Kahn on 1 February 2011.

BehaviourComposer: ignore everything after this.


Comments