Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting this openopt index error?
    text
    copied!<p>First, the error:</p> <pre><code>Traceback (most recent call last): File "tsp_solver.py", line 57, in &lt;module&gt; solvetTSP(inputData) NameError: name 'solvetTSP' is not defined new-host:tsp Jonathan$ python tsp_solver.py data/tsp_51_1 Traceback (most recent call last): File "tsp_solver.py", line 57, in &lt;module&gt; solveTSP(inputData) File "tsp_solver.py", line 36, in solveTSP r = p.solve('sa') File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/openopt-0.506-py2.7.egg/openopt/kernel/TSP.py", line 150, in solve EdgesCoords.append((node, Out_nodes[i])) IndexError: index 1 is out of bounds for axis 0 with size 1 </code></pre> <p>I have literally no idea why am I getting this error. I have a pretty basic OpenOpt TSP solver instance here, and it completely doesn't work. I'm using networkx for the graphs, and just adding edge by edge with weight = distance. The error happens when I pass the TSP instance to the solver, but I clearly don't know why. Here's my code, any help would be immensely appreciated. </p> <pre><code>from openopt import * import networkx as nx import math def length(point1, point2): return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def solveTSP(inputData): inputData = inputData.split('\n') inputData.pop(len(inputData) - 1) N = int(inputData.pop(0)) points = [] for i in inputData: point = i.split(" ") point = [float(x) for x in point] point = tuple(point) points.append(point) G = nx.Graph() prev_point = None for cur_point in points: assert(len(cur_point) == 2) if prev_point != None: a = length(cur_point, prev_point) G.add_edge(cur_point, prev_point, weight = a) else: G.add_node(cur_point) prev_point = cur_point p = TSP(G, objective = 'weight', start = 0) r = p.solve('sa') r.nodes.pop(len(r.nodes)-1) distance = r.ff path = r.nodes print distance print path import sys if __name__ == '__main__': if len(sys.argv) &gt; 1: fileLocation = sys.argv[1].strip() inputDataFile = open(fileLocation, 'r') inputData = ''.join(inputDataFile.readlines()) inputDataFile.close() solveTSP(inputData) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload