gpt4 book ai didi

python - 在 Python 3.5 中运行 PyGMO

转载 作者:太空宇宙 更新时间:2023-11-03 17:09:29 25 4
gpt4 key购买 nike

我不知道我是否来对了地方,但我现在正在尝试在 64 位 Windows、Python 3.5.1 上运行一个需要 PyGMO 的程序。

我下载了 1.1.7 的 msi 版本(已下载 here ),运行安装程序,并尝试运行该程序,出现以下错误:

Traceback (most recent call last):
File "Desktop\test-1.py", line 4, in <module>
from PyGMO import *
File "C:\Users\ycl\Anaconda3\lib\site-packages\PyGMO\__init__.py", line 57, in <module>
from PyGMO import core, algorithm, migration, problem, topology, test, util
File "C:\Users\ycl\Anaconda3\lib\site-packages\PyGMO\core\__init__.py", line 2, in <module>
from PyGMO.core._core import *
ImportError: DLL load failed: The specified module could not be found.

该程序是一个像这样的脚本:

import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
from PyGMO import *
edge_weights = np.loadtxt("ir33_weight_matrix.txt", delimiter=',')
print(edge_weights[0])
areas = np.loadtxt("ir33_areas.txt", delimiter=',')
print(areas)
N = len(areas)
node_weights = [int(round(10000*areas[i])) for i in range(N)]
capacity = 1000
prob = problem.tsp(edge_weights, node_weights, capacity, type = 'cities')
pop = population(prob, 100)
steps = 3000
stepsize = 100
algo = algorithm.inverover(gen=stepsize,ri=0.05,type="random")
c = []
g = []
prev_f = 0
for i in range(steps):
pop = algo.evolve(pop)
f = pop.champion.f[0]
if prev_f != f:
c.append(pop.champion.x)
g.append((i+1)*stepsize)
prev_f = f
f, _, id1, id2 = prob.find_city_subsequence(pop.champion.x)
f = f*0.0001
if id1 <= id2:
visited_cities = c[-1][id1:(id2 + 1) % N]
else:
visited_cities = c[-1][id1:] + c[-1][:id2 + 1]

print("The fitness of the of the best found tour is: %f " % f)
print("The according removal sequence is: ")
print(visited_cities)

fig = plt.figure()
ax = plt.axes(xlim=(-10,N+10), ylim=(-0.05,1))
plt.ylabel('cross section area')
plt.xlabel('debris piece index')
line1, = ax.plot([],[], marker='o',markersize=10, alpha=0.7, linestyle='', color='r')
line2, = ax.plot([],[], marker='o',markersize=6, alpha=0.4, linestyle='', color='b')
generations_text = ax.text(0.05, 0.95, '', transform=ax.transAxes)
fitness_text = ax.text(0.40, 0.95, '', transform=ax.transAxes)
length_text = ax.text(0.75, 0.95, '', transform=ax.transAxes)

def init():
line1.set_data([], [])
line2.set_data([], [])
generations_text.set_text('')
fitness_text.set_text('')
length_text.set_text('')
return line1, line2, generations_text, fitness_text, length_text

def animate(ll):
f, _, id1, id2 = prob.find_city_subsequence(c[ll])
f = 0.0001*f
if id1 <= (id2 +1) % N:
visited_cities = c[ll][id1:(id2 + 1)]
else:
visited_cities = c[ll][id1:] + c[ll][:(id2 + 1) % N]

area_visited = [areas[i] for i in visited_cities]
not_visited_cities = [i for i in range(N) if i not in visited_cities]
area_not_visited = [areas[i] for i in not_visited_cities]

line1.set_data(visited_cities, area_visited)
line2.set_data(not_visited_cities, area_not_visited)
generations_text.set_text('generations = %d' % g[ll])
fitness_text.set_text('fitness = %.4f' % f)
length_text.set_text('tour length = %d' % len(visited_cities))
return line1, line2, generations_text, fitness_text, length_text

anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=len(g), interval=150, blit=True, repeat=False)
plt.show()

有人有这方面的经验吗?

我根本不知道在哪里可以找到 DLL...

最佳答案

您的问题可能是由 python 版本与 msi 期望的版本不匹配造成的。

无论如何,新的 pagmo ( https://github.com/esa/pagmo2 ) 通过 pipconda 为大多数 python 版本和 osx 提供二进制文件(最后一个是建议的选择,因为它避免了使用 boost::python 的多个包之间的库不兼容)
conda 安装 pygmo
或者,
pip 安装 pygmo
现在应该可以解决您的问题。请注意,新的 pagmo 语法已更改,请参阅文档了解更新。

关于python - 在 Python 3.5 中运行 PyGMO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34248989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com