我有这个问题:
创建一个程序,构造一 (1) 维的晶格并
100000 个站点。在这个格子中随机放置一些陷阱
分子,其浓度为 c。随机放置 1 个粒子
放在格子上并让它执行随机游走。在这次行走中
您不会设置时间限制,即您不会声明
具体步数。当粒子落下时行走就会停止
陷阱中............................................注意边界
状况。当粒子到达晶格的边界时
不应该让它逃脱,而应该留在格子里,
要么返回到原来的位置,要么被放置在
格子的对面位置........
我的方法显示在我创建的代码中(我在其中有注释)。
def steps1d(self,pos,c):
#pos: number of positions
#c: concentration of trap-particles
# array full of traps (zeros)
myzeros = sc.zeros(self.c*self.pos)
# grid full of available positions(ones)
grid = sc.ones(self.pos)
# distribute c*pos zeros(traps) in random positions (number of positions is pos)
traps = sc.random.permutation(pos)[:c*pos]
# the grid in which the particle is moving which has traps inside it
grid[traps] = myzeros
steps_count = [] # list which holds the number of steps
free = 0
for i in range(pos):
# the step of the particle can be 0 or 1
step=sc.random.random_integers(0,1)
for step in grid[:]:
if step == 1:
free += 1
steps_count.append(free)
else:
break
return steps_count
我有 3 个问题:
1)我以 pos=10 为例,结果如下:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 , 26, 27, 28, 29, 30, 31, 32, 33, 34, 35...]
我期望 1 次运行每个 10 个数字(可变位置)。
2)我不知道如何处理边界条件。我在想这样的事情:
if free > grid.size:
free = free - 1
但我无法测试它。另外,我不确定这是否适用于网格的两个边界。
3)如果我想第一步从网格中间开始,我该怎么做?
如果有人对此有提示,我将不胜感激。