pyepo.model.utils¶
Problem-level helpers for optimization model construction.
Classes¶
Union-Find data structure for cycle detection in graphs |
Functions¶
|
Reconstruct a TSP tour from an undirected edge-selection vector. |
Module Contents¶
- class pyepo.model.utils.unionFind(n: int)¶
Union-Find data structure for cycle detection in graphs
- parent¶
- pyepo.model.utils.getTspTour(edge_list: list[tuple[int, int]], num_nodes: int, sol: numpy.ndarray | torch.Tensor | list, threshold: float = _EDGE_ACTIVE_TOL) list[int]¶
Reconstruct a TSP tour from an undirected edge-selection vector.
- Parameters:
edge_list – undirected edges of the model, ordered to match
solnum_nodes – number of nodes in the TSP instance
sol – solution values aligned with
edge_list; an edge is considered active when its value exceedsthresholdthreshold – activation threshold for an edge
- Returns:
node sequence of the tour, starting and ending at node 0
- Return type:
- Raises:
ValueError – if the solution does not form a single Hamiltonian tour closed back to node 0 (skips nodes, contains disconnected subtours, or the last visited node is not adjacent to 0).