pyepo.model.utils

Problem-level helpers for optimization model construction.

Classes

unionFind

Union-Find data structure for cycle detection in graphs

Functions

getTspTour(→ list[int])

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
find(i: int) int
union(i: int, j: int) bool
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 sol

  • num_nodes – number of nodes in the TSP instance

  • sol – solution values aligned with edge_list; an edge is considered active when its value exceeds threshold

  • threshold – activation threshold for an edge

Returns:

node sequence of the tour, starting and ending at node 0

Return type:

list

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).