Greetings, John Boward here, with the complexity course We're going to step through some solutions to the... ...final set of problems in the dynamics series at the advanced level... ...and this going to be a lot of fun. We're going to actually build a Net Logo model... ...from scratch and you can see how I approach building models. Of course there's lots of different ways to do it... ...and the most important thing when you begin programming is just to play around and... ...don't be afraid to make lots of mistakes because you that's the only way to learn... ...is from a thousand mistakes. I've been through these models, I've built hundreds and hundreds of models and I'm sure that I'm going to make mistakes... ...building this one... ...but that's just part of programming. Advanced level: we're going to make... ...a model... ...that uses agent-based population growth we're not actually basing it on an equation, we are actually making little entities that... ...reproduce, and we're going to see if we can... ...create a behavior that is what the... ...logistic model of population is... ...purported to be describing. So in a way are coming up with... ...that behavior but deriving it from... ...the actual behavior of agents. So it's kind of interesting philosophically... ...that these kind of models are much more low-level... ...and the actual collective behavior emerges from... ...properties and interactions of the agents. Let's jump into it. So here's Netlogo, the screen you get when you start off. Just a simple interface When I start a new model I always... ...add a Setup button, ... ...typically a Step button, ... ...in a model like this and... a Go button. These, of course, refer to procedures that have not yet been written Also I'm always careful to... ...line things up and leave the same amount of padding between all my buttons... it's just a pet peeve of mine, but that's how I do it. I also label... ...my models so that I can remember what they are... ...in the future. So there we go That's the basics that I do when I start making a model Now let's go. Let's see what we want to do: we want to create... ...a bunch of agents and we want them to... ...reproduce and we're going to plot... ...a graph to see if it looks like that sigmoidal curve. So we're going to plot too. So we'll get the basics out of the way... ...and we'll call this graph... ..."population". We know that ... ...it's going to be a population versus time, it's always a good idea right away to label... ...the... ...axes so you don't forget [typing] [typing] [typing] OK, some of the preliminaries are out of the way. OK. What we're going to do next we're going to actually make a... ...setup module that creates some agents, so let's jump in to the code... ...and we'll say "to setup"... ...and I always write the... ...begining and the end first, because I know we're going to have to do that We know that we want to create a certain number... ...initially. probably we'll have a... ...slider for that but we can just ... ...well let's make a slider right away just so that we get that... ...out of the way too. So go back to the interface. Make a slider and call it... ..."initial-population" ... ... and typically I'll copy that... ...and so we're going to... ...create that many ... ...initial population, and then we have an opportunity to... ...give these ... ...newly created entities some properties, so I'm going to say set their color to... ...green. Set their shape... ...to, say, a circle... ...and set their size... ...to ... let's leave them. Initially they come out sized one Now we'll... ...see a problem with this right away and I just want to... ...show you this, because ... Setup now works and will create 50 individuals by default so what I'm going to... ...do is, I'm going to... ...run Setup and you notice that it... ...looks like there's only one agent was created but actually there are twenty-seven and... ...they're all... ...created right on top of each other... ...in order to get them to move... We would have to go forward, ...we told them to each go forward 10. When we ran Setup, we would see... ...that they would all, since thay have a random heading, they would all move out. That's still not quite what we want, right? it looks... ...too organized and too... ...artificial so also we still haven't gotten rid of our initial... ...one. This reminds me that whenever we do a Setup... ...we almost always start off with the "clear-all"... ...shortcut for that is just "ca"... ...but clear-all will wipe away that. instead of using this create command, which is the... ...easiest way to... ...create a population of agents... ...we're going to use something else and that's the ... ...we're going to ask the patches ...and I'll ask a certain number of patches ask "n-of"... ...initial population... ...some I'm asking that many patches... ...to... "sprout" ...and of course, once I've decided who I'm talking to, I'm talking to patches... ...and what I'm asking them to do is this... "sprout" business saying: "hey you 12 patches... "...each one of you I want you to sprout one and then... "...tell that one to set its color to green, and set its shape to circle" And move forward 10, we don't need that "forward 10" anymore. So let's lust see if this works Sure enough... ... it randomly asks patches, every time you push it,... ...randomly ask a certain set of patches... ...27 in this case, or 80 of them... So now we have an initial population... ...of patches that we can control just with that one line of code. OK, so the next step is to think through: what are we going to want to with these?, We're going to want to... ...ask these ... ...agents, these little green dots,... ... we want them to, basically, reproduce They are going to need to be able to die... . ..because we we want to have non-overlapping generation so ... ...have a parent generation that gives birth to another generation... ...and the parent generation dies off. That means we're going to have to keep track of generations We're also going to... ...need them to spread out, to disperse so that they don't... ...all end up on top of each other and... ...it'll just be easier to keep track of them visually if we have them... ...stand on their own patch. OK. We don't have to have any kind o...f breeding. We could do that but would ...make it more complicated. So let's just see how we do that I'm going to say that... ...each step in time they will reproduce. So... I'm going to say "Step". They will do all the things that they need to do so this is just kind of pseudocode I'm gonna say that they need to... ...reproduce... ...parents need to die... ...and the remaining ones will disperse. There we have it. These are just going to be names for procedures I haven't written yet... ... but this procedure step is just gonna call these procedures so... ...let's think how reproduction is going to work