Lodging Choice Model
Model was written in NetLogo 6.1.1
•
Viewed 109 times
•
Downloaded 10 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [ guest-count host-count choice gini-index-reserve lorenz-points base-ratio aff-homo ] ;extensions [ import-a ] ;extensions [ rnd ] breed [hosts host] breed [guests guest] breed [trees tree] hosts-own [ h-race w-ratio b-ratio a-ratio w-cnt ;;expected number of white on the front page b-cnt ;;expected number of black on the front page a-cnt ;;expected number of asian on the front page num-guest ] guests-own [ g-race cate ] to setup clear-all ask patches [set pcolor green - random-float 0.5] ;ask patches [set pcolor 56 ] ;import-drawing "map.jpg" set-default-shape guests "person" set-default-shape hosts "house" set host-count (white-hosts + black-hosts + asian-hosts) ;;set guest-count (white-hosts + black-hosts + asian-hosts) ;;add number of hosts according to the input create-hosts white-hosts [ set size 2 set h-race "White" set color 105 ;; white = 105 set xcor -20 + random 40 set ycor -20 + random 50 ] create-hosts black-hosts [ set size 2 set h-race "Black" set color 3 ;; grey = 3 set xcor -20 + random 40 set ycor -20 + random 50 ] create-hosts asian-hosts [ set size 2 set h-race "Asian" set color 25 ;; yellow = 45 set xcor -20 + random 40 set ycor -20 + random 50 ] ;;set hosts apart for visual purpose ask hosts [move-to one-of patches with [not any? other hosts in-radius 2]] update-lorenz-and-gini reset-ticks end to go ;; update the front page reviewer counts for all hosts based on the guest race ask hosts [ if count link-neighbors > 0 [ set w-ratio count (link-neighbors with [g-race = "White"])/ count link-neighbors set b-ratio count (link-neighbors with [g-race = "Black"])/ count link-neighbors set a-ratio count (link-neighbors with [g-race = "Asian"])/ count link-neighbors if count link-neighbors > front-page [ set w-cnt w-ratio * front-page ;count (link-neighbors with [g-race = "White"]) set b-cnt b-ratio * front-page ;count (link-neighbors with [g-race = "Black"]) set a-cnt a-ratio * front-page ;count (link-neighbors with [g-race = "Asian"]) ] if count link-neighbors <= front-page [ set w-cnt count (link-neighbors with [g-race = "White"]) set b-cnt count (link-neighbors with [g-race = "Black"]) set a-cnt count (link-neighbors with [g-race = "Asian"]) ] ] if count link-neighbors = 0 [ set w-ratio 0 set b-ratio 0 set a-ratio 0 set w-cnt 0 set b-cnt 0 set a-cnt 0 ] set num-guest count (link-neighbors) ] ask links [ set color gray ] set guest-count (guest-count + 1) create-guest make-decision find-partner update-lorenz-and-gini tick end ;; used for creating a new guest to create-guest create-guests 1 [ ;set new? true let a-g-prob 1 - w-g-prob - b-g-prob let probs ( list (w-g-prob) (b-g-prob) (a-g-prob) ) set g-race (random-pick-guest-race probs) if g-race = "White" [set color 105 set cate 1] if g-race = "Black" [set color 3 set cate 2] if g-race = "Asian" [set color 25 set cate 3] ] end to make-decision [listing] ask (max-one-of guests [who]) [ if listing != nobody [ create-link-with listing [ set color grey ] ;; position the new node near its partner move-to listing fd 3 + (random 6) ] ] end to-report find-partner let temp-race ([g-race] of (max-one-of guests [who])) ;; update the attractiveness of hosts based on the guest race --> attractiveness is a list of probabilities ifelse gr_homo? [ ;;########################### ;;########################### ;;if switch is ON, pick host based on the coefficient and intercept let w-pref reduce sentence (map [[a] -> [w-cnt] of hosts with [who = a]] (range 0 (host-count))) let b-pref reduce sentence (map [[a] -> [b-cnt] of hosts with [who = a]] (range 0 (host-count))) let a-pref reduce sentence (map [[a] -> [a-cnt] of hosts with [who = a]] (range 0 (host-count))) if temp-race = "White" [ let coef (sentence (n-values white-hosts [w-w-coef]) (n-values black-hosts [w-b-coef]) (n-values asian-hosts [w-a-coef])) let ic (sentence (n-values white-hosts [w-w-ic]) (n-values black-hosts [w-b-ic]) (n-values asian-hosts [w-a-ic])) let att (map [[a b c] -> (a * b + c) ] coef w-pref ic) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last report host choice ] if temp-race = "Black" [ let coef (sentence (n-values white-hosts [b-w-coef]) (n-values black-hosts [b-b-coef]) (n-values asian-hosts [b-a-coef])) let ic (sentence (n-values white-hosts [b-w-ic]) (n-values black-hosts [b-b-ic]) (n-values asian-hosts [b-a-ic])) let att (map [[a b c] -> (a * b + c) ] coef b-pref ic) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last report host choice ] if temp-race = "Asian" [ let coef (sentence (n-values white-hosts [a-w-coef]) (n-values black-hosts [a-b-coef]) (n-values asian-hosts [a-a-coef])) let ic (sentence (n-values white-hosts [a-w-ic]) (n-values black-hosts [a-b-ic]) (n-values asian-hosts [a-a-ic])) let att (map [[a b c] -> (a * b + c) ] coef a-pref ic) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last report host choice ] ] [ ;;########################### ;;########################### ;;if switch is off, pick host without considering guest-reviewer homophily let w-a-1 1 - w-w-1 - w-b-1 let b-a-1 1 - b-w-1 - b-b-1 let a-w-1 1 - a-a-1 - a-b-1 if temp-race = "White" [ let gh-pref (sentence (n-values white-hosts [w-w-1]) (n-values black-hosts [w-b-1]) (n-values asian-hosts [w-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) set choice (random-pick-host gh-pref) report host choice ] if temp-race = "Black" [ let gh-pref (sentence (n-values white-hosts [b-w-1]) (n-values black-hosts [b-b-1]) (n-values asian-hosts [b-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) set choice (random-pick-host gh-pref) report host choice ] if temp-race = "Asian" [ let gh-pref (sentence (n-values white-hosts [a-w-1]) (n-values black-hosts [a-b-1]) (n-values asian-hosts [a-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) set choice (random-pick-host gh-pref) report host choice ] ] end to-report random-pick-guest-race [tmp] let var (1 / sum tmp) let _ps map [[a] -> a * var] tmp ;[0.1 0.2 0.1 0.4 0.1 0.01] let _r random-float 1 let _lst [ "White" "Black" "Asian" ] let _i 0 while [_r >= item _i _ps] [ set _r (_r - item _i _ps) set _i (_i + 1) ] report item _i _lst end to-report random-pick-host [tmp] let var (1 / sum tmp) let _ps map [[a] -> a * var] tmp ;[0.1 0.2 0.1 0.4 0.1 0.01] let _r random-float 1 let _lst (range 0 host-count) let _i 0 while [_r >= item _i _ps] [ set _r (_r - item _i _ps) set _i (_i + 1) ] report item _i _lst end ;;;;;;Gini coefficient to update-lorenz-and-gini let sorted-wealths sort [num-guest] of hosts let total-wealth sum sorted-wealths let wealth-sum-so-far 0 let index 0 set gini-index-reserve 0 set lorenz-points [] ;; now actually plot the Lorenz curve -- along the way, we also ;; calculate the Gini index. ;; (see the Info tab for a description of the curve and measure) if total-wealth > 0 [ repeat host-count [ set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths) set lorenz-points lput ((wealth-sum-so-far / total-wealth) * 100) lorenz-points set index (index + 1) set gini-index-reserve gini-index-reserve + (index / host-count) - (wealth-sum-so-far / total-wealth) ] ] end
There is only one version of this model, created over 4 years ago by Chao Yu.
This model does not have any ancestors.
This model does not have any descendants.