Tsp#
- class Tsp(graph)[fuente]#
Bases:
GraphOptimizationApplication
Optimization application for the «traveling salesman problem» [1] based on a NetworkX graph.
Referencias
[1]: «Travelling salesman problem», https://en.wikipedia.org/wiki/Travelling_salesman_problem
- Parámetros:
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
- graph#
Getter of the graph
- Devuelve:
A graph for a problem
Methods
- static create_random_instance(n, low=0, high=100, seed=None)[fuente]#
Create a random instance of the traveling salesman problem
- Parámetros:
- Devuelve:
A Tsp instance created from the input information
- Tipo del valor devuelto:
- draw(result=None, pos=None)#
Draw a graph with the result. When the result is None, draw an original graph without colors.
- Parámetros:
result (OptimizationResult | ndarray | None) – The calculated result for the problem
- static parse_tsplib_format(filename)[fuente]#
Read a graph in TSPLIB format from file and return a Tsp instance.
- Parámetros:
filename (str) – the name of the file.
- Muestra:
QiskitOptimizationError – If the type is not «TSP»
QiskitOptimizationError – If the edge weight type is not «EUC_2D»
- Devuelve:
A Tsp instance data.
- Tipo del valor devuelto:
- static sample_most_likely(state_vector)#
Compute the most likely binary string from state vector.
- Parámetros:
state_vector (QuasiDistribution | Statevector | ndarray | Dict) – state vector or counts or quasi-probabilities.
- Devuelve:
binary string as numpy.ndarray of ints.
- Muestra:
ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.
- Tipo del valor devuelto: