Hello, everybody. My name is and today, we're going to talk about how to build agent based models in the NetLogo environment. Similar to my introduction in the system dynamics tutorial part, I'm also going to mention that NetLogo is not the only software out there that you could use for building agent based models. There are also other options obviously for example, a commercial ones like Any Logic or any free softwares like Repast or similar to that. But I think NetLogo is a good point to a start. So, let's just go to the website of the NetLogo, and start from how to download it. So, I'm just going to go to Google. And go to the website of the net log on. I'm just going to also add that, in addition to being a software and getting updated very frequently. One of the biggest reason that NetLogo is like more popular than other agent base modeling softwares. Is that it has great resources available. They are very rich in terms of tutorials, course, different materials, even like the forum is very active. So, that's something to keep in mind why NetLogo is probably a better choice in comparison with other softwares. So, downloading should be easy. You just come to the first page and click on Download NetLogo. And probably you want to just stick to the latest version and Click on Download and here you just choose which type of machine you have, either it's Mac or it's just Windows. There are some notes also down here that you can look and they usually change, I don't expect that at the time that you see them it would be the similar notes here. There shouldn't be nothing specific regarding to installation phase unless if you are on Mac, you should also note that it's just type of old school installation, meaning that you need to drag and drop the folder to your application folder. And also, allow for third party apps to be run on your machine. So let's just go back to the home page. And now, what I just want to talk about is just where you can find the pool of resources available for NetLogo. Almost all of them are located here on the link Frequently Asked Questions, if you click on that it goes to a page like this which you can also access the same material when you install the software offline. So you will access to that through that link as well which I will mention later. So here on the left side you have an introduction to NetLogo you can look at that, and I'm going to also suggest you go and do these three tutorials. Which is module, different module, module one, module two and module three. And they're very helpful. And some part of that are kind of very close to what I'm going to do today. But it just start in a kind of very simple step by step way and just move forward and there are also interface guide for the whole software here. And other interesting and useful part is like programming guide that probably you're going to come back later for understanding what are different aspects of the coding part. And also, there is a NetLogo dictionary which is probably the most useful and the one that you are going to come frequently. And, actually here, all of different words and commands of the NetLogo Software are listed and you're going to come back here a lot if you are going to code with NetLogo and you're going to kind of use this as a kind of dictionary to understand what's the meaning of each word or each common. For example, if you click here on the common distance it goes to the meaning of that, an example of how does it work. So now let's just go back to the NetLogo software. And my assumption is that you already have the software installed on your machine. And you open the software and you should have a page like this. So here on the top you have pretty classic menu here on top. One thing that I just want to mention is that here on the help part, if you click here on NetLogo dictionary, it goes to the same page but at your local address. You can see that same material is also available here. And here there's a blank area here that I'm going to talk about it more. So now what I'm going to do is just going to the File menu and clicking on Models Library. And then you will have this dialogue box. And here what you can see is a set of different samples of NetLogo which you can run and just see them by yourself. And they are very helpful, and they are also fun. Because many of those examples are very counter-intuitive. And you don't expect to see what you observe, and there are from different disciplines, from biology here to social science to Earth science, different disciplines. What I'm going to load right now is just traffic model, the same model that I referred in the lecture, the introduction to agent based modeling, so I'm just going to write down the left side here, on the bottom, traffic. And then I'm going to choose this one, Traffic Grid, and click on open. So it's just going to open the sample here for me, and this model is actually about simulating a certain part of a city, for instance that you have kind of several blocks in the city, and there are junctions that are controlled by traffic lights and car move around and there are quickly traffic. Let me just show you what happens. So, in that logo you usually have two classic buttons, one is set up and the other one is go. Setup builds your whole board as we tend to call it. Makes your environment ready. When I click on it, it just creates random configuration for the first initialization. And then, when I click on go, the model simulates. And, you can see that the results are shown here. So let's just start by understanding better of how different things here work. So basically we have three main tabs in each NetLogo model, here on top in the middle, as you can see here is the interface lab that the graphical interface is located. The one the user can work and use that and there is an info tab that usually is used to tell the user how does the model work and how you can use it And what should you kind of try and what's the copyright issues, also code is located on the kind of last part here. Let's just go back to the interface. So here you also have options for adding different components button, sliders, switch. To your model, and also you can change the speed of the simulation here, by this slider. And here is the word that I was talking about. So if you click, if you right click on this area and go to edit, or you can also do it through this setting button if you click on that, this dialogue box will be open. And you can just change the dimensions of your whole port here. And as you can see in this case it's just the 37 to 37 and this means we have this number of piles in our which in the NetLogo language, we tend to call them patches. So patch is basically an s-core block, that when they connect to each other, they build this whole environment, this whole world. So we have this number, 37 multiplied by 37 of them in this world and you can also kind of change other settings here for the world, and in addition to patch, we also have a second major element of NetLogo, which is turtle. So basically, the term turtle in NetLogo language is being used for referring to agents, so they are pretty much the same. So turtles are our agents in the NetLogo environment. And there are some historical reasons for why they are called turtles, but we don't want to talk about them. And as you probably remember from the lecture, agents have attributes. They have different properties. And in this case, we, or turtles or agents are the cars. You can see that these blue cars are our agents. And I can right click on this area. And choose one of those turtles. And if I click on this, and it's a little bit tricky because it's just small, you can just click several times to find one of them. So here, I can come here on the bottom and click on of them. And I have several option. Inspect that turtle. Watch that turtle or follow that turtle. So, let's just click on inspect turtle. And it opens a dialogue box here which shows me that a specific turtle or that specific car in this case. And I can zoom in or zoom out. And. It shows me some standard attributes for the agent, the whole number. Every agent has a whole number, and id that determines which agent is that. Something like a social security number. Some other standard attributes for example x coordination, y coordination, and also here on the bottom we have also some other attributes that the term is what are the attributes that we define in odds model including speed in this case whether is a car going to up or not. A boolean variable and the wait time all of them are defined by the code and these other attributes are those that are available for each agent or each turtle. So you have also two other options of following and watching a turtle and you can kind of play with them yourself, I don't need to describe it to you. So now I just want to introduce you to most important commas in it's logo, the first one is ask, the second one is set. So in order to understand what is asked about I just want to have a kind of different way of saying that so you should think of yourself the one that you are developing the code. The designer as an observer. You should be flat in that logo board and everything you want to have agents to do for you, the turtle to do for you, you should ask them to do for you. You cannot just give a command to them. So ask determines that who is the target of your command. And set is very similar to equal in other programming languages. For example, C family of languages or Java. And set can be used for assigning a value to a variable or changing the value of a variable. And I'm just going to show you how this work in more detail right now. So if you come to here on the bottom left. And you have a comment center here that I would say is very handy. It's just like a terminal that you can use for kind of having commands that different turtles are performing. And what I'm going to do, and I'm going to ask you to do the same, is just go here and click on this empty text box, and type exactly the same thing that I'm going to type. Just write down ask Turtles, Left bracket. Set, color, green, and right bracket. And then hit enter. And you can see here in the model that all of the cars are now green, right? So what happens is that you ask all of the turtles, all of the agents in your model as an observer. To change their color to green. But, if you haven't used "ask" in your command, what would have happened? Let's just see. If I say set color green and I hit Enter, it's just going to show me an error saying that you cannot use color in an observer context because color is turtle/link-only. What I can do is just come in here and clicking on observer and changing it to turtles. And this time, it only work for turtles. Let's just make it a different colors so that you can notice that. For instance yet like yellow And hit Enter, and now we can see that all of them are turned into yellow. So if you're going to talk more about the difference between observer and turtle mode and patch mode more, and I would say that's just kind of a tricky part for beginners on NetLogo. And I guess it's also at this point to mention that you shouldn't be scared by the programming part of NetLogo, because it's just easier than regular programming languages, let's say Java, Python, C++. Because if you look at the origin of the whole language it was meant to be closer to how humans actually think And the code is supposed to be innovated. When you read that, you are able to understand it, similar to a textbook. So in that case, the writing in NetLogo, and learning to write in NetLogo, is much easier than other programming languages. So now, let's just work on some simplest steps of understanding basics of coding. And what I'm going to do is just kind of go in here to the File menu, and clicking on New part to kind of create. I don't need to Save it, Discard. It should just create a new model from scratch. And through that I'm just going to show you what are the basic elements of the NetLogo model, a typical NetLogo model. So basically we have two buttons in any NetLogo model. In order to add those models, I'm going to come here and click on this cross sign. And then button is already chosen, so I'm going to come here on the empty area and click, and then it prompts me for naming of a command. So here, I'm going to add the first button which is going to be set up, and that's all I want to have for now. And when I hit Enter, you notice that it's just red, the texts here and here are red, which if I go and right-click and then click on Edit, it just shows me the error. It says that nothing named SETUP has been defined. And if you notice, it needs a command that has the same name to go and refer to that. So I'm going to do that right now, and I just want to have you do exactly the same thing. I'm going to click on Okay, I'm just going to go here on top, click on the Code tab. And here I'm going to start with the word, to, so every procedure in the NetLogo world starts with the word, to. And then to setup, and then hit Enter. So to says that here is where the procedure starts, and then end tells to NetLogo where does it end. So this is the procedure that I needed. So now if I go back to interface, you will notice that it's not red anymore. There is a procedure that I defined for setup. Although there is nothing inside that, but there is a procedure with the name of setup. Let's just go back to code and work on it more. So I'm just going to come here and add more elements to this procedure. So first thing I just want to make sure is just there is nothing from before runs, so I'm going to say clear-all. It's just kind of classic way of doing that in NetLogo. And also I'm going to say reset-ticks. And, hit Enter. So, for setup, I just want to have NetLogo create a number of turtles for me. Let's say 20 of them. So, the command that I'm going to use is create- turtles. And let's just have 20 of them, okay? And one thing that I just want to mention is that you'll probably notice that the color of this text gets changed. And different colors are used for the words that NetLogo actually knows. For example, orange is being used for numbers, and the only exception is that if there is anything from your part all of them will be in black color. For example, setup which is the kind of optional name that I use. So let's just go back to the interface part and see what does it do. So if I click on setup now, it's just going to run the setup procedure. So if I click on that, you can see that 20 of different turtles are created. And since all of them by default are started from the center, or from the origin of the word, they're all located on top of each other, so you cannot differentiate among them. So I'm just going to go here, and move them to random locations by doing that. So I'm just going to type a left bracket and right bracket, so everything inside these two brackets are going to be run when turtles are being created. So I'm just going to have set x coordination to a random number. For instance, random between 0 and 16, which would be random 16. And then, similarly, set y coordination between 0 and 16. Now, let's see what happens. And here you can see that it just shows me an error that this is not correct, and actually NetLogo doesn't recognize that. So I'm just going to correct that. So, every time that you move between interface and code by default, NetLogo tries to compile your code. And if there is an error, it will just show it to you. So, now let's just click on the top, and you can see that all of them are here located on top right. But they have random direction. So far we had everything for setting up our environment, and now it’s just the time to add the second button that I was talking about, that usually all of NetLogo models have, and that is the bottom for simulation. It’s starting to simulate. So I'm just going to do the same procedure, here clicking on Add and button is already selected. And clicking here, this time I'm just going to call it go. And for go, I'm going to also select the Forever here, and you can notice that here this tiny icon is added to the button. And it means that NetLogo will be running the same procedure indefinitely until the user tells NetLogo not to do that anymore. And I'm just going to hit OK. And if I just want to move it, I can just click here and grab it and bring it on the top. And let's just go and add code to the go procedure. So the same procedure here again, Enter, to go. Enter, end. And for the go part, let's just have a simple task that we want edges to do. And for that part, let's say they just move randomly. And I'm just going to have turtles to just kind of go forward by one step. So I'm just going to enter forward 1. And in order to compile your model, to make sure that the grammar of your code is right, I can also click here on Check. And you can see that it's still red, so let's see what's the problem. I'm just going to click here and go to Edit, and it says that you cannot use GO in an observer mode. I should have done that by purpose because I just want to show you that these are common problems. So, why this happened just say that goal is turtle only. Why is that telling me that? Let's just go and figure out. So, its because I didn't ask them to do that, forward is only specific to turtles, and you should remember, if you as an observer, as a developer want then to do something you should deploy it and you should ask them. So, let’s just do that. Ask turtles bracket, And now, it should be fine. So let's just run the model again. Setup, go, and you can see that there are moving toward different directions, very randomly. It just make it a bit slower. So ,the next thing that I'm going to add to the model is the, lets just pause it for a second. It's just the idea of time, because every agent based model or most of agent based model have the component of time. And as you notice here on the top, ticks are shown. And ticks the smallest step of simulation you have. So here, I'm going to go, to go and add the comma tick. And this comma, is going to tell to net logo that increase the tick number by one. So, let's just see what happens. And you can see that now when I click on Go here on top the number of things are increasing constantly So, let's just stop it. So the next element that I wanted to add, is just an extra processor to the whole code. Let's just go back to the code and add the processor that have them changing the direction. So what I want them to do, is that instead of just moving constantly to the same direction, I just want to have them to change their direction. So, in order to add an extra procedure similar to setup and go. Here, I'm going to come on the very end and enter to the name of my procedure for instance, change direction. Change direction and end and I'm going to say with the probability of 50, they're going to turn to right with the same probability, they're going to turn to left. So, I'm going to write ifelse, and notice the syntax here, ifelse is used for logical type of commands, if else. And one way of making a probability working like 50%, is by doing it this way. I'm going to say a random number between 0 and 100 and if it's lower, and if it's smaller than 50, then turn right. So, I'm going to use again brackets. So this is if part, if that number that random number is smaller 50, then turn right. I'm going to say, "right 90", and 90 means degree and else, turn left, "left 90". And, I just want to also mention one really important thing is that I completely understand that probably I'm going fast, and for many of you it's just hard to understand some of these elements. But it's also important to know that I don't mean that you learn every single aspect of what I'm doing right now, but I'm just trying to expose you to some of these ideas and later you can do your own homework, if you're more interested, invest more time. So now, let's just use this processor first, indigo. So, I'm just going to have turtles to go forward by one step and then change direction this way. Change-direction and let's just make it kind of nicer by clicking here-enter, here-enter and here-enter. And I can select all of these and select tab on the keyboard, and you can see that it just adjusts all of the text here for me. So, let's just go back to the code and see what happens now. I'm going to click Setup and Go and you can see that the direction of turtles is changing. So now, let's just think about another scene, so what I'm going to do now is just adding attribute for turtles by doing it this way. I'm going to write down here turtles-own. And here, I'm going to say, for example, the number of walks, walks-number and close bracket. And here, in this bracket of by using turtles own, I'm adding an attribute, if you remember from or lecture on agent based modelling, we needed to define attributes for each agent and turtles own is used for that. And here, I'm just going to also use semi colons to add a comment to the whole thing, for example, the number of walks from the beginning. And it's just very good practice to always have very useful and helpful comments, so that other people can also understand your code. So in that logo, you do that with semicolon. And now, I'm just going to have turtles to show their walk numbers this way, by clicking here. Just, let's just make sure that the walks number are equal to zero at the beginning here, when the setup is run, I'm just going to say ask turtles set walks number zero and then every time, every tick they're going to add one. Set walks number equal to walks, number plus one. So, I'm just going to change the value of this variable to this right side. Box number is now called to box number plus one. Every tick, it would be increasing by one. I'm just going to have them showing that. By saying that set their label, the label of turtles as box number. And now, let's just go and see what happens. So here, setup first and go, and you can see that the number of bugs are shown as they move around. So, let's just make it faster. So, pause for now, and another important thing that I just want to cover today is just global variables. Global variables are actually variables that are accessible to the whole code, and they are defined this way. Globals, and then here I'm just going to assume, for example, the day number, and this variable is accessible to the whole quote turtles and patches, everything inside the quote. And here, I'm just going to assume that every four ticks is equal to one day in my simulation by saying that, if remainder ticks four equal to zero, then it says that if the remainder of division of ticks and four while equal to zero, then set day plus one. It means that every four ticks is equal to one day, and I'm going to also show day in my code, and I'm going to show day also in my interface. So, I'm going to go back to Interface, come here and click on, for example, Monitor and add it here by clicking here. I just want to show the value of day. Clicking on OK, let's just see what happens now. Setup, go, and you can see that the number of days are one-fourth of the numbers of ticks. That's all probably for now, what I just want to show you, but I'm just going to encourage you to spend more time to think of other things that you can add to your program. In the next part of our tutorial, you're going to go further in depths of programming and work with the models that are more related to the opacity part. Thank you.