关于存活时间编程
在t 1时候,crt 100,此时turtle 的存活时间为1,所有turtles的变量为m;在t 2时候,crt 100,此时t 1 turtle 的存活时间为2, turtles的变量为2m;而新造的turtles的存活时间为1,turtles的变量为m;
在t 3时候,crt 100,此时t 1 turtle 的存活时间为3,turtles的变量为3m;而t2 turtles的存活时间为2,turtles的变量为2m;而新造的turtles的存活时间为1,turtles的变量为m;
不断进行下去,到t n时停止
如何用logo语言将t n时段所有turtles的变量表达出来呢? 可以这么理解,就是程序跑完一遍,时间就加1
问题是这样的
globals [tenergy
]
;;energy为个体的能量,m为每阶段所有个体energy的均值
to setup
ca
setup-turtles
end
to setup-turtles
set-default-shape turtles "person"
create-persons 100 [ setxy random-xcor random-ycor
set color white
set energy random-normal 0.5 0.15 ]
end
to go
ifelse t < 60
[hire
socialize
set t t + 1]
tick
end
to hire
create-persons 20 [ setxy random-xcor random-ycor
set color white
set energy random-normal 0.5 0.15 ]
end
to socialize
setm mean [ energy ]of persons
ask persons [set energy( energy + 0.02*t);;???这里有问题:这样的话所有人的energy都乘以相同的 t ,但在hire程序中,那些新造的人的存活时间并不是全局间t,比如在t为30的时间段,t为13时段时造的人的存活时间为(30 - 13),而我要表达的就是怎没让0.02*t中的t代表人的真实地存活时间。高手赐教阿!!!
end
如果这样
globals [t
energy
n;;n为新造的人的时间
]
;;energy为个体的能量,m为每阶段所有个体energy的均值
to setup
ca
setup-turtles
end
to setup-turtles
set-default-shape turtles "person"
create-persons 100 [ setxy random-xcor random-ycor
set color white
set energy random-normal 0.5 0.15
]
end
to go
ifelse t < 60
[hire
socialize
set t t + 1]
tick
end
to hire
create-persons 20 [ setxy random-xcor random-ycor
set color white
set energy random-normal 0.5 0.15
setnt ] 在这里将新人的进入时间给定住
end
to socialize
setm mean [ energy ]of persons
ask persons [set energy( energy + 0.02*(t - n))不知这样改动后(t - n)能不能表示所有人的真实的存活时间。
end
[ 本帖最后由 wjcpcahu 于 2008-4-16 12:04 编辑 ] turtles-own
to setup
ca
setup-turtles
end
to setup-turtles
set-default-shape turtles"person"
create-turtles 100 [setxy random-xcor random-ycor
set color white
set initial-energy random-normal 0.5 0.15
]
end
to go
ifelse ticks < 5
[hire
tick
socialize
]
end
to hire
create-turtles 20 [setxy random-xcor random-ycor
set color white
set initial-energy random-normal 0.5 0.15
]
end
to socialize
ask turtles[
set s-time s-time + 1
set energy s-time * initial-energy
do-plots show-m
]
end
to do-plots
set-current-plot "total"
set-current-plot-pen "turtles"
plot count turtles
set-current-plot-pen "energy"
plot of turtle 1
end
to show-m
show of turtle 1
end 感谢啊 很专业
页:
[1]