pyorps.utils.neighborhood

PYORPS: An Open-Source Tool for Automated Power Line Routing

References: [1] Hofmann, M., Stetz, T., Kammer, F., Repo, S.: ‘PYORPS: An Open-Source Tool for

Automated Power Line Routing’, CIRED 2025 - 28th Conference and Exhibition on Electricity Distribution, 16 - 19 June 2025, Geneva, Switzerland

[2] Goodchild, M. F.: ‘An evaluation of lattice solutions to the problem of corridor

location’, Environment and Planning A: Economy and Space, 1977, 9, (7), pp 727-738

Functions

calculate_errors(directions, phi)

Calculate elongation error and maximum deviation for a given set of directions and path angle.

elongation_error(theta_j, theta_j_plus_1, phi)

Calculate the elongation error for a lattice path using Goodchild's formulation.

find_adjacent_directions(phi, directions)

Find the adjacent directions θ_j and θ_{j+1} such that θ_j < φ < θ_{j+1}.

find_max_errors(directions)

Find the maximum elongation error and maximum deviation for a given set of directions.

get_move_directions(moves)

Get all possible move directions in radians for a given move set.

get_neighborhood_steps(k[, directed])

Generate the steps for a k-neighborhood.

max_deviation(theta_j, theta_j_plus_1, phi)

Calculate the maximum deviation for a lattice path using Goodchild's formulation.

normalize_angle(angle)

Normalize an angle to the range [0, 2π).

pyorps.utils.neighborhood.get_neighborhood_steps(k, directed=True)[source]

Generate the steps for a k-neighborhood.

Parameters:
  • k (Union[int, str]) – The neighborhood parameter (k >= 0)

  • directed (bool) – If True, includes all possible step directions; if False, includes a minimal set of steps that ensures bidirectional connectivity in the graph

Returns:

A numpy array with dtype int8 containing all steps

Return type:

np.ndarray

References

[1]

pyorps.utils.neighborhood.normalize_angle(angle)[source]

Normalize an angle to the range [0, 2π).

Parameters:

angle (float) – Input angle in radians

Returns:

Normalized angle in the range [0, 2π)

Return type:

float

pyorps.utils.neighborhood.get_move_directions(moves)[source]

Get all possible move directions in radians for a given move set.

Parameters:

moves (np.ndarray) – Array of move vectors

Returns:

A sorted list of angles in radians [0, 2π)

Return type:

List[float]

pyorps.utils.neighborhood.find_adjacent_directions(phi, directions)[source]

Find the adjacent directions θ_j and θ_{j+1} such that θ_j < φ < θ_{j+1}.

Parameters:
  • phi (float) – The path direction in radians

  • directions (List[float]) – Sorted list of all possible move directions in radians

Returns:

A tuple (θ_j, θ_{j+1})

Return type:

Tuple[float, float]

pyorps.utils.neighborhood.elongation_error(theta_j, theta_j_plus_1, phi)[source]

Calculate the elongation error for a lattice path using Goodchild’s formulation.

The elongation error is given by: e(φ) = (sin(θ_{j+1} - φ) + sin(φ - θ_j)) / sin(θ_{j+1} - θ_j)

Parameters:
  • theta_j (float) – Lower adjacent direction in radians

  • theta_j_plus_1 (float) – Upper adjacent direction in radians

  • phi (float) – Path direction in radians

Returns:

The elongation error

Return type:

float

References

[2]

pyorps.utils.neighborhood.max_deviation(theta_j, theta_j_plus_1, phi)[source]

Calculate the maximum deviation for a lattice path using Goodchild’s formulation.

The maximum deviation is given by: δ(φ) = (sin(θ_{j+1} - φ) * sin(φ - θ_j)) / sin(θ_{j+1} - θ_j)

Parameters:
  • theta_j (float) – Lower adjacent direction in radians

  • theta_j_plus_1 (float) – Upper adjacent direction in radians

  • phi (float) – Path direction in radians

Returns:

The maximum deviation

Return type:

float

References

[2]

pyorps.utils.neighborhood.calculate_errors(directions, phi)[source]

Calculate elongation error and maximum deviation for a given set of directions and path angle.

Parameters:
  • directions (List[float]) – Sorted list of all possible move directions in radians

  • phi (float) – The path direction in radians

Returns:

A dictionary with the calculated errors

Return type:

Dict[str, float]

References

[2]

pyorps.utils.neighborhood.find_max_errors(directions)[source]

Find the maximum elongation error and maximum deviation for a given set of directions.

Parameters:

directions (List[float]) – Sorted list of all possible move directions in radians

Returns:

A dictionary with the maximum calculated errors

Return type:

Dict[str, float]