【发布时间】:2020-03-18 20:59:07
【问题描述】:
我实际上正在开发一个模拟来研究社会现象。 我的想法是一群特工选择离他们最近的工厂,向前走并(当他们到达时)回到他们的初始位置。 但是,我在编程时遇到了一些麻烦。一些特工只是经过他们的初始位置并到达我的模拟边界,停在那里。
这是我的代码:
breed [population person] ;create the population
breed [all-fac factory] ;create the factories
população-own [
myneighbor ;defines which factory is closer
myNND ;calculate the distance between the person and the closer factory
home-x ;initial x position
home-y ;initial y position
]
to setup
clear-all
reset-ticks
create-population 83 ; creates the population with 83 people in it
[
setxy random-xcor random-ycor ; set people initial position randomly
set shape "person"
set home-x xcor
set home-y ycor
]
create-all-fac 9
[
ask all-fac [ set color white]
ask facture 83 [ setxy 0 0 ] ; defines the initial position of every factory
ask facture 84 [ setxy 70 0]
ask facture 85 [ setxy -70 0 ]
ask facture 86 [ setxy 70 70 ]
ask facture 87 [ setxy 0 70 ]
ask facture 88 [ setxy -70 70 ]
ask facture 89 [ setxy 70 -70 ]
ask facture 90 [ setxy 0 -70 ]
ask facture 91 [ setxy -70 -70 ]
set shape "house"
]
end
to go
move
tick
choose-facture
end
to choose-facture
ask population [
set myneighbor min-one-of other fábricas [distance myself] ; choose my nearest neighbor based on distance
set myNND distance myneighbor
]
end
to move
ask population [
if xcor = home-x and ycor = home-y [
face myneighbor
fd 1
]
if any? all-fac in-radius 5 [
facexy home-x home-y
fd 1 ]
fd 1
]
end
如果有人可以帮助我,我将非常感激:)。
【问题讨论】:
标签: simulation netlogo agent