Presentation is loading. Please wait.

Presentation is loading. Please wait.

M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz www.iemar.tuwien.ac.at.

Similar presentations


Presentation on theme: "M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz www.iemar.tuwien.ac.at."— Presentation transcript:

1 M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz www.iemar.tuwien.ac.at

2 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 2, © 2011, Technical University Vienna.Today Filling the academical quarter: What to do if things go wrong (debugging) Followed by: You might get more than one value More neighbors and interactions Making code more readable and re-usable

3 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 3, © 2011, Technical University Vienna.Debugging Today meaning „to fix software errors“ Previous meaning: Grace Hopper, 1947, Logbook Mark II: „Relay #70, Panel F (moth) in relay.“, National Museum of American History, Washington Rear Admiral Grace Hopper, US Navy

4 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 4, © 2011, Technical University Vienna. NetLogo debugging capabilities...are astonishingly limited: print value… prints a value to the command center area, e.g. Concatenation may happen for adding a pre- or suffix to the printed value, using the (word … ) command: ask turtle 0 [print shape] print (word „The shape is “ shape)

5 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 5, © 2011, Technical University Vienna. Further debugging… ask turtles with […] [ print ] watch turtle 0 watch one-of turtles self reports the breed followed by the who number of the turtle, (e.g. „turtle 0“) watch puts a shiny spot around a turtle if you want to watch one randomly chosen agent out of a population, you can use the reporter one-of in fact, one-of is a general command for choosing one member of a population self one-of watch

6 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 6, © 2011, Technical University Vienna. Querying somebody else‘s properties Often, you „are“ observer or a specific turtle or patch. Querying somebody else‘s values can be done using of: of is used to access a property of an entity given by you. Examples: print [shape] of turtle 0 print [pcolor] of patch 0 0 ask patch 0 0 [ set pcolor [pcolor] of patch 1 1 ]

7 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 7, © 2011, Technical University Vienna. Comparing ask and of ask patch 0 0 [ print pcolor ;you are patch 0 0 ] ; you are observer print [pcolor] of patch 0 0 ask enters an entity. Therefore, can access a property by giving its name (e.g. print pcolor) of accesses a property of an entity you give – you need not be „inside“ the entity Hint: yes, of is a reporter, you might have guessed it!

8 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 8, © 2011, Technical University Vienna. Using of for debugging Add a monitor to the Interface In the appearing dialog, you can type any query. Type the following query and hit OK: The result of this query will be shown in the textfield of the monitor.

9 TOWARDS DEMOGRAPHIC DATA

10 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 10, © 2011, Technical University Vienna. You might get more (than one value) In a new newtlogo model, create five turtles Then, monitor the following: What you got is a list, used by netlogo to give you „more than one value“ Hint: The funky animation happens because the monitor runs over and over again, and [color] of turtles gives you the colors in randomized order. [color] of turtles

11 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 11, © 2011, Technical University Vienna. List are for… e.g. storing change of mortality as time-series or, as netlogo code: 15141613141514 item 0item 6 … let mortality (list 15 14 16 13 14 15 14 ) print mortality (list )

12 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 12, © 2011, Technical University Vienna. How to add a value a list … by the way, there is also that adds a value to the start of a list 15141613141514 let mortality (list 15 14 16 13 14 15 14) set mortality lput 13 mortality print mortality lput item 7 1313 fput

13 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 13, © 2011, Technical University Vienna. Further list commands (see Netlogo Dictionary) get the first item: get the last item: omit the first item: omit the last item: is the list empty? get item 3 of the list: get number of items: set mortality but-first mortality but-first set mortality but-first mortality but-last print first mortality first print first mortality last print empty? mortality empty? print 3 mortality item print mortality length

14 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 14, © 2011, Technical University Vienna. remove item 3: remove item with value 15: remove duplicates: replace item 3 by value 15 sort the list (ascending): set mortality remove 15 mortality remove Even further… set mortality but-first mortality remove-duplicates set mortality remove-item 3 mortality remove-item set mortality replace-item 3 mortality 15 replace-item set mortality mortality sort

15 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 15, © 2011, Technical University Vienna. And further… Add a plot to your model…

16 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 16, © 2011, Technical University Vienna. Histograms act on lists In hospital-1.nlogo, type the following into observer>: …to get the list of population sizes per patch. then type the following: print [popul] of patches set-histogram-num-bars 3 histogram [popul] of patches set-histogram-num-bars histogram

17 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 17, © 2011, Technical University Vienna. Calculations on lists remember from last lecture: to total-population let total 0 ask patches [ set total (total + popul) ] ; total now contains the ; sum of all popul end let mylist [popul] of patches let total mylist see how easy the same is done using lists sum maxminmedian variance…

18 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 18, © 2011, Technical University Vienna. Storing lists globally, step 1 …so they are available everywhere in a program („global variables“ or simply globals) Look at the newly introduced global with: globals [ mortality ] (standard value for globals)

19 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 19, © 2011, Technical University Vienna. Storing lists globally, step 2 in setup, fill the global in go, use it globals [ mortality ] to setup set mortality (list 15, 11, …) end to go ; get mortality at time ; = how many % of turtles die end ticks tick

20 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 20, © 2011, Technical University Vienna. From where do I get list values e.g. data.wien.gv.at (list 15.5 …) © data.wien.gv.at

21 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 21, © 2011, Technical University Vienna. Big Picture  Lists Patches holding population The World consisting of initial population Turtle of breed hospital hosting other Turtles of breed hospital demographic development Lists Color Maps

22 MORE NEIGHBORS

23 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 23, © 2011, Technical University Vienna. Neighbors on the same patch ask turtle or patch [ get all other turtles at this spot … ] A turtle or patch wants to know which turtles stand here Should also be able to select other breeds than turtles Reported entities should be „all on this spot, excluding caller“

24 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 24, © 2011, Technical University Vienna. How it is done… … ask turtle 0 [ ask [ print self ] ask patch 0 0 [ ask [ print self ] turtles-here is a reporter giving all agents on the current spot as agentset if the caller is an agent, he can exclude himself by using „other“ may specifically target other breeds than turtles using breed-name-here (e.g. other persons-here) otherturtles-here

25 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 25, © 2011, Technical University Vienna. What about social neighbors? Concept: Link two turtles together to signify a relationship between them Should be able to query for „the turtle at the other side of the link“

26 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 26, © 2011, Technical University Vienna. Introducing links Links are an own breed, which is created by a turtle: Any breed can be linked. Links can be both directed and undirected, although we will only cover the latter ones in this tutorial (refer to NetLogo Dictionary for directed ones). Furthermore, you can create breeds of links, which is also not covered in this course. ask person 0 [ create-link-with turtle 1 ] create-link-with

27 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 27, © 2011, Technical University Vienna. Get social neighbors… ask person 0 [ create-link-with turtle 1 create-link-with turtle 2 ] ask person 0 [ ask link-neighbors with […] [ print self ] link-neighbors reports all turtles connected to the current turtle by a link as always, this agentset can be further narrowed down using with[…] link-neighbors

28 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 28, © 2011, Technical University Vienna. Co-create social neighbors breed [persons person] … create-persons 1 [ let holder self create-turtles 1 [ create-link-with holder set xcor random-xcor set ycor random-ycor ] Wish to create persons and turtles at the same time, tied together (Note: it is a house- trained turtle we create). turtle is created by the person using hatch-breed, which is just like create- turtles (but can be used by turtles) laying the turtle on the person‘s lash is done by creating a link to the holder hatch-turtles

29 MORE INTERACTIONS

30 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 30, © 2011, Technical University Vienna.Usage ask turtle 0 [ ask patch 0 0 [ … ] An agent wants to interact with other agents or patches, probably exchanging some values In the course of the interactions, multiple nested asks are used, i.e. the first entity is asked, to… ask a second entity, to… do something

31 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 31, © 2011, Technical University Vienna. How it is done… ask turtle 0 [ let the-turtle self ask patch 0 0 [ set pcolor [color] of the-turtle ] 1.The caller temporarilly stores himself in a local variable 2.Then, the patch is asked 3.Inside the ask, a property of the caller is retrieved using of 4.This value is then assigned to a property of the patch ask color pcolor is set to

32 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 32, © 2011, Technical University Vienna. Hands on: Dropping a value turtles-own [ carries ] patches-own [ stores ] to setup ask patches [ set stores 0 ] create-turtles 1 [ set carries 10 ] end stores = 0 carries = 10

33 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 33, © 2011, Technical University Vienna. Hands on: Dropping a value to go ask turtles [ forward 1 if carries > 0 [ set carries (carries - 1) let the-turtle self ask patch-here [ set stores (stores + 1) set pcolor [color] of the-turtle ] end patch-here reports the patch under the turtle

34 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 34, © 2011, Technical University Vienna. Hands on: Retrieving a value turtles-own [ carries ] patches-own [ stores ] to setup ask patches [ set stores 10 ] create-turtles 1 [ set carries 0 ] end stores = 10 carries = 0

35 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 35, © 2011, Technical University Vienna. Hands on: Retrieving a value to go ask turtles [ forward 1 if [stores] of patch-here > 0 [ set carries (carries + 1) ask patch-here [ set stores (stores - 1) ] end

36 MAKING CODE MORE {RE}- USEFUL

37 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 37, © 2011, Technical University Vienna. A tale of users and programmers User of sin to setup print sin 30 end Programmer of sin to sinus (x) 1. 2. give back result to user end We have seen how to use reporters As mentioned, „something is being done behind the scenes“, i.e.  the parameter or parameters are passed into a reporter  this is used like a variable  the result is given back to the user

38 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 38, © 2011, Technical University Vienna. Don‘t be a user – write reporters yourself you can write reporters yourself: beneficial for „hiding the details“ of your model: to-report add [x y] let result (x + y) report result end Usage: to-report name [ parameters ] ; calculate something here ; using the parameters report result end to-report water-patches report patches with [pcolor = SKY] end optional to setup print water-patches end no parameters specified

39 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 39, © 2011, Technical University Vienna.Parameters …can also be used in procedures, by the way: to move-turtles [ in-direction how-far ] ask turtles [ set heading in-direction forward how-far ] end

40 Wurzer/Lorenz: „4D Simulation im Planungsprozess“, Lecture Notes, Slide 40, © 2011, Technical University Vienna. Recap – When to use what Write a procedure to group code lines together under a sounding name (e.g. move-turtles) Write a reporter to perform a calculation and return the result to the user (e.g. add) Use parameters whenever your code depends on values that need to be supplied by the user. Hint: Think of parameters as local variables, which are not defined using „let“ but given at the start of your procedure or reporter.

41 THANK YOU !


Download ppt "M10 WS11:Krankenhausbedarfsplanung More, More and Even-More More given by Gabriel Wurzer and Wolfgang E. Lorenz www.iemar.tuwien.ac.at."

Similar presentations


Ads by Google