The TSP solver assumes you have weighted edges already. See that documentation for ways to either add edges one by one, or you can separately use add_edge_label. In any case, you'll have to probably take your matrix and programmatically use those values to set the edge labels. Probably by going through the columns, and then through the rows in each column - but watch out, since such a matrix had better be symmetric, so you only need the first i-1 entries of the ith column, I suppose!