Reference¶
Construction¶
-
robotsp.construct.
from_coordinate_list
(coordinates, distfn=None, args=(), weight='weight')[source]¶ Construct a
nx.Graph
using the input coordinatesParameters: - coordinates (list) – The input coordinates
- distfn (Callable, optional) – The function to be used to compute the distance/weight between nodes. If
None,
robotsp.metric.euclidean_fn()
will be used. - args (tuple, optional) – Additional arguments to be passed to the
distfn
- weight (str, optional) – Use this edge attribute as the edge weight
Returns: rotated – The rotated tour
Return type: list
Metrics¶
Parser¶
-
class
robotsp.parser.
SUPPORTED_PROBLEM_TYPES
[source]¶ Bases:
enum.Enum
-
GTSP
= <SUPPORTED_PROBLEM_TYPES.GTSP: 2>¶
-
TOUR
= <SUPPORTED_PROBLEM_TYPES.TOUR: 3>¶
-
TSP
= <SUPPORTED_PROBLEM_TYPES.TSP: 1>¶
-
-
class
robotsp.parser.
SUPPORTED_WEIGHT_FORMATS
[source]¶ Bases:
enum.Enum
-
FULL_MATRIX
= <SUPPORTED_WEIGHT_FORMATS.FULL_MATRIX: 2>¶
-
LOWER_DIAG_ROW
= <SUPPORTED_WEIGHT_FORMATS.LOWER_DIAG_ROW: 1>¶
-
Solvers¶
Traveling Salesman Problem¶
-
robotsp.tsp.
nearest_neighbor
(graph, restarts=10, weight='weight')[source]¶ Recursive Nearest-Neighbor algorithm to solve the traveling salesman problem.
These are the steps of the algorithm for each restart:
- Start on a random node as current node;
- Find the shortest edge connecting the current node with an unvisited node;
- Mark the found node as current and visited;
- Go to step 2 until all nodes are visited
Parameters: - graph (NetworkX graph) –
- restarts (int, optional (default=10)) – Number of times the algorithm will try a different, randomly selected, node as starting point
- weight (string, optional (default='weight')) – Edge data key corresponding to the edge weight
Returns: best_tour – The sequence for visiting all the nodes
Return type: list
-
robotsp.tsp.
rotate_tour
(tour, start=0)[source]¶ Rotate a tour so that it starts at the given
start
index. This is equivalent to rotate the input list to the left.Parameters: - tour (list) – The input tour
- start (int, optional (default=0)) – New start index for the tour
Returns: rotated – The rotated tour
Return type: list