optiwindnet.db¶

Submodules¶

Package Contents¶

class optiwindnet.db.Machine(*args, **kwargs)[source]¶

Bases: BaseModel

id¶

Primary key.

name¶

Unique hostname/FQDN of the generating machine.

attrs¶

System attributes and specifications dictionary.

class optiwindnet.db.Method(*args, **kwargs)[source]¶

Bases: BaseModel

digest¶

SHA256 hash of funhash and JSON-serialized options.

solver_name¶

Name of the solver/algorithm family.

funname¶

Name of the optimization function.

options¶

Dictionary of function parameters.

timestamp¶

UTC timestamp of creation.

funfile¶

Source filename containing the optimization function.

funhash¶

SHA256 hash of the function bytecode.

class optiwindnet.db.NodeSet(*args, **kwargs)[source]¶

Bases: BaseModel

digest¶

SHA256 hash of VertexC coordinates array in .npy format.

name¶

Unique name of the wind farm location.

T¶

Number of non-root nodes (wind turbines).

R¶

Number of root nodes (substations).

B¶

Number of border-only vertices.

VertexC¶

2D coordinates array in UTM, shape (T + B + R, 2).

constraint_groups¶

Sizes of each polygon group (first boundary CCW, then obstacles CW).

constraint_vertices¶

Concatenated indices into VertexC for constraint polygons.

landscape_angle¶

Rotation angle of the landscape layout in radians.

class optiwindnet.db.RouteSet(*args, **kwargs)[source]¶

Bases: BaseModel

id¶

Primary key.

handle¶

Standardized wind farm location identifier.

T¶

Number of non-root nodes (turbines).

R¶

Number of root nodes (substations).

capacity¶

Cable capacity (maximum turbine load).

length¶

Total cable network length.

runtime¶

Optimization runtime in seconds.

feeders_per_root¶

List specifying number of feeders per root substation.

C¶

Number of contour nodes.

D¶

Number of detour nodes.

creator¶

Short identifier of the routeset origin.

detextra¶

length = (1+detextra)*undetoured.

Type:

Relative length increase due to detour

num_diagonals¶

Number of diagonal crossing structures.

tentative¶

List of vertex pairs representing tentative edges.

rogue¶

List of vertex pairs representing rogue/invalid edges.

timestamp¶

UTC timestamp of creation.

misc¶

Dictionary of extra metadata and solver metrics.

clone2prime¶

List of length C + D mapping cloned nodes back to original nodes.

edges¶

Terse tree encoding where edges[i] is the target of node i.

nodes¶

Foreign key link to the layout NodeSet.

method¶

Foreign key link to the Method used.

machine¶

Foreign key link to the generating Machine.

optiwindnet.db.database_connection(filepath: str, create_db: bool = False, timeout: int = _DEFAULT_SQLITE_TIMEOUT)[source]¶

Open the sqlite database for the duration of a context block.

Parameters:
  • filepath – path to database file

  • create_db – True → create a new file if it does not exist

  • timeout – seconds to wait for a locked database to be released

Yields:

Connected SqliteDatabase object (Peewee)

optiwindnet.db.open_database(filepath: str, create_db: bool = False, timeout: int = _DEFAULT_SQLITE_TIMEOUT) peewee.SqliteDatabase[source]¶

Opens the sqlite database v3 file specified in filepath.

Parameters:
  • filepath – path to database file

  • create_db – True → create a new file if it does not exist

  • timeout – seconds to wait for a locked database to be released

Returns:

SqliteDatabase object (Peewee)

optiwindnet.db.G_by_method(G: networkx.Graph, method: optiwindnet.db.model.Method) networkx.Graph[source]¶

Fetch from the database a layout for G by method.

G must be a layout solution with the necessary info in the G.graph dict. method is a Method.

optiwindnet.db.G_from_routeset(routeset: optiwindnet.db.model.RouteSet) networkx.Graph[source]¶

Translate a RouteSet database entry to a routeset graph.

Parameters:

routeset – an entry from the database RouteSet table.

Returns:

Graph G containing the routeset.

optiwindnet.db.Gs_from_attrs(farm: object, methods: optiwindnet.db.model.Method | collections.abc.Sequence[object], capacities: int | collections.abc.Sequence[int]) list[tuple[networkx.Graph]][source]¶

Fetch from the database a list (one per capacity) of tuples (one per method) of layouts.

farm must have the desired NodeSet name in the name attribute. methods is a (sequence of) Method instance(s). capacities is a (sequence of) int(s).

optiwindnet.db.L_from_nodeset(nodeset: optiwindnet.db.model.NodeSet, handle: str | None = None) networkx.Graph[source]¶

Translate a NodeSet database entry to a location graph.

Parameters:

nodeset – an entry from the database NodeSet table.

Returns:

Graph L containing the positions and location metadata.

optiwindnet.db.store_G(G: networkx.Graph) int[source]¶

Store G’s data to a new RouteSet record in the database.

If the NodeSet or Method are not yet in the database, they will be added.

Parameters:

G – Graph with the routeset.

Returns:

Primary key of the newly created RouteSet record.