Может ли кто-нибудь помочь мне вычислить после каждой итерации самую дальнюю точку от созданной точки?
Это агентная модель, которую я создал с помощью Netlogo и теперь пытаюсь перенести ее на Python.
Что касается того, какое расстояние было использовано, я действительно могу сказать, так как я использовал предопределенную функцию для его вычисления, извините за это.
import random
class Bug:
def __init__(self, number, xPos, yPos, worldXSize = 80, worldYSize = 80):
# the environment
self.number = number
self.worldXSize = worldXSize
self.worldYSize = worldYSize
# the bug
self.xPos = xPos
self.yPos = yPos
print ("Bug number ", self.number, \
" has been created at ", self.xPos, ", ", self.yPos)
# the action
def randomWalk(self):
self.xPos += randomMove()
self.yPos += randomMove()
self.xPos = (self.xPos + self.worldXSize) % self.worldXSize
self.yPos = (self.yPos + self.worldYSize) % self.worldYSize
# report
def reportPosition(self):
print ("Bug number ", self.number, " moved to X = ", \
self.xPos, " Y = ", self.yPos)
# returns -1, 0, 1 with equal probability
def randomMove():
return random.randint(-1, 1)
nBugs = input("How many bugs? ")
#bugList = [0] * nBugs
bugList=[]
worldXSize= input("X Size of the world? ")
worldYSize= input("Y Size of the world? ")
length = input("Length of the simulation in cycles? ")
for i in range(nBugs):
aBug = Bug(i, random.randint(0,worldXSize-1), \
random.randint(0,worldYSize-1),
worldXSize, worldYSize)
bugList.append(aBug)
for t in range(length):
for aBug in bugList:
aBug.randomWalk()
aBug.reportPosition()
Оригинальная модель на netlogo такова:
to setup
clear-all
create-turtles nBugs
reset-ticks
end
to go
tick
if ticks >= nCycles [stop]
ask turtles
[ set xcor xcor + random 3 - 1
set ycor ycor + random 3 - 1
type "I'm agent " type who type " and the farthest turtle from me is " print max-one-of turtles [distance myself]
]
end