pno v3

No preview image

1 collaborator

Default-person Taiyo Sogawa (Author)

Tags

(This model has yet to be categorized with any tags)
Model group EECS 372-Spring 2011 | Visible to everyone | Changeable by the author
Model was written in NetLogo 4.1.3 • Viewed 99 times • Downloaded 17 times • Run 0 times
Download the 'pno v3' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This section could give a general understanding of what the model is trying to show or explain.

HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.

HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.

THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed[patrons patron]
breed[vacancy-lights vacancy-light]
breed[trains train]

patrons-own[hunger searching eating returning bypassing R0x R0y R1x R1y R1p]
patches-own[capacity taste patronage restaurant?]
globals[rush-countdown]

to setup
  ifelse two-dimensional?
  [setup-2D]
  [setup-1D]
end 

to setup-1D       ;; setup the environment
  ca
  set rush-countdown 1000
  
  ask patches[
    set pcolor white
    set restaurant? 0
    if(pxcor = -7)[set pcolor 17]
    if((pxcor > -7) and (abs(pycor) = 2))[                       ;; setup restaurants  1-D for this first model
      set restaurant? 1
      set pcolor lime
      set patronage 0
      set taste random 100
      set capacity  (random capacity-variation) + (average-capacity - (capacity-variation / 2))
      if(capacity < 1)[set capacity 1]
    
      sprout-vacancy-lights 1[
        set shape "square"      ;; this will act as the restaurant's vacancy light!
        set color white
        set size .8
        set label-color black
      ]
      ]
    if((pxcor > -7) and (abs(pycor) > 2))[set pcolor brown]    
    if((pxcor = -7) and (abs(pycor) < 2))[set pcolor blue]         ;; setup home base for turtles to live between meals
 
     
     
       if((pxcor = -7) and (pycor = 0))[
        sprout-trains 1[
          set shape "train passenger car"
          set color gray + 3
          set size 2
          set heading 0
        ]
    ]   
    ]
  
  
  
  create-patrons number-patrons[
    setxy -7 0                  ;; have the turtles start out at their home base
    set shape "person"          
    set heading 90
    set hunger random 100
    set R0x 0
    set R0y 0
    set R1x 0
    set R1y 0
  ]
end 


;==============================================================TO SETUP-2D===========================================================

to setup-2D       ;; setup the environment
  ca
  set rush-countdown 1000
  
  ask patches[
    set pcolor white
    set restaurant? 0
    if(pxcor = -7)[set pcolor 17]
    if((pxcor = -7) and (pycor = 0))[
        sprout-trains 1[
          set shape "train passenger car"
          set color gray + 3
          set size 2
          set heading 0
        ]
    ]
    
    
    
    if((pxcor > -6) and ((pxcor mod (7 - N-S-street-density)) != 0) and ((pycor mod (7 - E-W-street-density))!= 0))[                       ;; setup restaurants  1-D for this first model
     
     ifelse(random 100 < restaurant-density)[
      set restaurant? 1
      set pcolor lime
      set patronage 0
      set taste random 100
      set capacity (random capacity-variation) + (average-capacity - (capacity-variation / 2))
      if(capacity < 1)[set capacity 1] ;make sure each restaurant has at least capacity of 1
      sprout-vacancy-lights 1[
        set shape "square"      ;; this will act as the restaurant's vacancy light!
        set color white
        set size .8
        
        set label-color black
      ]
      ]      
     [
       set pcolor brown
       
       
       ]
    ]
    
    
      
    if((pxcor = -7) and (abs(pycor) < 2))[set pcolor blue]         ;; setup home base for turtles to live between meals
 
  ]
  
  ask patches with [restaurant? = 1][
    if ((count neighbors4 with [pcolor = white]) = 0)[         ;; if they have no street access, don't make them a restaurant
      set pcolor brown
      set restaurant? 0
      ask turtles-here[die]
    ]
    
  ]
  
  
  create-patrons number-patrons[
    setxy -7 0                  ;; have the turtles start out at their home base
    set shape "person"          
    set heading 90
    set hunger random 100
    set R0x 0
    set R0y 0
    set R1x 0
    set R1y 0
  ]
end 

;==============================================================TO GO==================================================================

to go
  check-rush
  
  ask patrons[
    check-bypass
    check-eating
    check-hunger
    check-returning
    check-searching
    if(random 100000 < patron-turnover) [die]
   
  ]
  
  ask vacancy-lights[
    check-capacity
  ]
  
  ask patches[
    update-patronage
  ]
  
  ask vacancy-lights[
    set label [patronage] of patch-here
  ]
  
  ask trains[
    move
  ]
  
  update-charts
end 


;====================================================================================================================================

to check-location      ;; check if this is somewhere the turtle wants to eat
  if([restaurant?] of patch-here = 1)[
    ifelse(random 200 < hunger)       ;; the hungrier the turtle is, the more likely it is to enter a restaurant        
    [enter-restaurant]      ;; if the turtles are on a restaurant and like it, they will stop searching. Otherwise, turn around                  
    [keep-searching]
  ]  
  if([pcolor] of patch-here = brown)[keep-searching]
end 

to check-eating
  if(eating = 1)[
    set searching 0
    set hunger (hunger - 5)   ;; while eating, the turtle becomes less hungry
    if(hunger <= 0)[
      set eating 0     ;; no longer hungry
      set returning 1
     
    ] ;; when the turtle is no longer hungry, it will return home
  ]
end 

to check-hunger
  if((hunger > 100) and ([pcolor] of patch-here = blue))[ 
    
    ifelse((random 2 < 1) and (R1y != 0))       ;; choose if the turtle is going to search, or go straight to it's favorite restaurant
      [set bypassing 1]
      [set searching 1]
   ]
  set hunger (hunger + 1)    ;; every tick the turtle gets more hungry
end 

to check-returning
  if(returning = 1)[
    facexy -7 0
    fd .2
    if([pcolor] of patch-here = blue)[set returning 0]
    
  ]
end 

to check-searching
  if(searching = 1)[
  set heading (heading + (random 25) - (random 25))     ;; have the turtles wiggle, then move forward
  if(xcor < -6)[set heading 90]                         ;; if turtle is out of bounds, send them in the right direction
  fd .1
  check-location
  ]
end 

to check-bypass
  if(bypassing = 1)[
    facexy R1x R1y
    fd .1
    if(([pxcor] of patch-here = R1x) and ([pycor] of patch-here = R1y))[enter-restaurant]
   
  ]
end 

to enter-restaurant
  
  if(([pxcor] of patch-here = R0x) and ([pycor] of patch-here = R1y))[
    keep-searching];; if this is a restaurant the turtle dislikes, keep searching
  
  
  
  ifelse((count patrons-here) > ([capacity] of patch-here))   ;; make sure the restaurant hasn't reached capacity. If it has, we continue searching
  [
    
    keep-searching
  ]
  [
  set bypassing 0 ;; no longer in bypass mode
  set searching 0  ;; no longer in search mode
  set eating 1   ;; we found the restaurant, we're happy!  
  ask patch-here[
    set patronage patronage + 1
    if(pcolor > 60)[
      set pcolor (pcolor - 1) ;; readjust patch color
      if(pcolor < 60)[set pcolor 60]  ;; make sure readjustment doesn't overshoot
      ]
    
    ] ;; have the restaurant remember that they had another customer
  ]
  
  
   if((random 100 < ([taste] of patch-here)) and ([taste] of patch-here >= 20))[
        set R1x ([pxcor] of patch-here)   ;; have the turtle remember this restaurant if they liked it
        set R1y ([pycor] of patch-here)
      ]
      if((([taste] of patch-here) < 20) and (random 2 < 1))[
        set R1x ([pxcor] of patch-here)   ;; have the turtle remember this restaurant if they disliked it
        set R1y ([pycor] of patch-here)
      ]
end 

to check-capacity
  ifelse((count patrons-here) >= [capacity] of patch-here)
  [set color red]         ;; if a restaurant's capacity has been reached, signal by turning red
  [set color white]
end 

to keep-searching
  set searching 1
  set bypassing 0
  set heading (heading + 180 + random 80 - random 80)
  fd .5
end 

to check-rush
  
  if(rush-countdown = 75)[
    ask patrons[
      if(random 2 < 1)[
        set hunger 0
        set searching 0
        set bypassing 0
        set returning 1
        
      ]  
    ]
  ]
  
  


  
    
  
  if(rush-countdown = 0)[

    ask patrons[if([pcolor] of patch-here = blue)[set hunger 100]] ;;have each turtle release every 1000 ticks
    set rush-countdown 1000
 
    
    
    
    create-patrons (.01 * patron-turnover * number-patrons)[
    setxy -7 0                  ;; have the turtles start out at their home base
    set shape "person"          
    set searching 1                 ;; the customers start out searching
    set heading 90
    set hunger 100
    set R0x 0
    set R0y 0
    set R1x 0
    set R1y 0
  ]
      
      
  ]
  set rush-countdown (rush-countdown - 1)
end 

to update-patronage  ;; have the restaurants display their normalized patronage
  if((restaurant? = 1) and (pcolor < 69))[set pcolor (pcolor + .01)]
end 

to update-charts 
   
  set-current-plot "Patronage Distribution"   
  set-histogram-num-bars 10
  histogram ([70 - pcolor] of (patches with [restaurant? = 1]))
  tick 
  
  set-current-plot "Taste vs. Patronage"
  clear-plot
  set-plot-pen-mode 2
  ask patches with [restaurant? = 1][
    ;plotxy taste (70 - pcolor)
    plotxy taste (100 * patronage / ticks)
  ]
    
  set-current-plot "Distance vs. Patronage"
  clear-plot
  set-plot-pen-mode 2
  ask patches with [restaurant? = 1][
    
    let my-x-dist (distancexy -7 pycor)
    let my-y-dist (distancexy pxcor 0)
    
    
   ; plotxy (distancexy -7 0) (70 - pcolor)
   plotxy (my-x-dist + my-y-dist) (100 * patronage / ticks)
   
  ]
  
   set-current-plot "Patron Activity"
   set-plot-pen-mode 0
   set-current-plot-pen "pop"
   plot count patrons
   set-current-plot-pen "searching"
   plot count patrons with [searching = 1]
     set-current-plot-pen "bypassing"
   plot count patrons with [bypassing = 1]
     set-current-plot-pen "eating"
   plot count patrons with [eating = 1]
     set-current-plot-pen "returning"
   plot count patrons with [returning = 1]
   set-current-plot-pen "waiting"
   plot count patrons with [([pcolor] of patch-here = blue) and (searching = 0) and (returning = 0) and (bypassing = 0)]
end 

to move
  fd .015
  if(ycor > 7.499999)[ set ycor -7.5]
end 
  

There is only one version of this model, created almost 13 years ago by Taiyo Sogawa.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.