TSP
sgptools.utils.tsp
¶
resample_path(waypoints, num_inducing=10)
¶
Resamples a given path (sequence of waypoints) to have a fixed number of
num_inducing
points. This is useful for standardizing path representations
or for converting a path with an arbitrary number of waypoints into a
fixed-size representation for models. The resampling maintains the path's
shape and geometric integrity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
waypoints
|
ndarray
|
(num_waypoints, ndim); A NumPy array representing the
waypoints of a path. |
required |
num_inducing
|
int
|
The desired number of points in the resampled path. Defaults to 10. |
10
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: (num_inducing, ndim); The resampled path with |
Raises:
Type | Description |
---|---|
Exception
|
If the input |
Usage
import numpy as np
from sgptools.utils.tsp import resample_path
# Example 2D path
original_path_2d = np.array([[0,0], [1,5], [3,0], [5,5]], dtype=np.float64)
resampled_path_2d = resample_path(original_path_2d, num_inducing=5)
# Example 3D path
original_path_3d = np.array([[0,0,0], [1,1,1], [2,0,2]], dtype=np.float64)
resampled_path_3d = resample_path(original_path_3d, num_inducing=7)
Source code in sgptools/utils/tsp.py
run_tsp(nodes, num_vehicles=1, max_dist=25.0, depth=1, resample=None, start_nodes=None, end_nodes=None, time_limit=10)
¶
Method to run TSP/VRP with arbitrary start and end nodes, and without any distance constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
ndarray
|
(# nodes, ndim); Nodes to visit. |
required |
num_vehicles
|
int
|
Number of robots/vehicles. |
1
|
max_dist
|
float
|
Maximum distance allowed for each path when handling multi-robot case. |
25.0
|
depth
|
int
|
Internal parameter used to track re-try recursion depth. |
1
|
resample
|
Optional[int]
|
Each solution path will be resampled to have
|
None
|
start_nodes
|
Optional[ndarray]
|
(# num_vehicles, ndim); Optional array of start nodes from which to start each vehicle's solution path. |
None
|
end_nodes
|
Optional[ndarray]
|
(# num_vehicles, ndim); Optional array of end nodes at which to end each vehicle's solution path. |
None
|
time_limit
|
int
|
TSP runtime time limit in seconds. |
10
|
Returns:
Type | Description |
---|---|
Tuple[Optional[ndarray], Optional[List[float]]]
|
Tuple[Optional[np.ndarray], Optional[List[float]]]: - paths (np.ndarray): Solution paths if found, otherwise None. - distances (List[float]): List of path lengths if paths are found, otherwise None. |
Source code in sgptools/utils/tsp.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|