optiwindnet.interarraylib¶
Module Contents¶
- optiwindnet.interarraylib.assign_cables(G: networkx.Graph, cables: list[tuple[int, float | int]], currency: str = '€')[source]¶
Assign a cable type to each edge of
Gand update attribute'cost'.Each edge is assigned the cheapest cable type that can carry its load. The edge attribute
'cable'is the index incablesof the type chosen.Changes
Gin place.- Parameters:
G – networkx graph with edges having a
'load'attribute (usecalcload(G))cables – [(«capacity», «cost»), …] in increasing capacity order (each cable entry must be a tuple)
currency – symbol representing the unit of the cost
- optiwindnet.interarraylib.describe_G(G: networkx.Graph, significant_digits: int = 5) list[str][source]¶
Create a 3-4 line summary of G’s properties.
significant_digitsapplies only to total length and is enforced only when the integer part has fewer significant digits thansignificant_digits.- Parameters:
G – route set instance
significant_digits – minimum number of significant digits used for total length
- Returns:
- capacity and T, excess feeders and feeders per root, total length,
total cost.
- Return type:
Text lines
- optiwindnet.interarraylib.pathdist(G, path)[source]¶
Calculate the total length of a
pathof nodes inG.Uses the nodes’ coordinates (does not rely on edge attributes).
- optiwindnet.interarraylib.count_diagonals(S: networkx.Graph, A: networkx.Graph) int[source]¶
Count the number of Delaunay diagonals (extended edges) of
AinS.- Parameters:
S – solution topology
A – available edges used in creating
S
- Returns:
- number of non-gate edges of
Sthat are of kind'extended'or 'contour_extended'(kind is read fromA).
- number of non-gate edges of
- Raises:
ValueError – if an edge of unknown kind is found.
- optiwindnet.interarraylib.bfs_subtree_loads(G, parent, children, subtree)[source]¶
Recurse down the subtree, updating edge and node attributes.
Meant to be called by
calcload(), but can be used independently (e.g. from PathFinder). Nodes must not have a'load'attribute.- Returns:
Total number of descendant nodes
- optiwindnet.interarraylib.calcload(G)[source]¶
Calculate link loads and updates edge and node attributes of G.
Perform a breadth-first-traversal of each root’s subtree. As each node is visited, its subtree id and the load leaving it are stored as its attribute (keys
'subtree'and'load', respectively). Also the edges’'load'attributes are updated accordingly.
- optiwindnet.interarraylib.site_fingerprint(VertexC: numpy.ndarray, boundary: numpy.ndarray) tuple[bytes, dict[str, bytes]][source]¶
- optiwindnet.interarraylib.L_from_site(*, VertexC: numpy.ndarray, T: int, R: int, B: int = 0, border: numpy.ndarray | None = None, obstacles: list[numpy.ndarray] | None = None, name: str = '', handle: str = 'L_from_site', landscape_angle: float | None = None) networkx.Graph[source]¶
Create L from a location’s attributes.
- Parameters:
VertexC – numpy.ndarray (V, 2) with all (x, y) coordinates (V = R + T + B)
T – int number of wtg
R – int number of oss
B – number of border and obstacle zones’ vertices
border – array (B,) of VertexC indices that define the border (ccw)
obstacles – sequence of numpy.ndarray of VertexC indices
name – site name
handle – site identifier
- Returns:
Graph containing
N = R + Tnodes and no edges (all args become graph attributes).
- optiwindnet.interarraylib.G_from_S(S: networkx.Graph, A: networkx.Graph) networkx.Graph[source]¶
Create G from S and A.
Graph
Scontains the topology of a routeset network (nodes only, no contours or detours).Smust have been created from the available edges inA, whose contour information is used to obtain a routesetG(possibly with contours, but not with detours – use PathFinder afterward).
- optiwindnet.interarraylib.S_from_G(G: networkx.Graph) networkx.Graph[source]¶
Get
G’s topology (contours, detours, lengths, coords are dropped).- If using S to warm-start a MILP model, call after
S_from_G(): as_hooked_to_nearest(): if the model usestopology='branched'as_hooked_to_head(): if the model usestopology='radial'
This ensures that topology
Sis feasible (if radial) and not trivially suboptimal (if branched).- Parameters:
G – must contain a feasible solution (either tree or path)
- Returns:
Topology of
G
- If using S to warm-start a MILP model, call after
- optiwindnet.interarraylib.L_from_G(G: networkx.Graph) networkx.Graph[source]¶
Return new location with nodes and site attributes from G.
The returned location graph
Lretains only roots, nodes and basic graph attributes. All edges and remaining attributes are not carried fromG.- Parameters:
G – routeset graph to extract site data from.
- Returns:
Site graph (no edges) with lean attributes.
- optiwindnet.interarraylib.S_from_terse_links(terse_links, **kwargs)[source]¶
Create a solution topology graph
Sfrom itsterse_linksencoding.Inverse function of
terse_links_from_S().- Parameters:
terse_links – tree links encoded as 1D array (edges are: i→terse_links[i])
- Returns:
Solution topology S.
- optiwindnet.interarraylib.terse_links_from_S(S)[source]¶
Make a terse representation of the topology
Sas a 1D array.Inverse function of
S_from_terse_links().- Parameters:
S – solution topology (must be a tree)
- Returns:
1D array
terse, where(i, terse[i])are links ofS
- optiwindnet.interarraylib.as_obstacle_free(Lʹ: networkx.Graph) networkx.Graph[source]¶
Make a shallow copy of an instance and remove its obstacles.
The vertices that are used only by obstacles are also removed. To be used on locations (edge-less graphs).
- Parameters:
Lʹ – input location
- Returns:
location without obstacles.
- optiwindnet.interarraylib.as_single_root(Lʹ: networkx.Graph) networkx.Graph[source]¶
Make a shallow copy of an instance and reduce its roots to one.
The output’s root is the centroid of the input’s roots. This may not work well for locations with obstacles, use
as_obstacle_free()first.- Parameters:
Lʹ – input location
- Returns:
location with a single root.
- optiwindnet.interarraylib.as_normalized(Aʹ: networkx.Graph, *, offset: optiwindnet.geometric.CoordPair | None = None, scale: float | None = None) networkx.Graph[source]¶
Make a shallow copy of an instance and shift and scale its geometry.
Coordinates are subtracted by graph attribute
'norm_offset'. All lengths and coordinates are multiplied by graph attribute'norm_scale'. Graph attribute'is_normalized'is set toTrue. Affected linear attributes:'VertexC','d2roots'(graph);'length'(edge).- Parameters:
Aʹ – (or Gʹ) any instance that has inherited
'scale'from an edgesetAʹ.offset – coordinates (2,) offset to override graph’s
'norm_offset'scale – multiplicative scaling factor to override graph’s
'norm_scale'
- Returns:
A copy of the instance with changed coordinates and linear metrics.
- optiwindnet.interarraylib.as_rescaled(Gʹ: networkx.Graph, L: networkx.Graph) networkx.Graph[source]¶
Revert normalization done by
as_normalized().- Parameters:
Gʹ – routeset to rescale to pre-normalization size.
L – (or G or A) locations or routeset to get
'VertexC'from (also'd2roots', if available).
- Returns:
Routeset with coordinates and lengths at site scale.
- optiwindnet.interarraylib.as_undetoured(Gʹ: networkx.Graph) networkx.Graph[source]¶
Create an undetoured version of Gʹ.
Creates a shallow copy of
Gʹwithout detour nodes (and possibly with the resulting crossings). Changed links’'kind'become'tentative'.This is to be applied to a routeset that already has detours. It serves to re-run PathFinder on a detoured routeset, but it is not the best solution to prepare a routeset to be used as warmstart (re-hooking is missing).
- optiwindnet.interarraylib.as_hooked_to_nearest(Gʹ: networkx.Graph, d2roots: numpy.ndarray) networkx.Graph[source]¶
Make tentative feeders link to the nearest-to-root node of each subtree.
Output may be branched (use with care with path routesets).
Sifts through all
'tentative'gates’ subtrees and choose the hook closest to the respective root according tod2roots.Should be called after
as_undetoured()if the goal is to use G as a warmstart for MILP models.- Parameters:
G – routeset or topology S
d2roots – distance from nodes to roots (e.g.
A.graph['d2roots'])
- optiwindnet.interarraylib.as_hooked_to_head(Sʹ: networkx.Graph, d2roots: numpy.ndarray) networkx.Graph[source]¶
Make tentative feeders link to the nearest-to-root end of each string.
Only works with solutions where subtrees are paths (radial topology).
Sifts through the subtrees of
'tentative'feeders and re-hook the subtree via the end-node that is nearest to the respective root according tod2roots.Should be called after
as_undetoured()if the goal is to use S as a warmstart for MILP models.- Parameters:
S – solution topology
d2roots – distance from nodes to roots (e.g.
A.graph['d2roots'])
- optiwindnet.interarraylib.as_stratified_vertices(Lʹ: networkx.Graph) networkx.Graph[source]¶
Ensure border-vertices are all in the B-range of VertexC.
Apply this to L when terminal or root coordinates are to be updated by writting to the array elements of VertexC. In order to keep the borders in place, they must not rely on vertices in the terminal or root sections (T-range, R-range). This function creates duplicates of any terminal-vertex or root-vertex used by borders/obstacles.
- Parameters:
L – location geometry to be stratified
- Returns:
New location geometry with stratified vertices
- optiwindnet.interarraylib.make_remap(G, refG, H, refH)[source]¶
Create a mapping between two representations of the same site.
CAUTION: only WTG node remapping is implemented.
If the nodes in
Gand inHrepresent the same site, but have different orientation, scale and node order, the mapping produced here can be used withNetworkX.relabel_nodes(G, remap)to translate a routeset in G to a routeset in H.- Parameters:
G – routeset with obsolete representation.
refG – two nodes to used as references.
H – routeset with valid representation.
refH – two nodes corresponding to
refG
- optiwindnet.interarraylib.add_terminal_closest_root(A: networkx.Graph) None[source]¶
Add attributes
'root'to terminals and'rootmap__'toA.Changes A in-place.
node attribute
'root'is the index of the root closest to node.graph attribute
'rootmap__'is an R-long list of T-long bitarrays.
- Parameters:
A – available-links graph
- optiwindnet.interarraylib.add_link_blockmap(A: networkx.Graph)[source]¶
Add edge attributes
'blocked__'.Edges’ attribute
'blocked__'are R-long list of T-long bitarray maps.If an edge’s
blocked__[r][t] == 1, then this edge crosses the line-of-sight t-r.Changes
Ain place.Ashould have no feeder edges.Note
this function neglects borders and contours.
the space taken scales with
R × T × num_edges(A)
- optiwindnet.interarraylib.add_link_cosines(A: networkx.Graph)[source]¶
Add cosine of the angle wrt each root to all links of A as attribute
'cos_'.Changes A in-place. The cosine is of the acute angle between the link line and the line that contains the mid-point of the link and the root (for each root).
- optiwindnet.interarraylib.scaffolded(G: networkx.Graph, P: networkx.PlanarEmbedding) networkx.Graph[source]¶
Create a new graph merging G and P.
Useful for visualizing the funnels explored by
pathfinding.PathFinder.Gmust have been created usingP.- Parameters:
G – network graph for location
P – planar embedding of location
- Returns:
Merged graph (pass to
plotting.gplot()orsvg.svgplot()).