ecar
No preview image
Model was written in NetLogo 6.1.0
•
Viewed 268 times
•
Downloaded 26 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
;; 2 semicolon ha tozihat satr hastand (ghabel hazf hastand) ;; 1 semikolon ha dar barname taghyir ijad mikonad breed [consumers consumer] globals[ pop-level-1 pop-level-2 pop-level-3 TR sen-random temp-feature-D temp-price-D temp-promo-D temp-place-D temp-feature-F temp-price-F temp-promo-F temp-place-F s ] consumers-own [ ;social-level ***************************************** be kar narafte ast price-sen feature-sen promo-sen SI-sen PRE-1 PRE-2 PRE buy-ok feature-index-D price-index-D promo-index-D SI-index-D feature-index-F price-index-F promo-index-F SI-index-F t ;;reset buy-ok after 100 tick ;;social: adoptee-neighbors random-thresh p; change: exogenouce factors p1 p2 p3 p4 q; change: endogenouce factors ] patches-own [ feature-D price-D promo-D SI-D feature-F price-F promo-F SI-F ] to setup clear-all goods ;;goods = patches setup-pa ;index ask consumers [ set p1 random-normal 4 3 ;p1-mean p1-SD ; entekhab adadi ba miangin p1-mean va enheraf meyar p1-SD set p2 random-normal 4 3 ;p2-mean p2-SD set p3 random-normal 4 3 ;p3-mean p3-SD set p4 random-normal 4 3 ;p4-mean p4-SD set p (p1 + p2 + p3 + p4) / 4 ] ; change p can be replaced by latent-thresh ask consumer random total-population [set color red] reset-ticks end to go if not any? consumers [ stop ] if ticks = maxticks [stop] change consumer-move social-interact ;;social: update-local-search decide-adopt index preferences tick end to consumer-move ask consumers [ rt random 90 lt random 90 fd 1 ] end to index ask consumers[ if pcolor = blue [ set feature-index-D feature-sen * battry-distance set price-index-D -1 * price-sen * charge-time set promo-index-D promo-sen * max-speed set SI-index-D SI-sen * charge-cost set PRE-1 feature-index-D + price-index-D + promo-index-D + SI-index-D ;si-sen baraye meghdar avaliye ast va badan SI-index nashi az interact ezafe mishavad. ] if pcolor = yellow[ ;Foreign set feature-index-F feature-sen * battry-distance2 set price-index-F -1 * price-sen * charge-time2 set promo-index-F promo-sen * max-speed2 set SI-index-F SI-sen * charge-cost2 set PRE-2 feature-index-F + price-index-F + promo-index-F + SI-index-F ] set PRE max (list PRE-1 PRE-2) ] end to make-node [old-node] ;set-default-shape consumers "person" set total-population total-population set darsad-taxi-driver darsad-taxi-driver set darsad-employee darsad-employee set darsad-engineer darsad-engineer if (darsad-taxi-driver + darsad-employee + darsad-engineer) != 1[ show "error: population percent is not true"] set pop-level-1 darsad-taxi-driver * total-population set pop-level-2 darsad-employee * total-population set pop-level-3 darsad-engineer * total-population let clist [] let c1 count consumers with [label = 1] let c2 count consumers with [label = 2] let c3 count consumers with [label = 3] if c1 <= pop-level-1 [set clist lput 1 clist ] if c2 <= pop-level-2 [set clist lput 2 clist] if c3 <= pop-level-2 [set clist lput 3 clist] if clist = [] [set clist lput 1 clist ] let c one-of clist if c = 1 [ ;;level-1 Groups: create-consumers 1[ set label 1 setxy random-xcor random-ycor ;;;social;;; set color red if old-node != nobody [ create-link-with old-node [ set color green ] ;; position the new node near its partner move-to old-node fd 8 ] ;;social;; set sen-random random-normal sen-batry1 0.065624 set feature-sen sen-random set sen-random random-normal sen-charget1 0.183302 set price-sen sen-random set sen-random random-normal sen-speed1 0.024031 set promo-sen sen-random set sen-random random-normal sen-chargCost1 0.083501 set SI-sen sen-random set PRE-1 feature-index-D + price-index-D + promo-index-D + SI-index-D set PRE-2 feature-index-F + price-index-F + promo-index-F + SI-index-F set buy-ok 0 set t 0 set size 0.75 ] ] if c = 2 [ ;;level-2 Groups: create-consumers 1 [ set label 2 setxy random-xcor random-ycor ;;;social;;; set color red if old-node != nobody [ create-link-with old-node [ set color green ] ;; position the new node near its partner move-to old-node fd 8 ] ;;social;; set sen-random random-normal sen-batry2 0.026539 set feature-sen sen-random set sen-random random-normal sen-charget2 0.11829 set price-sen sen-random set sen-random random-normal sen-speed2 0.046191 set promo-sen sen-random set sen-random random-normal sen-chargCost2 0.149441 set SI-sen sen-random set PRE-1 feature-index-D + price-index-D + promo-index-D + SI-index-D set PRE-2 feature-index-F + price-index-F + promo-index-F + SI-index-F set buy-ok 0 set t 0 set size 0.75 ] ] if c = 3 [ ;;level-3 Groups: create-consumers 1 [ set label 3 setxy random-xcor random-ycor ;set color white - 5 ;;;social;;; set color red if old-node != nobody [ create-link-with old-node [ set color green ] ;; position the new node near its partner move-to old-node fd 8 ] ;;social;; set sen-random random-normal sen-batry3 0.021685 set feature-sen sen-random set sen-random random-normal sen-charget3 0.196543 set price-sen sen-random set sen-random random-normal sen-speed3 0.18422 set promo-sen sen-random set sen-random random-normal sen-chargCost3 0.044505 set SI-sen sen-random set PRE-1 feature-index-D + price-index-D + promo-index-D + SI-index-D set PRE-2 feature-index-F + price-index-F + promo-index-F + SI-index-F set buy-ok 0 set t 0 set size 0.75 ] ] set c1 0 set c2 0 set c3 0 set clist [] ;ask consumers [set buy-ok 0 set t 0 set size 0.75] ;ask consumer random total-population [set color red] ;;social end to goods ask patches [ set pcolor gray if random 100 < 3 and pcolor = gray [set pcolor blue ] ;; 3 % khanehaye patch abi rang (Domestic) mishavand. if random 100 < 3 and pcolor = gray [set pcolor yellow ] ;; 3 % khanehaye patch abi rang (Foreign) mishavand. ] ask patches [ if pcolor = blue[ ;Goods inputs ;;Domestic Goods set battry-distance battry-distance set temp-feature-D battry-distance set charge-time charge-time set temp-price-D charge-time set max-speed max-speed set temp-promo-D max-speed set charge-cost charge-cost set temp-place-D charge-cost ] ;foreign Goods if pcolor = yellow [ set battry-distance2 battry-distance2 set temp-feature-F battry-distance2 set charge-time2 charge-time2 set temp-price-F charge-time2 set max-speed2 max-speed2 set temp-promo-F max-speed2 set charge-cost2 charge-cost2 set temp-place-F charge-cost2 ] ] end to change ;;goods parameters change ask patches [ if temp-feature-D != battry-distance [set battry-distance battry-distance set temp-feature-D battry-distance set s 1] if temp-price-D != charge-time [set charge-time charge-time set temp-price-D charge-time set s 1] if temp-promo-D != max-speed [set max-speed max-speed set temp-promo-D max-speed set s 1] if temp-place-D != charge-cost [set charge-cost charge-cost set temp-place-D charge-cost set s 1] if temp-feature-F != battry-distance2 [set battry-distance2 battry-distance2 set temp-feature-F battry-distance2 set s 1] if temp-price-F != charge-time2 [set charge-time2 charge-time2 set temp-place-F charge-time2 set s 1] if temp-promo-F != max-speed2 [set max-speed2 max-speed2 set temp-promo-F max-speed2 set s 1] if temp-place-F != charge-cost2 [set charge-cost2 charge-cost2 set temp-place-F charge-cost2 set s 1] ] end to preferences ;SI-prosseces ask consumers [if buy-ok != 0 [set t t + 1]] ;if t = 50 [set buy-ok 0]] set TR random-normal adoption-threshold 0.1 ask consumers [ ;set TR random-normal adoption-threshold 1 if s = 1 [ change ask consumers [ set PRE-1 feature-index-D + price-index-D + promo-index-D + SI-index-D set PRE-2 feature-index-F + price-index-F + promo-index-F + SI-index-F set PRE max(list PRE-1 PRE-2) ] ] ;] ;set TR adoption-threshold ;ask consumers [ if buy-ok = 0[ if pcolor = blue or pcolor = yellow [ ;;if moshtari rooye khaneyi (patch) bashad k kala hast. ifelse PRE-1 >= TR and PRE-2 >= TR [ ;set PRE max (list PRE-1 PRE-2) ifelse PRE >= TR [ if PRE = PRE-1 [set buy-ok 1 beep] if PRE = PRE-2 [set buy-ok 2 beep] ] [show "Error when PRE calculate" stop] ] [ ;;else if PRE-1 < TR and PRE-2 < TR [ set buy-ok 0 ;set color white ;;buy-ok : 2 for foreign , 1 for Domestic ] if PRE-1 >= TR [ ;;******** sath income ra be nahvi bayad vared konim va buy-ok ra sefr gharar dahim. sath income ra be mizan entezar dar amad (vam o ...) niz vabaste konam set buy-ok 1 ;set color yellow + 2 beep ] if PRE-2 >= TR[ set buy-ok 2 ;set color white beep ] ] ] ] ;if buy-ok != 0 [set t t + 1] ;if t = 50 [set buy-ok 0] ] end ;;;;;;;;;;;;;;;;;;;;; ;;;Social Function;;; ;;;;;;;;;;;;;;;;;;;;; to setup-pa ;set-default-shape consumers "person" ;; make the initial network of two consumers and an edge make-node nobody ;; first node, unattached make-node consumer 0 ;; second node, attached to first node repeat total-population [ go-pa ] ask consumers [set color white] ask links [set color yellow] reset-ticks ask consumers [ set q count link-neighbors] ; change: calculating the degree of centrality of each node ask consumers [ set q count link.... end to go-pa ask links [ set color yellow ] make-node find-partner ;; find partner & use it as attachment ;; point for new node ;tick if layout? [layout-pa] end to-report find-partner let total random-float sum [count link-neighbors] of consumers let partner nobody ask consumers [ let nc count link-neighbors ;; if there's no winner yet... if partner = nobody [ ifelse nc > total [ set partner self ] [ set total total - nc ] ] ] report partner end to social-interact ask consumers [ set PRE-1 PRE-1 - SI-index-D set PRE-2 PRE-2 - SI-index-F ] ask consumers with [ label = 1] [ let SI-index-1 0 ask link-neighbors with [label = 1] [ set SI-index-1 SI-index-1 + 0.4 * sen-chargCost1] ask link-neighbors with [label = 2] [ set SI-index-1 SI-index-1 + 0.5 * sen-chargCost2] ask link-neighbors with [label = 3] [ set SI-index-1 SI-index-1 + 0.1 * sen-chargCost3] set SI-index-D (SI-index-D + SI-index-1) / count link-neighbors * charge-cost set SI-index-F (SI-index-F + SI-index-1) / count link-neighbors * charge-cost2 set PRE-1 PRE-1 + SI-index-D set PRE-2 PRE-2 + SI-index-F ] ;;;;;; label 2 ask consumers with [ label = 2] [ let SI-index-2 0 ask link-neighbors with [label = 1] [ set SI-index-2 SI-index-2 + 0.3 * sen-chargCost1] ask link-neighbors with [label = 2] [ set SI-index-2 SI-index-2 + 0.4 * sen-chargCost2] ask link-neighbors with [label = 3] [ set SI-index-2 SI-index-2 + 0.3 * sen-chargCost3] set SI-index-D (SI-index-D + SI-index-2) / count link-neighbors * charge-cost set SI-index-F (SI-index-F + SI-index-2) / count link-neighbors * charge-cost2 set PRE-1 PRE-1 + SI-index-D set PRE-2 PRE-2 + SI-index-F ] ;;;;;; label 3 ask consumers with [ label = 3] [ let SI-index-3 0 ask link-neighbors with [label = 1] [ set SI-index-3 SI-index-3 + 0.1 * sen-chargCost1] ask link-neighbors with [label = 2] [ set SI-index-3 SI-index-3 + 0.3 * sen-chargCost2] ask link-neighbors with [label = 3] [ set SI-index-3 SI-index-3 + 0.6 * sen-chargCost3] set SI-index-D (SI-index-D + SI-index-3) / count link-neighbors * charge-cost set SI-index-F (SI-index-F + SI-index-3) / count link-neighbors * charge-cost2 set PRE-1 PRE-1 + SI-index-D set PRE-2 PRE-2 + SI-index-F ] end ;;;;;;;;;;;;;; ;;; Layout ;;; ;;;;;;;;;;;;;; to layout if not layout? [ stop ] ;; the number 10 here is arbitrary; more repetitions slows down the ;; model, but too few gives poor layouts repeat 10 [ do-layout display ;; so we get smooth animation ] end to do-layout layout-spring (consumers with [any? link-neighbors]) links 0.4 6 1 end ;;;;;;;;;;;;;; ;;; Layout ;;; ;;;;;;;;;;;;;; ;; resize-nodes, change back and forth from size based on degree to a size of 1 to resize-nodes ifelse all? consumers [size <= 1] [ ;; a node is a circle with diameter determined by ;; the SIZE variable; using SQRT makes the circle's ;; area proportional to its degree ask consumers [ set size sqrt count link-neighbors ] ] [ ask consumers [ set size 1 ] ] end to layout-pa ;; the number 3 here is arbitrary; more repetitions slows down the ;; model, but too few gives poor layouts repeat 3 [ ;; the more consumers we have to fit into the same amount of space, ;; the smaller the inputs to layout-spring we'll need to use let factor sqrt count consumers ;; numbers here are arbitrarily chosen for pleasing appearance layout-spring consumers links (1 / factor) (7 / factor) (1 / factor) display ;; for smooth animation ] ;; don't bump the edges of the world let x-offset max [xcor] of consumers + min [xcor] of consumers let y-offset max [ycor] of consumers + min [ycor] of consumers ;; big jumps look funny, so only adjust a little each time set x-offset limit-magnitude x-offset 0.1 set y-offset limit-magnitude y-offset 0.1 ask consumers [ setxy (xcor - x-offset / 2) (ycor - y-offset / 2) ] end to-report limit-magnitude [number limit] if number > limit [ report limit ] if number < (- limit) [ report (- limit) ] report number end to update-local-search ask consumers [ set adoptee-neighbors count link-neighbors with [color = red] ;set label adoptee-neighbors set label-color 45 - adoptee-neighbors ];green ] end to decide-adopt ;; adoption means to turn red ;; based on comparing a random number between 0 and 100 to the various effects ;; these effects, in total, must exceed the random num for diffusion to occur let nadopt count consumers with [color = red] ask consumers [ ;set shape "person" if color = white [ set random-thresh random 100 if random-thresh < p + ( q * (nadopt / number-of-nodes ) ) + ( adoptee-neighbors * cohesion-effect ) [ ; if random-thresh < constant-effect + ( endogenous-effect * (nadopt / number-of-nodes ) ) + ( adoptee-neighbors * cohesion-effect ) [ set color red set shape "person"] ;; adopt if random number (0-100) is lower than ;; constant hazard + proportion adopted * endogenous hazard ;; note, cohesion-fx doesn't seem to work yet ] ] end
There are 2 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.