Hello.
I try to use acopy in the graph which was made by networkx.
import acopy
import tsplib95
import networkx as nx
import random
import matplotlib.pyplot as plt
solver = acopy.Solver(rho=.03, q=1)
colony = acopy.Colony(alpha=1, beta=3)
// try to use graph made by networkx
G = nx.fast_gnp_random_graph(10, 0.9)
for (u, v) in G.edges():
G.edges[u, v]['weight'] = random.randint(1, 1000)
tour = solver.solve(G, colony, limit=100)
nx.draw_networkx(G)
plt.show()
print(tour.cost)
print(tour.path)
But when I run this code, the error occured below.
Traceback (most recent call last):
File "/Users/students/Desktop/keras_aco/main.py", line 15, in <module>
tour = solver.solve(G, colony, limit=100)
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/solvers.py", line 193, in solve
for solution in self.optimize(*args, **kwargs):
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/solvers.py", line 225, in optimize
solutions = self.find_solutions(state.graph, state.ants)
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/solvers.py", line 259, in find_solutions
return [ant.tour(graph) for ant in ants]
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/solvers.py", line 259, in <listcomp>
return [ant.tour(graph) for ant in ants]
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/ant.py", line 57, in tour
node = self.choose_destination(graph, solution.current, unvisited)
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/ant.py", line 110, in choose_destination
scores = self.get_scores(graph, current, unvisited)
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/acopy/ant.py", line 125, in get_scores
edge = graph.edges[current, node]
File "/Users/students/.pyenv/versions/keras_aco_env/lib/python3.6/site-packages/networkx/classes/reportviews.py", line 930, in __getitem__
return self._adjdict[u][v]
KeyError: 0
I think that acopy's ant tried to use the edge which doesn't exists.
So, error occured.
Thank you, and sorry for bad english.