# 个体位置轨迹产生的算法

Moving in a Neighborhood(MN) algorithm

``````import random

class dummy:
def __init__(self):
self.x = 0
self.y = 0
self.t = 0

def MovingInNeighborhood(m,n):

dummyPretemp = dummy() # 前一时刻用户位置及时间信息
dummyNexttemp = dummy() # 后一时刻用户位置及时间信息

# 用户位置及时间 初始化
dummyPretemp.x = 0
dummyPretemp.y = 0
dummyPretemp.t = 0
# 生成下一位置及时间信息
dummyNexttemp.x = random.randint( dummyPretemp.x - m, dummyPretemp.x + m )
dummyNexttemp.y = random.randint( dummyPretemp.y - m, dummyPretemp.y + m )
dummyNexttemp.t = dummyPretemp.t + 1

dummyNext= [ dummyNexttemp.x, dummyNexttemp.y, dummyNexttemp.t ]
dummyNext = [ dummyNext ]

i = 0
for i in range(n):
print i
print dummyNext
dummyPretemp = dummyNexttemp
# 生成下一位置及时间信息
dummyNexttemp.x = random.randint( dummyPretemp.x - m, dummyPretemp.x + m )
dummyNexttemp.y = random.randint( dummyPretemp.y - m, dummyPretemp.y + m )
dummyNexttemp.t = dummyPretemp.t + 1

dummyNext.append( [ dummyNexttemp.x, dummyNexttemp.y, dummyNexttemp.t ] )
i = i + 1

#print dummyA.x

MovingInNeighborhood(3,3)
``````
原文作者：SecondLife
原文地址: https://segmentfault.com/a/1190000000655778
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。