Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while using tspy package #1

Closed
skantbksc opened this issue Jan 27, 2020 · 1 comment
Closed

Error while using tspy package #1

skantbksc opened this issue Jan 27, 2020 · 1 comment

Comments

@skantbksc
Copy link

D = [[ 0, 60, 66, 258, 256, 682, 770, 888],
[ 60, 0, 50, 225, 213, 630, 719, 832],
[ 66, 50, 0, 275, 260, 618, 707, 829],
[258, 225, 275, 0, 52, 689, 772, 840],
[256, 213, 260, 52, 0, 637, 719, 789],
[682, 630, 618, 689, 637, 0, 88, 245],
[770, 719, 707, 772, 719, 88, 0, 181],
[888, 832, 829, 840, 789, 245, 181, 0]]

from tspy import TSP
tsp = TSP()

tsp.read_mat(D)

from tspy.solvers import TwoOpt_solver
two_opt = TwoOpt_solver(initial_tour='NN', iter_num=100)
two_opt_tour = tsp.get_approx_solution(two_opt)

The code does not exceute and gives the following error:
TypeError: list indices must be integers or slices, not tuple

@wborgeaud
Copy link
Owner

The problem is that read_mat takes a numpy matrix as argument (this is mentioned in the docs).
If you replace the first line by

import numpy as np
D = np.array([[...],...,[...]], np.float64)

the code runs as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants