CS108L Computer Science for All Week 6 Video Summary Abstraction in Modeling and Simulation • Abstraction is Simplification ▫ Why? • “Real world” problems are too complicated • Must simply in order to model • Ignoring some details or parts so that you can focus on what is important to you at that time. • As your interests change the amount of abstraction you need can change too. ▫ Involves assumptions (things that you take to be true). • Before abstraction • During abstraction • After abstraction during model development • Assumptions are what the modeler assumes when moving from the real world problem to a model. • Sometimes a simplification • Sometimes a specification • Assumptions need to be carefully considered • Affect the outcome of the model • Should be validated Variables and Scope Variable • A container that holds a value that can be used and changed. • Three Steps for Using Variables ▫ Declare – allocates the space and sets the variable name ▫ Initialize – set the initial value of the variable ▫ Get/Set– Use or change the value as the program is executed • There are three types of NetLogo variables / they differ in scope • Local Variables– used in the block where declared • Agent Variables– used by specific type of agents • Global Variable– used anywhere in the program • Local Variables • Can only be used in the procedure or command block where it is declared • Can be used by any agent • How to Use: ▫ Declare and initialize local variables using the let command ▫ Use the local variable in an expression or ▫ Modify a local variable using the set command Document1 • Agent Variables ▫ Three types of Agent Variables Turtle Variables • Each turtle has its own value for every turtle variable Patch Variables • Each patch has its own value for every patch variable Link Variables • Each link has its own value for every link variable • • • • Built-In Agent Variables ▫ Some agent variables are built-in to NetLogo Turtles: color, heading, xcor, ycor, etc. Patches: pcolor, pxcor, pycor, etc. Links: color, shape, etc. User-defined variables ▫ Can make user defined agent variables by declaring them at the beginning of the program turtles-own [ energy ] patches-own [ grass? ] links-own [ strength ] How to use an agent variable ▫ Declare the agent variable if necessary (do not declare built-in variables) ▫ Change/modify the variable using the set command ▫ Generally can only be used/set by the specific agent Turtles Turtle Variables Patches Patch Variable Link Link Variables Exceptions ▫ An agent can set a different agent's variable by using the ask command. ask patches [……. ask turtle 5 [ set color blue] ;; changes turtle 5’s color to blue …] ▫ One agent can read another agent’s variable using the of command show [color] of turtle 5 ;; prints turtle 5’s color ▫ A turtle can read and set patch variables of the patch it is standing on directly ask turtles [set pcolor blue] ;;makes patches under all turtles blue Global Variables • The is only one value of each global variable at any time • You can declare a global variable by ▫ Using an input device on the interface tab (switch, slider, chooser or input box) ▫ In the code by using the globals keyword at the beginning of the code Document1 globals [NumTurtles] • • Can be used ▫ At any location in any procedure in the code ▫ By any agent ▫ Use by using the variable name Modified by using ▫ In the Code, with the set command set NumTurtles 100 ▫ On the Interface tab with switch, slider, chooser or input box Interface Input in NetLogo • Can input Global Variables from the Interface tab of NetLogo ▫ A quick way to change variable value ▫ No recoding • Four ways: ▫ Sliders ▫ Switches ▫ Choosers ▫ Input Boxes • Sliders ▫ Slider sets a global variable value to a NUMBER ▫ Slider has a range of values • from the minimum value • to the maximum value. ▫ Move the slider to the desired value • Increase by moving the slider to the right • Decrease by moving to the left ▫ The current value of the variable is given on the right below the sliders • Switches ▫ Switches are used to set the global variable to a boolean value (On/Off) • Choosers o Can set the Global variable to be any data type: strings, numbers, booleans, or lists. o Lets you choose from a list of choices. o List is in a drop down menu. Input Boxes o Input Boxes are used to enter the value global variables that contain strings, numbers or colors. • Strings can be • simple strings • commands/reporters (checks syntax) • Any type number can be entered (more variety than sliders) • Color input boxes offer a color chooser using the NetLogo color table. Document1 Interface Output in NetLogo • Gathering data is an important part of modeling • Easiest to Output to the Interface Tab • Four ways/locations ▫ Monitor ▫ Graph ▫ Command Center ▫ Output Area • Monitor • Outputting to a Monitor is easiest. • Requires no in-code output commands • Just need the variable name • Outputs the value of a variable • Updated continuously as the model runs • Graph • Outputting to a Graph is slightly harder but… Can output more than one variable at a time A line for each variable Graphical information can be easier to understand Provides a history of output • Outputs the value of an variable • Updated continuously as the model runs Document1