⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ---model.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 4 页
字号:
            if (areas-of turtle buyer = my_area and not empty? my_area)      [set request ? ; if the seller is a collocator, pick the first request sent by another collocator       set n position ? reverse my_inbox             ]  ]      if (empty? request)[ ; if there is no request from other collocators, or if the seller is a telecommuter, pick the first request in the seller's inbox.  set my_inbox reverse my_inbox  set request first my_inbox  set n 0  ]  ] ; end of the favoritism selling rule  [  set my_inbox reverse my_inbox  set request first my_inbox  set n 0  ];end else, the f-c-f-s rule      set quantity read-from-string first request ; retrieve the amount to sell from the request  set buyer read-from-string butfirst request ; retrieve the buyer ID from the  request   ask turtle buyer[    set demand item shape_to_deliver my_need  ]    if (quantity > demand)  [set quantity demand] ; if the buyer does not need as many shapes as it requests (the buyer might have got the same shape from the;                         the other producer before the current seller responds), set the amount to sell as the current need of the buyer.;                         This is to prevent any agent from buying more shapes than they need.    if (quantity <= 0) [  ask seller_id [set inbox filter [? != request] inbox] ; if the buyer does not need the shape anymore, remove all the buyer's requests from the seller's   ;                                               inbox and stop the turtle-sell procedure.  stop]    ask seller_id[       if (quantity > production_limit)    [set quantity production_limit] ; if the buyer requests more than the seller can produce, set the amount to sell to the number of shapes left of the seller.    set production_limit production_limit - quantity ; deduct the amount sold from the seller's production limit    set inbox filter [? != request] inbox ; remove the fulfilled request from the seller's inbox           if production_limit = 0 [set color color - 2] ; if the seller is sold out, shrink its size on the screen.    if sum shape_inventory = 8 [ set color 75]  ]  ask turtle buyer[ ; update the buyer's inventory and shape needed variable    set shape_inventory replace-item shape_to_deliver shape_inventory (item shape_to_deliver shape_inventory + quantity)     set size 5 + (sum shape_inventory)    set my_need replace-item shape_to_deliver my_need (item shape_to_deliver my_need - quantity)     set endx xcor    set endy ycor  ]    ifelse (empty? areas-of turtle buyer) ; update the total shapes bought by collocators and telecommuters.  [set t_inv t_inv + quantity]   [set c_inv c_inv + quantity]    if (empty? areas-of seller_id and empty? areas-of turtle buyer) ; update the 2 x 2 who-is-selling-to-whom table on the screen    [set t_t t_t + quantity]  if (empty? areas-of seller_id and not empty? areas-of turtle buyer)    [set t_c t_c + quantity]  if (not empty? areas-of seller_id and empty? areas-of turtle buyer)    [set c_t c_t + quantity]  if (not empty? areas-of seller_id and not empty? areas-of turtle buyer)    [set c_c c_c + quantity]     ask seller_id[ ; update the sell-to variable of the seller    set sell-to replace-item (id-of turtle buyer) sell-to (item (id-of turtle buyer) sell-to + quantity)    ]    while [quantity > 0][ ; demonstrate the delivery of shapes on the screen  ask seller_id[    hatch 1 [              set size 5             set heading towardsxy-nowrap endx endy             set move_turtle self          ]    ask move_turtle [          fd distancexy-nowrap endx endy          find_edge seller_id turtle buyer           die         ]                 ]  set quantity quantity - 1]  do_plots ; update the plots on the interface.end;--------------------------end of turtle-sell------------------------;--------------------------beginning of initiate-round--------------;purpose: set up initial configuration in the beginning of a round;when called: during the play;called by: the "setup" procedure in the beginning of an experiment and the "turtle-trading" procedure during the play;receives: none;returns: none;remarks: to initiate-roundlocals [temp i] ask nodes [die] ask edges [die] ask delayed-requests [die] cp  set-current-plot "inventory" clear-plot   set t 0  set prod_limit 6  set clock 0  set current_area 0  set expired 0  set c_inv 0  set t_inv 0  set t_t 0  set t_c 0  set c_t 0  set c_c 0  set i 0  set shape_need [[0 3 3 1 1][1 0 3 3 1][1 1 0 3 3][3 1 1 0 3][3 3 1 1 0]]    set-default-shape edges "line"    set shape_list [ "circle" "box" "x" "diamond" "triangle" ]  set color_list [ yellow blue brown white red violet orange pink gray green ]    set id_list []  while [i < number_nodes][  set id_list lput i id_list  set i i + 1  ]  setup-nodes ; call the "setup-nodes" procedure to assign initial configuration to the agents    ask nodes  [      ask nodes with [self != myself and shape != shape-of myself]        [form-edge myself]  ] ; draw the lines connecting each pair of agentsset-environment  set distracted_col random-n-of #_of_distraction nodes with [not empty? areas]  set distracted_col values-from distracted_col [who]end;----------------------end of initiate-round---------------------------------;--------------------------beginning of initiate-first-round--------------;purpose: set up initial configuration in the beginning of a round;when called: during the play;called by: the "setup" procedure in the beginning of an experiment and the "turtle-trading" procedure during the play;receives: none;returns: none;remarks: to initiate-first-roundlocals [temp i] ct cp clear-all-plots  set-variables    set shape_need [[0 3 3 1 1][1 0 3 3 1][1 1 0 3 3][3 1 1 0 3][3 3 1 1 0]]    set-default-shape edges "line"    set shape_list [ "circle" "box" "x" "diamond" "triangle" ]  set color_list [ yellow blue brown white red violet orange pink gray green ]  set i 0  set id_list []  while [i < number_nodes][  set id_list lput i id_list  set i i + 1  ]    setup-nodes ; call the "setup-nodes" procedure to assign initial configuration to the agents    ask nodes  [      ask nodes with [self != myself and shape != shape-of myself]        [form-edge myself]  ] ; draw the lines connecting each pair of agentsset-environment  set distracted_col random-n-of #_of_distraction nodes with [not empty? areas]  set distracted_col values-from distracted_col [who]if (statistics?) [ make-summary-data-turtle ]end;-------------------------end of initiate-first-round--------------------;--------------------------beginning of set-variables--------------;purpose: set up initial values of varialbes;when called: during the play;called by: the "initiate-first-round" procedure in the beginning of an experiment;receives: none;returns: none;remarks: to set-variables  set t 0  set prod_limit 6  set clock 0  set current_area 0  set expired 0  set c_inv 0  set t_inv 0  set t_t 0  set t_c 0  set c_t 0  set c_c 0  set run_c_c 0  set run_c_t 0  set run_t_t 0  set run_t_c 0  set stat-flag false  set cc-ct-stat false  set cc-tc-stat false  set cc-tt-stat false  set ct-tc-stat false  set ct-tt-stat false   set tc-tt-stat false  set col-tel-stat falseend;----------------------end of set-variables---------------------------------;---------------------beginning of plot procedures----------------------------------;purpose: plot the "inventory" and "running_average" charts on the screen ;when called: during the play;called by: the "turtle-sell" procedure;receives: none;returns: none;remarks: to do_plots  set-current-plot "inventory"  auto-plot-on  set-current-plot-pen "col"    plot c_inv ; the red line shows the total number of shapes bought by collocators  set-current-plot-pen "tel"    plot t_inv ; the black line shows the total number of shapes bought by telecommutersendto do_plots_rt  set-current-plot "running-averages"  auto-plot-on    set-current-plot-pen "col_col"  plot (run_c_c / (current_round)) ; the red line shows the total number of shapes bought by collocators  set-current-plot-pen "col_tel"  plot (run_c_t / (current_round)) ; the black line shows the total number of shapes bought by telecommuters  set-current-plot-pen "tel_col"  plot (run_t_c / (current_round)); the red line shows the total number of shapes bought by collocators  set-current-plot-pen "tel_tel"  plot (run_t_t / (current_round)); the black line shows the total number of shapes bought by telecommuters    set-current-plot "average-inventory"  auto-plot-on    set-current-plot-pen "col"  plot (run_c_inv / (current_round)) ; the red line shows the average number of shapes bought by cols    set-current-plot-pen "tel"  plot (run_t_inv / (current_round)) ; the black line shows the average number of shapes bought by telsend;--------------------- end of plot procedures------------------------------------------  ;--------------------- start log information -----------------------------------;purpose: write to the log files;when called: during the play;called by: the "turtle-trading" procedure;receives: none;returns: none;remarks: to do-logfilelocals [condition]    ask nodes[    ifelse (empty? areas-of self)    [set condition 1]    [set condition 0]      file-open "logfile"    file-print (word get-date-and-time "\t" current_round "\t" favoritism "\t"       cost_of_telecommuting "\t" #_of_distraction "\t" time_of_distraction "\t"      condition "\t" who "\t" item 0 shape_inventory "\t"       item 1 shape_inventory "\t" item 2 shape_inventory "\t"       item 3 shape_inventory "\t" item 4 shape_inventory "\t"       sum shape_inventory "\t" sell-to)        ]    file-close        file-open "roundlog"    file-print (word get-date-and-time "\t" current_round "\t" favoritism "\t" cost_of_telecommuting                "\t" #_of_distraction "\t" time_of_distraction                 "\t" c_inv "\t" t_inv "\t" c_c "\t" c_t "\t" t_t "\t" t_c)    file-closeend;--------------------- end log information -------------------------------------to find_edge [s_to s_from] ;node procedure  locals [cur_edge lines]     set cur_edge random-one-of edges with [(s_to = a and s_from = b) or (s_to = b and s_from = a)]     set lines ["line" "line1" "line2" "line3" "line4"]    if cur_edge != nobody [     ask cur_edge [        set shape item turtle_traffic lines        set color 96        set turtle_traffic turtle_traffic + 1        set label turtle_traffic     ]   ]       endto-report connected-to? [other-node]  ;; node procedure  report member? other-node (map [b-of ?] out-edges)endto connect-to [other-node]  ;; node procedure  hatch 1    [ set breed edges      set turtle_traffic 0      set color 81.7; 109.9      set a myself      set b other-node      set (out-edges-of a) lput self (out-edges-of a)      set (in-edges-of b) lput self (in-edges-of b);      set label who      reposition ]endto reposition  ;; edge procedure  setxy (xcor-of a) (ycor-of a)  set heading towards-nowrap b  set size distance-nowrap b  jump (distance-nowrap b) / 2endto form-edge [other-node];; node procedure;  set other-node random-one-of (nodes in-radius-nowrap 150 with [self != myself])  if (other-node != nobody) and     (not connected-to? other-node) and     (not value-from other-node [connected-to? myself])    [ connect-to other-node ]endto disappear  ;; edge procedure  set (out-edges-of a) remove self (out-edges-of a)  set (in-edges-of b) remove self (in-edges-of b)  dieend;--------------------------------------------------------to kill_links  if mouse-down? [     ask turtles-at round mouse-xcor round mouse-ycor [            disappear     ]   ]end;--------------------------------------------------------to node_draglocals [num]set num 0  while [mouse-down?]   [     ask turtles-at round mouse-xcor mouse-ycor [         if num = 0 [            set grabbed? true            set num 1        ]      ]          ask nodes with [ grabbed? ] [        without-interruption [            setxy mouse-xcor mouse-ycor           foreach out-edges [ ask ? [ reposition ] ]           foreach in-edges [ ask ? [reposition ] ]        ]      ]   ]      ask nodes [ set grabbed? false ]      set num 0  end ;--------------------------------------------------------to box_mouselocals[startx starty endx endy draw_turtle];  ask patches;     [;        set areas[]; ;    if ((pycor = (- screen-edge-y + 10) or pycor = screen-edge-y) and (pxcor >= (0 - 10) and pxcor <= screen-edge-x)) [;    set pcolor black;    ];    if ((pycor >= (- screen-edge-y + 10) and pycor <= screen-edge-y) and (pxcor = screen-edge-x or pxcor = (0 - 10) ))[;    set pcolor black

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -