guofei9987 / scikit-opt

Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)
https://scikit-opt.github.io/scikit-opt/#/en/
MIT License
5.19k stars 985 forks source link

ACA算法发生除0问题 #209

Open chenwycool opened 1 year ago

chenwycool commented 1 year ago

当prob中的元素极限小时,prob.sum()会得到0值,发生除0,请考虑

  1. 将 next_point = np.random.choice(allow_list, size=1, p=prob)[0] 代码改为 if prob.sum() != 0: prob = prob / prob.sum() # 概率归一化 next_point = np.random.choice(allow_list, size=1, p=prob)[0] else: next_point = np.random.choice(allow_list, size=1)[0] 或者 2.将 prob = prob / prob.sum() 代码改为 prob = prob / prob.sum() + 1e-10