pho model v2

No preview image

1 collaborator

Default-person Taiyo Sogawa (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model Pho Model Parent of 2 models: pho model v3 and pho model v 4
Model group EECS 372-Spring 2011 | Visible to everyone | Changeable by the author
Model was written in NetLogo 4.1.3 • Viewed 168 times • Downloaded 20 times • Run 0 times
Download the 'pho model v2' 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]


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

to setup       ;; setup the environment
  ca
  set rush-countdown 1000
  
  ask patches[
    set pcolor white
    set restaurant? 0
    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 5) + 2
      sprout-vacancy-lights 1[
        set shape "square"      ;; this will act as the restaurant's vacancy light!
        set color white
        set size .8
      ]
      ]        
    if((pxcor = -7) and (abs(pycor) < 2))[set pcolor 17]         ;; setup home base for turtles to live between meals
  ]
  
  
  create-patrons 200[
    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
  ]
end 

to go
  check-rush
  
  ask patrons[
    check-bypass
    check-eating
    check-hunger
    check-returning
    check-searching
   
  ]
  
  ask vacancy-lights[
    check-capacity
  ]
  
  ask patches[
    update-patronage
  ]
  
  set-histogram-num-bars 10
  histogram ([pcolor] of (patches with [restaurant? = 1]))
  tick 
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]
  ]  
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 = 17))[ 
    
    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 = 17)[set returning 0]
    
  ]
end 

to check-searching
  if(searching = 1)[
  set heading (heading + (random 45) - (random 45))     ;; 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 - .5) ;; 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)
  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 = 17)[set hunger 100]] ;;have each turtle release every 1000 ticks
    set rush-countdown 1000
  ]
  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 

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

Attached files

No files