aaa---micro-macro_evolve_salzano.nlogo
来自「NETLOGO」· NLOGO 代码 · 共 951 行 · 第 1/5 页
NLOGO
951 行
; ================== For Individuals ============== ;;;;;;; If there are Representative Agents set all the initial individual's preferences equal ;We suppose that the individual demand and offre are both vertically and orizzontally summable ;;;;;;;;;;;;;;;For GOODS and WORK ;;; FORSE IL PRIMO BLOCCO ? RIPETUTO SUBITO DOPO ask Agg_individual [set ind-indiv 0 while [ind-indiv <= Individuals_N - 1] [set x-work 0 if (x-work = 0)[ Ifelse (Repr-Agents = "Yes")[ ask turtle (ind-indiv) [set mylist1 lput ((item x-work Ag-mylist1-of turtle (Individuals_N + Firms_N)) / Individuals_N) mylist1 set mylist2 lput ((item x-work Ag-mylist2-of turtle (Individuals_N + Firms_N)) / Individuals_N) mylist2 set work_r-list lput ((item x-work Ag-work_r-list-of turtle (Individuals_N + Firms_N)) / Individuals_N) work_r-list ]]; close 1? Ifelse (Repr-Agents = "Yes") ; Of course, here it should be possible to introduce the tax on single individual; ;;;; If there is no Representative Agents set them differently, but with their sum equal to the aggregated [ask turtle (ind-indiv) [ set mylist1 lput ((item x-work Ag-mylist1-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) mylist1 set mylist2 lput ((item x-work Ag-mylist2-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) mylist2 set work_r-list lput ((item x-work Ag-work_r-list-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) work_r-list ]; close ask turtle (ind-indiv) ]] set x-work 1 ask turtle (ind-indiv) [ while [(item (x-work - 1) mylist2 < item (x-work - 1) mylist1) and ((x-work - 1) < length Ag-mylist1-of turtle (Individuals_N + Firms_N) - 1) ] [ Ifelse (Repr-Agents = "Yes")[ ask turtle (ind-indiv)[set mylist1 lput ((item x-work Ag-mylist1-of turtle (Individuals_N + Firms_N)) / Individuals_N) mylist1 set mylist2 lput ((item x-work Ag-mylist2-of turtle (Individuals_N + Firms_N)) / Individuals_N) mylist2 set work_r-list lput ((item x-work Ag-work_r-list-of turtle (Individuals_N + Firms_N))/ Individuals_N) work_r-list]];set x-work x-work + 1]; close 1? Ifelse (Repr-Agents = "Yes") [ask turtle (ind-indiv) [ set mylist1 lput ((item x-work Ag-mylist1-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) mylist1 set mylist2 lput ((item x-work Ag-mylist2-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) mylist2 set work_r-list lput ((item x-work Ag-work_r-list-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) work_r-list ]] set x-work x-work + 1 ]] set ind-indiv ind-indiv + 1 ]] ask Agg_individual[ set Ag-H replace-item 0 Ag-H (max Ag-mylist1) set Ag-H replace-item 1 Ag-H (max Ag-work_r-list) ];; the Walrasian condition for Agg-individual Ifelse (Repr-Agents = "Yes")[ ask individual [set H replace-item 0 H ((item 0 Ag-H-of turtle (Individuals_N + Firms_N)) / Individuals_N) set H replace-item 1 H ((item 1 Ag-H-of turtle (Individuals_N + Firms_N)) / Individuals_N)]];close I Ifelse (Repr-Agents = "Yes") [set ind-indiv 0 while [ind-indiv <= Individuals_N - 1] [ask turtle (ind-indiv) [ set H replace-item 0 H ((item 0 Ag-H-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) set H replace-item 1 H ((item 1 Ag-H-of turtle (Individuals_N + Firms_N)) * RND-of turtle (ind-indiv)) ]; close ask turtle (ind-indiv) set ind-indiv ind-indiv + 1 ]] ; close while [ind-indiv < Individuals_N - 1] ; ================== For Firms ============== ;;;;;;; If there are Representative Agents set all the initial individual's preferences equal ;;;;;;;;;;;;;;;For GOODS and WORK ask Agg_Firm [set ind-indiv Individuals_N while [ind-indiv <= Individuals_N + Firms_N - 1] [set x-work 0 if (x-work = 0)[ Ifelse (Repr-Agents = "Yes")[ ask turtle ind-indiv [set mylist3 lput ((item x-work Ag-mylist3-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) mylist3 set mylist4 lput ((item x-work Ag-mylist4-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) mylist4 set work_r1-list lput ((item x-work Ag-work_r1-list-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) work_r1-list] ] ; close 1? Ifelse (Repr-Agents = "Yes") ;;;; If there is no Representative Agents set them differently, but with their sum equal to the aggregated [ask turtle (ind-indiv) [ set mylist3 lput ((item x-work Ag-mylist3-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) mylist3 set mylist4 lput ((item x-work Ag-mylist4-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) mylist4 set work_r1-list lput ((item x-work Ag-work_r1-list-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) work_r1-list ]]]set x-work 1 ask turtle (ind-indiv) [while [(item (x-work - 1) mylist4-of turtle (ind-indiv) < item (x-work - 1) mylist3-of turtle (ind-indiv) ) and (x-work < length Ag-work_r1-list-of turtle (Individuals_N + Firms_N + 1))][ Ifelse (Repr-Agents = "Yes")[ ask turtle (ind-indiv)[set mylist3 lput ((item x-work Ag-mylist3-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) mylist3 set mylist4 lput ((item x-work Ag-mylist4-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) mylist4 set work_r1-list lput ((item x-work Ag-work_r1-list-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) work_r1-list] ] ; close 1? Ifelse (Repr-Agents = "Yes") ;;;; If there is no Representative Agents set them differently, but with their sum equal to the aggregated [ask turtle (ind-indiv) [ set mylist3 lput ((item x-work Ag-mylist3-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) mylist3 set mylist4 lput ((item x-work Ag-mylist4-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) mylist4 set work_r1-list lput ((item x-work Ag-work_r1-list-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) work_r1-list ]] set x-work x-work + 1 ] ] set ind-indiv ind-indiv + 1 ] ] ;close II Ifelse (Repr-Agents = "Yes") ;; create initial-Agents number of breed Agents ask Agg_Firm [ set Ag-F replace-item 0 Ag-F (max Ag-mylist3) set Ag-F replace-item 1 Ag-F (max Ag-work_r1-list) ];; the Walrasian condition for Agg-Firm Ifelse (Repr-Agents = "Yes")[ ask Firm [set F replace-item 0 F ((item 0 Ag-F-of turtle (Individuals_N + Firms_N + 1)) / Firms_N) set F replace-item 1 F ((item 1 Ag-F-of turtle (Individuals_N + Firms_N + 1)) / Firms_N)]];close I Ifelse (Repr-Agents = "Yes") [set ind-indiv Individuals_N while [ind-indiv <= Individuals_N + Firms_N - 1] [ask turtle (ind-indiv) [ set F replace-item 0 F ((item 0 Ag-F-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) set F replace-item 1 F ((item 1 Ag-F-of turtle (Individuals_N + Firms_N + 1)) * RND-of turtle (ind-indiv)) ]; close ask turtle (ind-indiv) set ind-indiv ind-indiv + 1 ]] ; close while ; set the initial information for each firm the individual has [It is 1 (or it may be 0)] set tp-list [] set td-list [] set t-o-list [] ask individual[ set list_in_bbI []]; repeat Individuals_N set index 0 while [index <= Individuals_N - 1] [ask turtle index [repeat Firms_N [set list_in_bbI lput 1 list_in_bbI]] set index index + 1 ] Ask Agg_firm [set Total-Good [] set Total-Work [] ]; Define as lists a3-setup-form-individual-price-image end ; End of Setup Procedure to a1-setup-instruction; Part of Setup Procedure set instruction "Click on Setup" end to a2-setup-build-friends-list; Part of Setup Procedure ; Start of the information pre-process - Individual exchange information only with friends ; The simplifing assumption adopted here is that the same group of friends give informations for both work and goods. ; The group formation is casual. An individual can be in more then one group. Each individual has one friend list. ; ------------------------------------------------------------ Build the group of friends of each individual ----------------------------------------------------------------------------------------------- ask friends_group [set group_of_friends [] set group 0 set indexf 0 ] while [group < group_N] [ while [(indexf < hmanyfrom_gr) and (((group * hmanyfrom_gr) + indexf) < Individuals_N)] [;type " indexf: " type indexf type " group: " print group ask turtle (Individuals_N + Firms_N + 2 + group) [set group_of_friends lput ((group * hmanyfrom_gr) + indexf) group_of_friends] set indexf indexf + 1] set group group + 1 set indexf 0 ] set indexf 0 set group 0 ask turtle (indexf) [ set friends-list [] ]; set indrnd 0] while [(((group * hmanyfrom_gr) + indexf) < Individuals_N)] [while [(indexf < hmanyfrom_gr) and (((group * hmanyfrom_gr) + indexf) < Individuals_N)] [type " indexf: " type indexf type " group: " print group set friends-list-of turtle ((group * hmanyfrom_gr) + indexf) group_of_friends-of turtle (Individuals_N + Firms_N + 2 + group ) set friends-list-of turtle ((group * hmanyfrom_gr) + indexf) remove ((group * hmanyfrom_gr) + indexf) friends-list-of turtle ((group * hmanyfrom_gr) + indexf); "indrnd" pu? essere adoperato per recuperare le preferenze degli amici set indexf indexf + 1] set group group + 1 set indexf 0] end ;set mylist remove 7 mylist ; ------------------------------------------------------------------ Price shock ----------------------------------------------------------------------------------------- to w-Price-shock Show "PRICE SHOCK" ask firm [set price 10 + (random-int-or-float (2 * Firms_N))] end to w-Information-shock-a set information-shock true end ;;; -------------------------------------------------------- STARTING THE RUN OF SIMULATION ------------------------------------------------------------- to bgo set instruction "Take account that if there is only one individual and only one firm the microeconomic and macroeconomic models coincide." set time time + 1 if (pref-evol = true and time > 20) [bpreference-evolution] ;----------------------------------Trova la lunghezza di ogni lista di caratteristiche degli agenti - Riempie di zeri le liste di domanda e offerta totali Crea una variabile intermedia "mlp" di ml1 ml2 mlw --------------------------------------------------------------------- ;----------------------------------Create the "lists with a terminator" indicating the permanence of offer and demand - Introduce the maximum of the list --------------------------------------------------------------------- set mlp [] ask individual [ set mlp lput max values-from individual [length (mylist1)] mlp set mlp lput max values-from individual [length (mylist2)] mlp set mlp lput max values-from individual [length (work_r-list)] mlp ] set mlt max mlp set mlpf [] ask firm [ set mlpf lput max values-from firm [length (mylist3)] mlpf set mlpf lput max values-from firm [length (mylist4)] mlpf set mlpf lput max values-from firm [length (work_r1-list)] mlpf ] set mltf max mlpf ask individual [if (empty? mylist1) [while [((length mylist2 ) < mlt )] [set mylist2 lput 0 mylist1]] set mylist1a mylist1 while [((length mylist1 ) < mlt )] [set mylist1a lput max mylist1 mylist1a set mylist1 lput 0 mylist1]] ask individual [if (empty? mylist2) [while [((length mylist2 ) < mlt )] [set mylist2 lput 0 mylist2]] set mylist2a mylist2 while [((length mylist2 ) < mlt )] [set mylist2a lput max mylist2 mylist2a set mylist2 lput 0 mylist2]] ask individual [if (empty? work_r-list) [while [((length work_r-list) < mlt )] [set work_r-list lput 0 work_r-list]] set work_r-lista work_r-list while [((length work_r-list ) < mlt )] [set work_r-lista lput max work_r-list work_r-lista set work_r-list lput 0 work_r-list]] ask firm [if (empty? mylist3) [while [((length mylist3) < mltf )] [set mylist3 lput 0 mylist3]] set mylist3a mylist3 while [((length mylist3 ) < mltf )] [set mylist3a lput max mylist3 mylist3a set mylist3 lput 0 mylist3]] ask firm [if (empty? mylist4) [while [((length mylist4) < mltf )] [set mylist4 lput 0 mylist4]] set mylist4a mylist4 while [((length mylist4 ) < mltf )] [set mylist4a lput max mylist4 mylist4a set mylist4 lput 0 mylist4]] ask firm [if (empty? work_r1-list) [while [((length work_r1-list) < mltf )] [set work_r1-list lput 0 work_r1-list]] set work_r1-lista work_r1-list while [((length work_r1-list ) < mltf )] [set work_r1-lista lput max work_r1-list work_r1-lista set work_r1-list lput 0 work_r1-list]] d-sum-mylists e-bbbb end to bpermanence set ind-indiv 0 while [ind-indiv <= Individuals_N - 1] [ask turtle (ind-indiv) [ set satisfpermang 0 set satisfpermanw 0 set inperm 0 ;(20 - permanence) while [inperm < permanence][ set satisfpermang satisfpermang + item ((20 - permanence) + inperm) timesatisfggg set satisfpermanw satisfpermanw + item ((20 - permanence) + inperm) timesatisfwww set inperm inperm + 1]; print " PASSA 2 "
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?