扩展模型

时间:2018-12-28 01:21:30

标签: netlogo

我是Netlogo初学者。我正在尝试通过将除糖以外的“咖啡盐豆和小扁豆”添加到糖区中来扩展糖景模型。 该文件中的.txt文件提供了该区域中资源的分布(现在只有糖)。

我试图通过添加其他资源管理器来改变糖的“乌龟拥有”,“补丁拥有”和其他程序,但似乎无济于事。

致谢

    turtles-own [
  sugar           ;; the amount of sugar this turtle has
  metabolism      ;; the amount of sugar that each turtles loses each tick
  vision          ;; the distance that this turtle can see in the horizontal and vertical directions
  vision-points   ;; the points that this turtle can see in relative to it's current position (based on vision)
]
patches-own [
  psugar           ;; the amount of sugar on this patch
  max-psugar       ;; the maximum amount of sugar that can be on this patch
]
;;
;; Setup Procedures
;;
to setup
  clear-all
  create-turtles initial-population [ turtle-setup ]
  setup-patches
  reset-ticks
end
to turtle-setup ;; turtle procedure
  set color red
  set shape "circle"
  move-to one-of patches with [not any? other turtles-here]
  set sugar random-in-range 5 25
  set metabolism random-in-range 1 4
  set vision random-in-range 1 6
  ;; turtles can look horizontally and vertically up to vision patches
  ;; but cannot look diagonally at all
  set vision-points []
  foreach (range 1 (vision + 1)) [ n ->
    set vision-points sentence vision-points (list (list 0 n) (list n 0) (list 0 (- n)) (list (- n) 0))
  ]
  run visualization
end
to setup-patches
  file-open "sugar-map.txt"
  foreach sort patches [ p ->
    ask p [
      set max-psugar file-read
      set psugar max-psugar
      patch-recolor
    ]
  ]
  file-close
end
;;
;; Runtime Procedures
;;
to go
  if not any? turtles [
    stop
  ]
  ask patches [
    patch-growback
    patch-recolor
  ]
  ask turtles [
    turtle-move
    turtle-eat
    if sugar <= 0
      [ die ]
    run visualization
  ]
  tick
end
to turtle-move ;; turtle procedure
  ;; consider moving to unoccupied patches in our vision, as well as staying at the current patch
  let move-candidates (patch-set patch-here (patches at-points vision-points) with [not any? turtles-here])
  let possible-winners move-candidates with-max [psugar]
  if any? possible-winners [
    ;; if there are any such patches move to one of the patches that is closest
    move-to min-one-of possible-winners [distance myself]
  ]
end
to turtle-eat ;; turtle procedure
  ;; metabolize some sugar, and eat all the sugar on the current patch
  set sugar (sugar - metabolism + psugar)
  set psugar 0
end
to patch-recolor ;; patch procedure
  ;; color patches based on the amount of sugar they have
  set pcolor (yellow + 4.9 - psugar)
end
to patch-growback ;; patch procedure
  ;; immediately grow back all of the sugar for the patch
  set psugar max-psugar
end
;;
;; Utilities
;;
to-report random-in-range [low high]
  report low + random (high - low + 1)
end
;;
;; Visualization Procedures
;;
to no-visualization ;; turtle procedure
  set color red
end
to color-agents-by-vision ;; turtle procedure
  set color red - (vision - 3.5)
end
to color-agents-by-metabolism ;; turtle procedure
  set color red + (metabolism - 2.5)
end

0 个答案:

没有答案