optiwindnet.api¶

Module Contents¶

optiwindnet.api.logger[source]¶
class optiwindnet.api.Router[source]¶

Bases: abc.ABC

Abstract base class for routing algorithms in OptiWindNet.

Each Router implementation must define a route method.

abstractmethod route(P: networkx.PlanarEmbedding, A: networkx.Graph, cables: list[tuple[int, float]], cables_capacity: int, verbose: bool, **kwargs) tuple[networkx.Graph, networkx.Graph][source]¶

Run the routing optimization.

Parameters:
  • P – Navigation mesh for the location.

  • A – Graph of available links.

  • cables – set of cable specifications as [(capacity, linear_cost), …].

  • cables_capacity – highest cable capacity in cables.

  • verbose – Whether to print progress/logging info.

  • **kwargs – Additional router-specific parameters.

Returns:

Solution topology (selected links). G : Optimized network graph with routes and cable types.

Return type:

S

class optiwindnet.api.WindFarmNetwork(cables: int | list[int] | list[tuple[int, float]] | numpy.ndarray, turbinesC: numpy.ndarray | None = None, substationsC: numpy.ndarray | None = None, borderC: numpy.ndarray = np.empty((0, 2), dtype=np.float64), obstacleC_: Sequence[numpy.ndarray] = [], name: str = '', handle: str = '', L: networkx.Graph | None = None, router: Router | None = None, verbose: bool = False)[source]¶

Wind farm electrical network.

Wrapper of most of OptiWindNet’s functionality (optimization, visualization, cost/length evaluation, and gradient calculation).

An instance represents a wind farm location, which initially contains the number and positions of wind turbines and substations, the delimited area and eventual obstacles. A cable network may be provided or a Router instance may be used to create an optimized network.

Initialize a wind farm electrical network.

Parameters:
  • cables – Multiple formats are accepted (capacity is in number of turbines): * Set of cable specifications as: [(capacity, linear_cost), …]. * Sequence of maximum capacity per cable type: [capacity_0, capacity_1, …] * Maximum capacity of all available cables: capacity

  • turbinesC – Turbine coordinates (T, 2): [(x, y), …].

  • substationsC – Substation coordinates (R, 2): [(x, y), …].

  • borderC – Polygonal border coordinates (_, 2): [(x, y), …].

  • obstacleC – One or more polygons for exclusion zones list of (_, 2): [[(x, y), …], …].

  • name – Human-readable instance name. Defaults to “”.

  • handle – Short instance identifier. Defaults to “”.

  • L – Location geometry (takes precedence over coordinate inputs).

  • router – Routing algorithm instance. Defaults to EWRouter.

  • buffer_dist – Buffer distance to dilate borders / erode obstacles. Defaults to 0.

Notes

  • If both L and coordinates are provided, L takes precedence.

  • Changing coordinate data after creation (turbinesC and/or substationsC)

    rebuilds L and refreshes the navigation mesh and available links.

Example:

wfn = WindFarmNetwork(
  cables=[(3, 100.0), (5, 150.0)],
  turbinesC=np.array([[0, 0], [1, 0], [0, 1]]),
  substationsC=np.array([[10, 0]]),
)
wfn.optimize()
print(wfn.cost(), wfn.length())
name = ''[source]¶

Instance name.

handle = ''[source]¶

Short instance identifier.

property router: Router[source]¶

Router instance used for optimization.

property cables: list[tuple[int, float]][source]¶

Set of cable specifications as [(capacity, linear_cost), …].

verbose = False[source]¶

Enable verbose logging.

property L: networkx.Graph[source]¶

Location geometry (turbines, substations, borders, obstacles).

property polygon: shapely.Polygon | shapely.MultiPolygon | None[source]¶

Shapely (Multi)Polygon that bounds the cable-laying area.

property P: networkx.PlanarEmbedding[source]¶

Triangular mesh over L (navigation mesh).

property A: networkx.Graph[source]¶

Available links graph (search space).

property S: networkx.Graph[source]¶

Solution topology (selected links).

property G: networkx.Graph[source]¶

Optimized network with cable routes and types.

property buffer_dist: float[source]¶

Buffer distance applied to dilate borders / erode obstacles.

cost() float[source]¶

Get the total cost of the optimized network.

length() float[source]¶

Get the total cable length of the optimized network.

plot_original_vs_buffered(**kwargs) matplotlib.axes.Axes | None[source]¶

Plot original and buffered borders and obstacles on a single plot.

Parameters:

**kwargs – passed to matplotlib’s pyplot.figure()

Returns:

matplotlib Axes instance.

classmethod from_yaml(filepath: str, **kwargs)[source]¶

Create a WindFarmNetwork instance from a YAML file.

classmethod from_pbf(filepath: pathlib.Path | str, **kwargs)[source]¶

Create a WindFarmNetwork instance from a .OSM.PBF file.

classmethod from_windIO(filepath: pathlib.Path | str, **kwargs)[source]¶

Create a WindFarmNetwork instance from WindIO yaml file.

plot(*args, **kwargs)[source]¶

Plot the optimized network.

plot_location(**kwargs)[source]¶

Plot the original location geometry.

Plot available links from planar embedding.

plot_navigation_mesh(**kwargs)[source]¶

Plot navigation mesh (planar graph and adjacency).

Plot tentative link selection.

Get a compact representation of the solution topology.

Update the network from terse link representation.

Accepts integers or integer-like floats (e.g., 3.0).

get_network()[source]¶

Export the optimized network as a structured array.

map_detour_vertex()[source]¶

Map detour vertices back to their original coordinate indices.

merge_obstacles_into_border()[source]¶
add_buffer(buffer_dist)[source]¶

Dilate the cable-laying area by buffer_dist.

Useful if boundaries are not strictly enforced during optimization. This may happen if boundary compliance is achieved through the application of penalties for violations. OptiWindNet will fail if turbines are outside the border, so choose a buffer_dist that is greater than the maximum single step in position.

Parameters:

buffer_dist – Buffer distance to dilate borders / erode obstacles.

gradient(turbinesC=None, substationsC=None, gradient_type='length')[source]¶

Compute length/cost gradients with respect to node positions.

optimize(turbinesC=None, substationsC=None, router=None, verbose=False)[source]¶

Optimize electrical network.

solution_info()[source]¶

Get model and solver information of the latest solution (runtime, objective, gap, etc.).

class optiwindnet.api.EWRouter(maxiter: int = 10000, feeder_route: str = 'segmented', verbose: bool = False, **kwargs)[source]¶

Bases: Router

A lightweight, ultra-fast router for electrical network optimization.

  • Uses a modified Esau-Williams heuristic (segmented or straight feeders).

  • Produces solutions in milliseconds, suitable for quick solutions or warm starts.

Create a Esau-Williams-based router. :param maxiter: Maximum iterations. :param feeder_route: Feeder routing mode (“segmented” or “straight”). :param verbose: Enable verbose logging.

verbose = False[source]¶
maxiter = 10000[source]¶
feeder_route = 'segmented'[source]¶
route(P, A, cables, cables_capacity, verbose=False, **kwargs)[source]¶

Run the routing optimization.

Parameters:
  • P – Navigation mesh for the location.

  • A – Graph of available links.

  • cables – set of cable specifications as [(capacity, linear_cost), …].

  • cables_capacity – highest cable capacity in cables.

  • verbose – Whether to print progress/logging info.

  • **kwargs – Additional router-specific parameters.

Returns:

Solution topology (selected links). G : Optimized network graph with routes and cable types.

Return type:

S

class optiwindnet.api.HGSRouter(time_limit: float, feeder_limit: int | None = None, max_retries: int = 10, balanced: bool = False, seed: int | None = None, verbose: bool = False, **kwargs)[source]¶

Bases: Router

A fast router based on Hybrid Genetic Search (HGS-CVRP).

Uses the method and implementation by Vidal, 2022:

Vidal, T. (2022). Hybrid genetic search for the CVRP: Open-source implementation and SWAP* neighborhood. Computers & Operations Research, 140, 105643. https://doi.org/10.1016/j.cor.2021.105643

  • Balances solution quality and runtime.

  • Produces only radial solutions.

Create an HGS-based router.

Parameters:
  • time_limit – Maximum runtime for a single HGS run (in seconds).

  • feeder_limit – Maximum number of feeders allowed (ignored if multiple substations).

  • max_retries – Maximum number of retries if a feasible solution is not found.

  • balanced – Whether to balance turbines/loads across feeders.

  • seed – Set the seed of the pseudo-random number generator (reproducibility).

  • verbose – Enable verbose logging.

Notes

  • The total runtime may reach up to max_retries * time_limit in the worst case.

time_limit[source]¶
verbose = False[source]¶
max_retries = 10[source]¶
feeder_limit = None[source]¶
balanced = False[source]¶
seed = None[source]¶
route(P, A, cables, cables_capacity, verbose=False, **kwargs)[source]¶

Run the routing optimization.

Parameters:
  • P – Navigation mesh for the location.

  • A – Graph of available links.

  • cables – set of cable specifications as [(capacity, linear_cost), …].

  • cables_capacity – highest cable capacity in cables.

  • verbose – Whether to print progress/logging info.

  • **kwargs – Additional router-specific parameters.

Returns:

Solution topology (selected links). G : Optimized network graph with routes and cable types.

Return type:

S

class optiwindnet.api.MILPRouter(solver_name: str, time_limit: float, mip_gap: float, solver_options: dict | None = None, model_options: optiwindnet.MILP.ModelOptions | None = None, verbose: bool = False, **kwargs)[source]¶

Bases: Router

An exact router using mathematical programming.

  • Uses a Mixed-Integer Linear Programming (MILP) model of the problem.

  • Produces provably optimal or near-optimal networks (with quality metrics).

  • Requires a longer runtime than heuristics- and meta-heuristics-based routers.

Create a MILP-based router. :param solver_name: Name of solver (e.g., “gurobi”, “cbc”, “ortools”, “cplex”, “highs”, “scip”). :param time_limit: Maximum runtime (seconds). :param mip_gap: Relative MIP optimality gap tolerance. :param solver_options: Extra solver-specific options. :param model_options: Options for the MILP model. :param verbose: Enable verbose logging.

time_limit[source]¶
mip_gap[source]¶
solver_name[source]¶
solver_options[source]¶
model_options[source]¶
verbose = False[source]¶
solver[source]¶
route(P, A, cables, cables_capacity, verbose=False, S_warm=None, S_warm_has_detour=False, num_retries: int = 2, **kwargs)[source]¶

Run the routing optimization.

Parameters:
  • P – Navigation mesh for the location.

  • A – Graph of available links.

  • cables – set of cable specifications as [(capacity, linear_cost), …].

  • cables_capacity – highest cable capacity in cables.

  • verbose – Whether to print progress/logging info.

  • **kwargs – Additional router-specific parameters.

Returns:

Solution topology (selected links). G : Optimized network graph with routes and cable types.

Return type:

S