import sys
import random
import numpy as np
import matplotlib.pyplot as plt
sys.setrecursionlimit(10**7)
nL,nC=100,100
a,b=50,50
c = 5
n=0
L=np.zeros((nL,nC))
T = []
def case_prox(L1:list,i,j):
l=len(L1)
return [[L1[(i 1)%l][j],(i 1)%l,j],[L1[(i-1)%l][j],(i-1)%l,j],[L1[i][(j 1)%l],i,(j 1)%l],[L1[i][(j-1)%l],i,(j-1)%l]]
def avancer(L,i,j):
global n,S,T,p
S = []
p = 0
while n<150:#global dans le while
a = random.randrange(0,len(case_prox(L,i,j)))
if L[case_prox(L,i,j)[a][1]][case_prox(L,i,j)[a][2]] == 0:
L[case_prox(L,i,j)[a][1]][case_prox(L,i,j)[a][2]] = 1
n =1
avancer(L,50,50)
S.append(p 1)
else:
avancer(L,case_prox(L,i,j)[a][1],case_prox(L,i,j)[a][2])
n =1
p =1
print(L)
L[50][50]=1
print(case_prox(L,30,30))
print(case_prox(L,30,30)[0][1],case_prox(L,30,30)[0][2])
avancer(L,50,50)
plt.plot(S)
我做了一個基于內部擴散有限聚合的演算法。主函式是遞回的,所以我必須多次呼叫該函式。我決定增加遞回限制,但問題沒有解決。該功能長時間作業并發揮作用。請問你能幫我嗎?
uj5u.com熱心網友回復:
我認為你想在 else 中呼叫 avancer 之前迭代 n ,否則你會冒無限回圈的風險......
def avancer(L,i,j):
global n,S,T,p
S = []
p = 0
while n<150:#global dans le while
a = random.randrange(0,len(case_prox(L,i,j)))
if L[case_prox(L,i,j)[a][1]][case_prox(L,i,j)[a][2]] == 0:
L[case_prox(L,i,j)[a][1]][case_prox(L,i,j)[a][2]] = 1
n =1
avancer(L,50,50)
S.append(p 1)
else:
n =1
avancer(L,case_prox(L,i,j)[a][1],case_prox(L,i,j)[a][2])
p =1
print(L)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/482929.html
上一篇:如何在遞回函式中獲取下一行
下一篇:VBA使用遞回獲取檔案(物件)
