-
Notifications
You must be signed in to change notification settings - Fork 5
/
Swarm_original README in folder simpleSwarmBug2.txt
122 lines (78 loc) · 4.21 KB
/
Swarm_original README in folder simpleSwarmBug2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// simpleSwarmBug2
MANAGING MORE AGENTS
main.m
We extend the model in this version, but............not here!
Our model is now encapsulated in the ModelSwarm, so any extensions
will now happen there. This main.m is exactly the same as the previous
one: We just build and start the modelSwarm
ModelSwarm.h and ModelSwarm.m
Now that we have our model encapsulated in an object, further work
on the model happens here. In this version, we extend the model by
allowing for a large number of bugs to live in the same world.
We add two structures to accomodate the newcomers.
First, we don't want them stepping all over each other so we add
another space with which the bugs interact which makes sure that
there is never more than one bug at a site.
Second, we create a "collection" of all the bugs, so we can treat
them as a unit. In fact, we encapsulate them into a "List" object,
and now we communicate with them by sending messages to the bugList,
which, in turn, forwards our messages to the whole set of bugs.
Thus, we have "incarnated" another abstraction into a kind of "thing"
that we can interact with: the collection of all the bugs.
Grid2d is Class of objects that is already defined in the Swarm
libraries, so we just ask it to make us an instance. Grid2d
enforces only 1 bug per site. "nil" means that there is no bug at
the site, while a bug's "id" itself is stored there when a bug is
there.
The collection of bugs is entrusted to a List object. A List is also
predefined, so we don't need to define either of these ourselves
via .h and .m files.
The uniformDblRand id is an object in the random number library
of swarm that gives us random "real" numbers with a uniform
distribution when we ask it to.
We grab the first bug we created off the list and anoint it
the "reporterBug" - we'll continue to have one bug tell us about
its food encounters. After we've grabbed it we stick it back on
the list....or rather, we ask the list to reinsert it.
In buildActions, we again create the list of simulation actions.
We put these in an action group, because we want these actions to
be executed in a specific order, but these steps should take no
(simulated) time. The M(foo) means "The message called <foo>".
You can send a message To a particular object, or ForEach object
in a collection.
Here, we construct an action that will go on a schedule that has more
than one thing happening, but we assume that they both happen in "zero"
time, and hence effectively concurrently
We want two things to happen: we want *all* of the bugs to take their
basic time-step action, and we want the reportBug to report to us if it
found food.
The creatActionTo: message to the reportBug is like the one in the last
version to tell aBug to take its step.
However, the createActionForEach: message is what we send to the List
managing the collection of bugs, requesting that it rebroadcast the
request to each of the bugs it manages, saving us from having to know
about or deal with each bug explicitly. Bugs could come and go, and
yet we would not have to change our behavior at this level.
Then we create a schedule that executes the modelActions. modelActions
is an ActionGroup, by itself it has no notion of time. In order to
have it executed in time, we create a Schedule that says to use
the modelActions ActionGroup at particular times.
This schedule has a repeat interval of 1, it will loop every time step.
The action is executed at time 0 relative to the beginning of the loop.
activateIn is the same as before
Bug.h andBug.m
We have added functionality to the bugs, as they now must share
a world with each other. They have to be able to determine that
there is nobody else at the site that they have chosen to move
to. They now check for this as well as for food in the step method.
For reporting purposes, the bugs set a variable if they did eat on
this step, so that they can report that if they happen to be the
reporterBug.
Also, we have a new method for "being" a reporterBug. If you get sent
this message, you were selected as the reporterBug, and you will
check that you ate this last step, and tell the world about it.
FoodSpace.h and FoodSpace.m
No change.
Makefile
No change.
NEXT -> simpleSwarmBug3