1 / 8

_Strumenti, seguito

_Strumenti, seguito. _______________________________________ Un modello di riferimento: cocktail party (model library, prove pt/party_pt) party_pt.nlogo, in linea a web.econ.unito.it/terna/materiale/master_ec_pol_san/ _______________________________________.

trista
Download Presentation

_Strumenti, seguito

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. _Strumenti, seguito _______________________________________ Un modello di riferimento:cocktail party (model library, prove pt/party_pt) party_pt.nlogo, in linea a web.econ.unito.it/terna/materiale/master_ec_pol_san/ _______________________________________ Master in economia e politica sanitaria - Simulazione per la sanità

  2. ;The 'turtles-own' keyword, like the globals, breed, <BREED>-own, and patches-own keywords, ;can only be used at the beginning of a program, before any function definitions. ;It defines the variables belonging to each turtle turtles-own [man? woman? happy?] patches-own [men women people] globals [boring-groups moves number-happy group-sites] to setup ca ; 'with' takes two inputs: on the left, an agentset (usually "turtles" or "patches"). ; On the right, a boolean reporter. set group-sites patches with [group-site?] set-default-shape turtles "person" ; 'cct' create-custom-turtles cct number [ ;;blue represents male, pink represents female. No stereotypes are meant ;;to be promoted. Simply change the colors right here if you'd like. Master in economia e politica sanitaria - Simulazione per la sanità

  3. ;ifelse reporter [ commands1 ] [ commands2 ] ifelse (random 2 = 0) [set man? true set woman? false set color blue] [set man? false set woman? true set color pink] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left set ycor 0 set xcor random world-width ] ; These reporters give the total width and height of the NetLogo world. ; Screen-size is the same as ((2 * screen-edge) + 1) ask turtles [move-into-groups] setup-patches setup-plots set moves 0 update-labels spread-people update-plots end Master in economia e politica sanitaria - Simulazione per la sanità

  4. to setup-patches ask patches [ set men 0 set women 0 set people 0] ask turtles [ if man? [set men (men + 1)] if woman? [set women (women + 1)]] ask patches [ set people (men + women)] update-happiness update-boring-groups end to go if (number-happy = number) [ stop ;; stop the simulation if everyone is happy ] group-people ;; put all people on the x-axis update-happiness move-if-unhappy update-boring-groups update-labels spread-people ;; move the people into vertical columns set moves (moves + 1) update-plots if limit-speed? [ wait 0.75 ] ;; keep the spread groups on the screen for a bit end

  5. to update-labels ask group-sites [ set plabel count turtles-here ] ; plabel is a pattch label ; turtles-here reports an agentset containing all ; the turtles on the caller's patch (including the caller ; itself if it's a turtle). ; count agentset reports the number of agents in the given agentset end to update-happiness ask patches [ set people (men + women)] ask turtles [ ;;; you are happy if the proportion of people of the opposite sex does not exceed your tolerance if man? [ifelse (women / people) > (tolerance / 100) [set happy? false] [set happy? true]] if woman? [ifelse (men / people) > (tolerance / 100) [set happy? false] [set happy? true]] ;; if (happy? = true) [set num-happy (num-happy + 1)] ] set number-happy count turtles with [happy?] ;; update number-happy variable end Master in economia e politica sanitaria - Simulazione per la sanità

  6. to move-if-unhappy ask turtles [ if (not happy?) [ifelse man? [set men men - 1] ;;decrease the count in your old group [set women women - 1] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left fd 1 ;; move out of your group move-into-groups ifelse man? [set men men + 1] [set women women + 1]]] ;;increase the count in your new in group end to move-into-groups ;;turtle procedure ; move forward until you hit the closest group if not group-site? [ fd 1 if limit-speed? [ wait 0.1 ] ;; slow it down so user can see it happening move-into-groups] end Master in economia e politica sanitaria - Simulazione per la sanità

  7. to-report group-site? ;; turtle or patch procedure ;; if your pycor is 0 and your pxcor is where a group should be located, ;; then you're a group site (patch) or on a group site (turtle) locals [group-interval] ;; first figure out how many patches apart the groups will be set group-interval floor (world-width / num-groups) report ;; first check pycor (pycor = 0) and ;; then check if the distance between groups divides evenly into ;; our distance from the right hand edge of the screen (((max-pxcor - pxcor) mod group-interval) = 0) and ;; finally, make sure we don't wind up with more groups than ;; the user asked for (floor ((max-pxcor - pxcor) / group-interval) < num-groups) end to update-boring-groups ask group-sites [ set plabel-color white if people > 0 [if ((men = 0) or (women = 0)) [set plabel-color gray]]] set boring-groups (count group-sites with [plabel-color = gray]) end Master in economia e politica sanitaria - Simulazione per la sanità

  8. to setup-plots set-current-plot "Happy Partygoers" set-plot-y-range 0 number end to update-plots set-current-plot "Happy Partygoers" set-current-plot-pen "Happy" plot (count turtles with [happy?]) set-current-plot "Single Sex Groups" plot boring-groups end ;; spread people out vertically to spread-people ask turtles [ifelse man? [set heading 0 fd 2] [set heading 180 fd 2] jump count other-turtles-here] ;; this trick works because of the serial ordering of turtle execution ; 'jump': turtles move forward by number units all at once, without the ; amount of time passing depending on the distance. end ;; pile people up on the x-axis to group-people ask turtles [set ycor 0] end Master in economia e politica sanitaria - Simulazione per la sanità

More Related