在安装时一次创建海龟一次,而不是每次创建一次

时间:2018-09-06 10:15:59

标签: netlogo agent

在我的程序中,乌龟品种的CO2初始浓度为10,而乌龟品种的葡萄糖将从10开始,每个滴答增加10(如设定饲料程序所述)。该程序包括乌龟繁殖细菌,每个tick虱都吃掉CO2和葡萄糖。问题是,按照我当前的代码,海龟,二氧化碳和葡萄糖的繁殖都增加了每只tick。我当前的输出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

;;;;;;;;;;;;;;帮助程序

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

1 个答案:

答案 0 :(得分: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