In this practical, the festival model will be extended by adding a new type of agent to represent criminals (called 'muggers') and by creating some interactions between different agents if they happen to bump into each other.
breedcommand - if you can't remember how this command works check the NetLogo Programming Guide or refer to the last practical.
victims' that the muggers will use to keep track of the number of people they mug. Hint: the
muggers-owncommand will do this, as covered in the last practical.
Now, NetLogo knows that there are two types of agents in the model. The next thing to do is actually create some muggers
number-of-muggers'. This will be used to set the number of mugger agents. You can choose the limits of the slider - I choose a limit of 100 and default of 10.
setup-muggers'. This procedure should create the new mugger agents and do three things:
setup-muggers' procedure in the main '
setup' procedure, just after the call to '
setup-people. By the end, your setup procedures will look similar to the right image. Sorry, the
setup-muggersprocedure has gotten smudged, you'll have to work out what goes in there on your own!
The next stage is to implement some behaviour for the mugger agents. We need a procedure that will move the muggers around the environment and, if they come into contact with a visitor, commit a mugging.
show-crimes. This will be used later to turn on (or off) a label that shows where crimes have been committed.
Next, we will create a new procedure that controls the behaviour of the mugger
agents. There is already a procedure called '
move' that tells the visitor
agents what to do at each model iteration. No we need a similar procedure that will
tell a mugger to walk around the festival site and, if they come across a
visitor, mug them.
move-and-mug'. This procedure will contain the code that we need to control the mugger agents.
||The procedure is called 'move-and-mug'. It will control where the agents go and make them mug visitors if they happen to meet on the same patch.|
||These commands make the muggers move around the environment randomly. They don't move between food stalls and stages like the visitors do.|
||Important! This commands checks to see if there are any visitors on the same patch as the mugger. If there is at least one visitor on the patch, then any code after the square bracket will run.|
||This code will only be executed if there are victims here. It increases
the value of the mugger's
||The last thing we want to do, after a mugging, is (optionally) to show
where crimes have taken place. This command checks to see if
||Ask the patch where the mugging has just taken place ...|
||... to create a label that has black text ...|
||... and shows the letter 'c' (as in 'crime').|
||Closing braces for the
||This closing bracket closes the
go' procedure after the visitors have moved:
ask muggers [
plot ( sum [ victims ] of muggers ) / ( ticks + 1)(note:
ticks+1is used to prevent problems with dividing by zero when the model starts).
When you have finished, your model should look something similar to the one below. There is quite a lot to take in from this practical. Before you finish, have a go at the activity below. It will help you to understand how the behaviour of the agents really works.
Change the behaviour of the mugger agents so that, instead of walking randomly around the festival site they move between the two stages.
;' character) to hide the old
move-and-mugcode. This way, you can revert to the old behaviour if you want to by commenting-out your new code, and uncommenting the old stuff.