Tsp¶
- class Tsp(graph)[source]¶
Bases:
GraphOptimizationApplication
Optimization application for the “traveling salesman problem” [1] based on a NetworkX graph.
References
[1]: “Travelling salesman problem”, https://en.wikipedia.org/wiki/Travelling_salesman_problem
- Parameters:
graph (Graph | ndarray | List) – A graph representing a problem. It can be specified directly as a NetworkX graph, or as an array or list format suitable to build out a NetworkX graph.
Attributes
Methods
create_random_instance
(n[, low, high, seed])Create a random instance of the traveling salesman problem
interpret
(result)Interpret a result as a list of node indices
parse_tsplib_format
(filename)Read a graph in TSPLIB format from file and return a Tsp instance.
Convert a traveling salesman problem instance into a
QuadraticProgram
tsp_value
(z, adj_matrix)Compute the TSP value of a solution.