Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Make graph from matrix


I'm a new user of SageMath and maybe my question is very simple or already answered somewhere but I wasn't able to find an answer to my problem. For my studies I have to implement a brute-force algorithm for solving the travelling salesman problem. I found out, that SM already has a solver for this problem that handles Graph - objects. I wan't to use it to check the results of my algorithm. I wrote some input data as a dictionary to feed into both alg, but if I wan't to do it for more than a few cities (I can handle only a few with bruteforce anyway because of the time it takes to calculate all the possibilities) and I've found a matrix with distances between cities. It is available here

https:// (ha30_dist.txt)

I threw the first two lines out and I can import this file with numpy.loadtxt(). But later, when I try to make Graph using this matrix, I get the error: "ValueError: There must be one or two nonzero entries per column in an incidence matrix. Got entries [39, 22, 59, 54...". What am I doing wrong?