在设置时创建海龟ONCE,而不是在每个刻度中创建

问题描述 投票:0回答:1

在我的计划中,海龟品种二氧化碳的初始浓度为10,海龟品种葡萄糖将从10开始,每个滴答增加10(如设置 - 饲料程序中所述)。该过程包括一种龟类繁殖细菌,它们每次滴答吃二氧化碳和葡萄糖。问题是,根据我目前的代码,海龟,二氧化碳和葡萄糖的种类增加每个蜱。我当前的输出Excel如下所示:

enter image description here

我希望我的输出Excel看起来像这样:

enter image description here

对此问题有任何意见或建议吗?

Breed [glucose a-glucose];; Glucose
Breed [CO2s CO2]
Breed [bacteria bacterium]

 glucose-own [glucose_mass] 
 bacteria-own [bacteria_mass]
 CO2s-own [CO2s_mass]

Globals
[
time

Initial_concentration_glucose
Initial_concentration_CO2s
total_glucose
total_CO2s
]

to setup
  clear-all
  set time 0
  set Initial_concentration_glucose 0 
  set Initial_concentration_CO2s 0
  set total_glucose 0
  set total_CO2s 0

;;; BACTERIA;;;
  set-default-shape bacteria "default"
  create-bacteria (20)
  [ set color cyan
   set bacteria_mass 20 / 20
  ]
 ;;; CO2s;;;
  set-default-shape CO2s "circle"
  create-CO2s (10)
  [set color orange
   set CO2s_mass (10 / 10)
    setxy random-xcor random-ycor
   ]

  setup-feed
  output-1
  reset-ticks
end

to setup-feed

  set-default-shape glucose "circle";; Glucose shape
  Create-glucose (10) 
  [
   set glucose_mass 10 / 10
   setxy random-xcor random-ycor
  ]

end

to output-1
if (file-exists? "TestINOUT-AD.csv") [carefully [file-delete "TestINOUT-AD.csv"] [print error-message]]
   file-open "TestINOUT-AD.csv"
      file-type "tick,"
      file-type "Initial_concentration_glucose,"
      file-type "Initial_concentration_CO2s,"
      file-type "Bacteria,"
      file-type "CO2s,"
      file-print "glucose,"
   file-close
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;程序;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
   if not any? turtles [stop]

  Calculate_concentrations

  ask bacteria
   [ eat
  ]

  set time time + 1

  count_glucose
  count_CO2s

  output-2

 tick

if (time = 72) [stop]

end

;;;;;;;;;;;;;;; HELPER PROCEDURES

to Calculate_concentrations
  set Initial_concentration_glucose (Initial_concentration_glucose + sum [glucose_mass] of glucose + 0.0000001)
   set Initial_concentration_CO2s (Initial_concentration_CO2s + sum [CO2s_mass] of CO2s + 0.0000001)
end

to eat
  let prey one-of glucose-here
  if prey != nobody
  [ask prey [die]]

   let prey2 one-of CO2s-here
  if prey2 != nobody
  [ask prey2 [die]]

end


to output-2
  file-open "TestINOUT-AD.csv"
   file-type ticks file-type ","
   file-type Initial_concentration_glucose file-type ","
   file-type Initial_concentration_CO2s file-type ","
  file-type total_CO2s file-type ","
   file-print total_glucose 
  file-close
end

to count_glucose
  set total_glucose (total_glucose + sum [glucose_mass] of glucose)
end

 to count_CO2s
    set total_CO2s (total_CO2s + sum [CO2s_mass] of CO2s )
end
netlogo agent
1个回答
2
投票

没有创建海龟,你的程序count_glucose是glucose_mass的累积总和,这是你文件中输出的内容。但是你的问题表明你认为这是报告葡萄糖药物的数量。

to count_glucose
  set total_glucose (total_glucose + sum [glucose_mass] of glucose)
end

如果你真的想要计算葡萄糖剂,那么你想要count glucose

file-print count glucose

代替:

file-print total_glucose
© www.soinside.com 2019 - 2024. All rights reserved.