qiskit.optimization.applications.ising.tsp¶
Convert symmetric TSP instances into Pauli list Deal with TSPLIB format. It supports only EUC_2D edge weight type. See https://wwwproxy.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/ and http://elib.zib.de/pub/mp-testdata/tsp/tsplib/tsp/index.html Design the tsp object w as a two-dimensional np.array e.g., w[i, j] = x means that the length of a edge between i and j is x Note that the weights are symmetric, i.e., w[j, i] = x always holds.
Functions
|
calculate distance |
|
Generate Hamiltonian for TSP of a graph. |
Get graph solution from binary string. |
|
|
Read graph in TSPLIB format from file. |
|
Generate a random instance for TSP. |
|
Check whether a solution is feasible or not. |
|
Compute the TSP value of a solution. |
Classes
|
Create new instance of TspData(name, dim, coord, w) |
- class TspData(name, dim, coord, w)¶
Create new instance of TspData(name, dim, coord, w)
- property coord¶
Alias for field number 2
- count(value, /)¶
Return number of occurrences of value.
- property dim¶
Alias for field number 1
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- property name¶
Alias for field number 0
- property w¶
Alias for field number 3
- get_operator(ins, penalty=100000.0)[source]¶
Generate Hamiltonian for TSP of a graph.
- Parameters
ins (TspData) – TSP data including coordinates and distances.
penalty (float) – Penalty coefficient for the constraints
- Returns
operator for the Hamiltonian and a constant shift for the obj function.
- Return type
tuple(WeightedPauliOperator, float)
- get_tsp_solution(x)[source]¶
Get graph solution from binary string.
- Parameters
x (numpy.ndarray) – binary string as numpy array.
- Returns
sequence of cities to traverse.
- Return type
list[int]
- logger = <Logger qiskit.optimization.applications.ising.tsp (WARNING)>¶
Instance data of TSP
- parse_tsplib_format(filename)[source]¶
Read graph in TSPLIB format from file.
- Parameters
filename (str) – name of the file.
- Returns
instance data.
- Return type
- random_tsp(n, low=0, high=100, savefile=None, seed=None, name='tmp')[source]¶
Generate a random instance for TSP.
- Parameters
n (int) – number of nodes.
low (float) – lower bound of coordinate.
high (float) – upper bound of coordinate.
savefile (str or None) – name of file where to save graph.
seed (int or None) – random seed - if None, will not initialize.
name (str) – name of an instance
- Returns
instance data.
- Return type