Introduction to agent-based modeling GIS extension So I am going to talk a bit about the NetLogo GIS extension today, right. The model that I want to talk about is in the models library under IBM textbook chapter eight. And is it called Netlogo ticket or it is called ticket sales right. And this was inspired by the dissertation of Tseng, who was a student at Maryland while I was there. And she was interested in, in working with her dissertation chair Wendy Moe in trying to understand how live event ticket sales affected each other. This model never quite got to the point of really kind of exploring that question in detail from an agent-based model (???) Again her dissertation is much better at that, but it is not agent-based. But it does examine, it is a first attempt at trying to get to that point, right So, in this model, you will notice that it takes a little while to set up and run And that is because what we are going do, is we are actually going to do is pull in data about real geographical spaces. And this was data that was obtained from the Federal government the US Federal government's census. Basically drawn from Tiger which is their tool that provides free data about the census to anyone who goes and logs in essentially . Now some of the data you have to pay for and stuff like that but much of it is free. So what I have done is I pulled in a map of Manhattan with the census boundaries laid out on it. and then I populated each of those census boundaries with a representative agent for every household, actually I think it is like one for every ten households that are in that particular census tract. So, it is kind of interesting just what you see from this right away. For instance, there is no one living in Centreal Park, which runs right down the middle as you might expect, right. And then, what I also have is a venue that I have kind of located in the world, And what this allows you to do is then explore how people decide whether or not they are going to this venue over that venue. and using real demographic data about that particular area. So, in this case, right all of these agents decide that is is worth their time and money to attend. And you can kind of understand how placing different venues might have. and eventually what you'd like to have two venues that compete against each other and maybe provide discounts and offers and things like that. That's how the model runs. Let's pause for a second and I'm going to show you how the code actually works. So, in order to read in a NetLogo extension, you have to start the model code with extensions and the name of the extension, and you saw this a little bit in unit 4 where we went over how to build the viral marketing model. And so in this particular case, I'm going to read in the GIS extension. and that GIS extension is one of the ones that is built into the NetLogo package when you download it. and the first thing it does is call this setup maps command, and the setup maps command actually says 'load using the GIS command dataset, load these shapefiles from a ??? and it's going to put those into variables. And shapefiles, for those who've never played around with them before, are a GIS way of describing polygons, points and lines and how they describe the space of the world. So this describes the roads and the tracks so you can see what's going on. The next thing we have to do, is we have to actually, since the way GIS works is that you all this data about the whole world .... but you only want to look at a particular point part of it. cos you don't want to look at the whole world when we study Manhattan so, what we're going to do is, we're going to set the world what's called the envelope (the space wrapping around the world) and wer='re going to set that envelope to the union of the roads dataset and the census tracts dataset. These have specified envelopes, so there's something that sets the outer limits of the roads and the outer limits of the census tracts. So we're going to take that and we're going to use that to create the union of our system and create the envelope. And then we're going to display the roads and display the tracts and we're going to essentially do those by drawing setting the drawing colour for GIS to red, and tell NetLogo to draw it with a line thickness of 1. And what that does, is actually draw the red lines that you see back here. And in fact we can turn that off and on because of the way we specified that code. Now this is in the drawing layer and so there are few ways to interact with it we can display the tracts and illustrate them as well and we'll show you how to do the interaction in just a bit so one of the things we do, and this is where we do the interaction, is we say 'for each of the tracts ask the patches that are intersecting with that tract to set their tract ID in the patch to the GIS property STFID, which is this tract ID value that is stored in the tract dataset.' so now that we've done that, each patch knows which tract it is attached to in the GIS dataset and when we load the patch data, we're going to the households file, which contains the population for the households in each of the tracts but the most important thing is that we read in that household population and it turns out this GISID2 specifies the census tract that that population is describing. So we can ask the patches that have the tractID that matches that census tract to set their population to read from the string of that population. Now there's one small problem with that, there could be multiple patches in each census tract and we don't want to have multiple accounting by having the population in each of these. So the next line deals with that. It says ask the patches with population > 0, set their population to the population divided by the count of the patches which have the same tract ID. So if I have 2 patches that are in that tract because they have the same tract ID then I actually split the population between the two of them. And so, now, using this final intersection, we've intersected the drawing layer in terms of the tracts with the actual patches. It's this GIS-intersecting that is determining that for us. Then after that, the rest of the code is pretty much standard agent-based modelling code, it's just going to determine the consumers are from the venue, and then make a decision about whether to buy based on that. So, that's it for the GIS extension in the next talk, I'll talk about the network extension