Let's construct a second model that builds on our first. The first thing we're going to do is make a copy of this "ant1.nlogo". Here, I can do that by right-clicking and saying 'copy' this. And then I can do a command-v, or control-v, ok, so however you in your system copy files. Make a copy of that, and I'm going to re-name it "ant2.nlogo". Then I'm going to double-click on it to open it and we'll re-label it by right-clicking on this label, selecting 'edit' and calling it "ant2". Now that we have an ant that can move around, let's give it something to eat. So let's go to the code tab and let's grow some food for the ant. So in the setup procedure, we would write 'grow food'. Ok, but now we have to tell the system how to grow food. So we can go down here and write a new procedure 'to grow food' And what we're going to do here is 'ask patches set pea color green end' So let me explain about patches. We go over here back to the interface, you see here in the world, which is this black area, we can right-click and edit, and you see that this shows the coordinate system for the world. It's probably hard to see that on your screen, but you can do it in netlogo and take a look, where the (0,0) coordinate is in the middle and then this goes to -16 to 16 in the vertical and -16 to 16 in the horizontal, and so the whole box is a grid of 33 by 33 squares, which are called 'patches'. And here's the net number of pixels per patch, here, it's 13 and so on. So each patch has properties of its own, like color. If I go back to the code, I've now asked all of the patches to set their colour, pea color is the color of the patch, to green. So let's see what happens when I do 'setup'. Indeed, they've all been set to green. So we can take that as a model of an ant living in a world of grass. Now let's go back to the 'code' tab and write some code to have the ants eat the grass. So do this, we're going to write the following right here: If pea color equals green that is I'm going to write a comment here. if the turtle is located on a green patch. So this is asking the turtle to look at their patch and the patch that they are on every turtle is on a particular patch. And if the patch is green, then this is what it has to do It's going to eat the piece of green grass by setting the color back to black So set pea color black. Ok and then it is going to keep track of how much food its eaten so it's going to set food eaten to food eaten plus one. Then we are going to do one more thing which is have it wear on its body a label that says, it's going to tell us how much food it has eaten so we are going to set label to food eaten Notice that this is all something that we are going to ask the turtles to do and I realize that I have to this bracket down here. And I'm going to put tabs I'm going to put tab. Every time hit a tab it indents this to where it should go. So now I have two brackets This one and this one. around all the commands we are going to ask the turtles to do. We are going to ask them to turn right or left. go forward four and look at their patch if the color is green set the color black, increase the amount of food eaten by one, and wear a label that says how much of the food the ant has been eaten. Now there is one thing we have to do. which is food eaten which we have to set that up. So turtles have to have some kind of variable associated with them called food eaten. We could think of that as the turtle's stomach. Which keeps track of how much food its eaten and the turtles never digest anything in this model so to do that I'm going to say turtles, turtles_owed, food eaten and what that does is it sets a variable called food eaten that's specific to each turtle. Each turtle has it's own food eaten variable So every turtle is going to have a different amount of food eaten. Up here in set up. I'm going to set that to zero. Set food eaten zero. So, to make sure it starts out at zero. Then as it goes the turtle or ant will accumulate the amount of food it has eaten let's check this. Click ok. Go back to interphase. Let's slow it down a little bit so we can watch the turtle eating food. So, the turle is going through-- --I'm sorry the ant. I should say, is going through the world moving around and every time it goes through, it lands on a green patch, it eats the food there. Remeber it's taking between 0 and 3 steps every time. So, it only eats the food after it's done. Taking all it's steps. So you see it going around. Speed it up a little bit And you can watch the ant going around eating the food. You probably can't see it on your screen but the ant is showing a label of how much food it has eaten. It's alot of food for one little ant to eat. And the next thing to do is to give our ant a colony. So let's add some more ants. The way to do that is to add a population And let's allow the user of our model to set the population size. So I'm going here to the interphase menu. And go to slider I'm going to put in a slider I'm going to call it global variable population. I'm going to let the minimum population be 1. The maximum be--let's say--200. We can allow people to increment them by one. This gets the initial value 50. Then we will do apply and ok. We will move this--select it and move it up here. But now we have to tell the code what to do with this variable population. I'm going to go to the code tab. and instead of create turtles of one. Create turtles of population. So the user will set the population number and then the code will create that many turtles. So let's see what happens when we setup. Now we have all our aunts in the middle. We will allow 50 of them. And let's allow them go. So, we can see them move around. I've slowed it down. So they are all doing the same thing. But each has some random choices it makes. We can see them all acting a little bit differently. And, if we speed it up. We start to see things. that look almost like real ants. moving around eating food. Let's try increasing the population. 130 seems like a good number of ants. Now they are really crowded. They are so crowded that I think we should go into the code and make them smaller let's set their size to 1. Let's see what that does. So I'll setup. Now they are much smaller little ants You probably can't see them too well. They certainly give each other more room. Again it's too small to see on your screen. But, each ant has a label saying how much food it's eaten. One thing we'd like to know. Food the total colony has eaten. So what I'm going to add a plot of overtime how much food has been eaten. If we go up again to the interphase menus I'm going to choice plot. And it's going to ask me a bunch of things about plot I'm going to call it "Total Food Eaten" It's going to take care of minimum and maximum itself I'll let that adjust by itself. I'll call the x axis label total food eaten The Y axis label is time. and let's call the pen name, the color we will leave black. The color name we will call total food eaten And I'm going to give a plot command. Here I'm going to tell it to plot the sum of food eaten of turtles. So this says, for each turtle look at how much food it has eaten. And sum all of that and plot that vs time. Ok, apply, oops, I gave the wrong. This should have been the y axis total food eaten and this should be x axis time. now we are good. so, let's select this. Let's move this. A little bit taller so we can see ok, and now, let's see if that works. Setup. Go. so you can the plot is adjusting itself This number keeps changing. and this shows how fast the food is eaten. And you can play with the population size to see how much that effects how fast the food is eaten. To finish off our model. Let's let the uses set some of the other variables. that the ants obey so for example let's have a slider. that let's you set both the maximum step size and the maximum turn angle. So I'm going to select the plot. Move it down for two more sliders. and I'm going to go up here and select slider. And we have the variable, let's call it max step size. Let's have it's minimum be one. It's maximum be 10. Let's have it's initial value be 4. Ok, let's move this here. And, let's let this move these guys up. and then let's do another slider. called maximum turn angle. and let's say a minimum be 1 degree and a maximum of 180. Ok, initial value, we had 60 in the code, apply ok. Select move. ok now we have to put these variables in the code So here, instead of saying sixty here. Let's say max turn angle and same here max turn angle. Ok, now we have right max turn angle. Let max turn angle. Well you might notice if you are paying attention that this random statement returns an integer between 0 and this minus 1. The max turn angle minus 1 So actually the max turn angle is a little of a misnomer it really should be the max turn angle would be this minus one but i'm not going to worry too much about that Here we are going to do the same thing Instead of four I'm going to say max step size Alright, so let's check this code. By the way, I realize this code might be hard to see on your screen. I'm uploading it to the course material page. Called ant2.nlogo So you can download it yourself and take a look at it And you will actually be using it to do the homework Alright so now we have to see if this works. Again, ok. It seems to work. Another really handy thing I should tell you about in netlogo. Sometimes netlogo can get stuck where even if you click the go button. It doesn't turn off. Because it is doing so many commands. Up at the tools there is a halt command. which you can use to always stop the program it always works. for stopping the program. It's always handy if for some reason the program gets hung up and you can't just click go again. Ok, let's do an experiment. Let's increase the max steps ize. All the way to ten and see what happens. well alot more seem to get stuck at the edges. And you can play around with these different-- --these three different variables and see how much, how long it takes the total food to get eaten. But what we would like it to do is actually stop when all the food is eaten So we can see exactly how many tics it took for the food to get eaten So I'm going to put a command in there. To do that. So I go here to the go procedue. Here is the command to make it stop if there is not any patches with patch color pea color equal to green. that is they all turn black then we will do this stop So this is the kind of syntax that net logo uses you can do not, you can do any question mark patches with some property and stop. Ok, so let's try all that. Let's set the population all the way to 200 and the step size to four the turn angle to 60 and let's see how fast these ants can eat all the food. They did in only 105 tics. Now, let's save our model by going to the file menu and clicking on save that's the end of our second model.