WindFarmNetwork/Router

This notebook is a practical guide to OptiWindNet’s Network/Router API (i.e. high-level API). It covers creating a wind farm model, using different routers (EWRouter, HGSRouter, MILPRouter), and applying key WindFarmNetwork functionalities. Specifically, we will:

  • Explore the WindFarmNetwork class

  • Compare available routers and their use cases

  • Run a complete optimization example

✅ WindFarmNetwork

The WindFarmNetwork class is the central user-facing component in the OptiWindNet Network/Router-API. It is flexible and extensible, supporting multiple input formats and routers (electrical network optimizers), and is used to model and optimize the electrical network of a wind farm.

To create a WindFarmNetwork instance:

Required:

  • Turbine and substation coordinates (see Data Input for formats)

  • Cable data (capacities and costs, or at least maximum capacity as a single number)

Optional:

  • Borders and obstacles: to add spatial constraints

  • Router: optimization strategy (defaults to EWRouter if not specified)

  • verbose: log/hide logging messages (default to Fault).

Key Responsibilities

Feature

Description

Initialization & Parsing

Accepts turbine/substation coordinates or the Location geometry L (Can be constructed from YAML, PBF, or WindIO formats for integration with real-world datasets), validates cable data, and constructs the internal graph structure.

Optimization

Interfaces smoothly with different routers (EWRouter, HGSRouter, MILPRouter) to optimize the network (cable routing) for cost and cable length.

Visualization

Provides plotting functions for location geometry, links, mesh, and the optimized network.

Gradient & Update Graph

Computes gradients for optimization and allows updating the electrical network using a compact “terse link” format.

Example Workflow

# Initialize with coordinates and cable types
wfn = WindFarmNetwork(
    cables=[(2, 1500.0), (5, 1800.0)],
    turbinesC=...,
    substationsC=...,
)

# Optimize electrical network using the default router (EWRouter)
wfn.optimize()

# Access total cost or cable length
total_cost = wfn.cost()
total_length = wfn.length()

# Visualize network
wfn.plot() # or simply wfn if you are running on notebooks

🧭 Router

In OptiWindNet, a Router is used to compute the optimal network (cable routing) of the wind farm’s electrical network. Given turbine and substation positions (layout), available cable options, and routing constraints, a router determines which turbines connect to which substations and how cables should be laid to minimize length (and consequently cost).

Currently Available Routers

The routers currently included in the optiwindnet.api module are:

  • EWRouter

    • Fastest option — completes in a fraction of a second

    • Great for quick network generation

    • Produces only branched-topology solutions

    • Heuristic method (EW = modified Esau-Williams) — solutions may be far from the optimum

  • HGSRouter

    • Still fast — can provide high-quality solutions in 0.5–2 seconds

    • Produces only radial-topology solutions (no branching)

    • A maximum number of feeders can be enforced

    • Meta-heuristic method (HGS = Hybrid Genetic Search)

  • MILPRouter

    • Delivers solutions with quality guarantees (a bound on the distance from the optimum)

    • May take a few to several minutes depending on the problem size and quality required

    • Full set of model options to choose from

    • Should be used when optimality is more important than speed

    • MILP = Mixed Integer Linear Programming

Run an example

In this section we will:

  • Create a simple wind farm network

  • Use heuristic and MILP optimization

  • Explore key methods such as:

    • .optimize()

    • .plot()

    • .cost(), .length()

    • .terse_links(), .update_from_terse_links()

    • .gradient()

    • .get_network()

    • .add_buffer()

Create a WindFarmNetwork instance

Import required modules

[1]:
import numpy as np
from optiwindnet.api import WindFarmNetwork, EWRouter, MILPRouter, ModelOptions
[2]:
# Display figures as SVG in Jupyter notebooks
%config InlineBackend.figure_formats = ['svg']

Load location data

OptiWindNet operates on location geometries, which define turbine and substation positions (plus optional borders/obstacles).

You can load a location from:

  • .yaml or .osm.pbf files;

  • The included locations repository;

  • Your own coordinate arrays.

For more details see Data Input.

We start with a simple geometry (5 turbines and 1 substation), and define a simple set of cables.

[3]:
wfn = WindFarmNetwork(
    cables=[(2, 1500.0), (5, 1800.0)],
    turbinesC=np.array([[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]),
    substationsC=np.array([[2, -2]]),
    borderC=np.array([[0, -3], [0, 2], [4, 2.1], [5, 1], [4, -3]]),
    obstacleC_=[np.array([[0.2, -2.5], [1.5, -2.5], [0.2, -1]])]
)
Plot location

Note: Many of the Jupyter notebooks provided include SVG figures as output. To ensure these visuals are displayed correctly in JupyterLab or Jupyter Notebook, make sure the notebook is marked as trusted. In JupyterLab, you can do this by pressing Ctrl + Shift + C and selecting Trust Notebook.

[4]:
wfn
[4]:
../_images/notebooks_a02_WindFarmNetwork_23_0.svg

Method: optimize(router=...)

This is the main method that optimizes the electrical network using the given router (heuristic, metaheuristic or MILP). > Note that the router could be passed directly to WindFarmNetwork(router=...).

Use a heuristic router (Esau-Williams)

[5]:
wfn.optimize(router=EWRouter())
[5]:
array([ 1,  2, -1,  2,  3])

Plot the result

[6]:
wfn
[6]:
../_images/notebooks_a02_WindFarmNetwork_29_0.svg

Use a MILP router with full control over topology and feeders

The solution from the previous call to wfn.optimize() is stored within the wfn object. If this solution is feasible under the current ``MILPRouter`` settings, it will be automatically used as a warm start. Otherwise, if it does not meet the current ModelOptions constraints, it will be ignored, and the MILP solver will start from scratch.

[7]:
model_opts = ModelOptions(
    topology='radial',
    feeder_limit='minimum',
    feeder_route='straight',
)
wfn.optimize(
    router=MILPRouter(
        solver_name='ortools',
        time_limit=2,
        mip_gap=0.01,
        model_options=model_opts
    ),
    verbose=True,
)
wfn

Warning: No warmstarting (even though a solution is available) due to the following reason(s):
    - branched network incompatible with model option: topology="radial"


Starting CP-SAT solver v9.15.6755
Parameters: max_time_in_seconds: 2 log_search_progress: true relative_gap_limit: 0.01
Setting number of workers to 8

Initial optimization model '': (model_fingerprint: 0xa76b63835d29c974)
#Variables: 46 (#bools: 23 in floating point objective) (35 primary variables)
  - 23 Booleans in [0,1]
  - 18 in [0,4]
  - 5 in [0,5]
#kAtMostOne: 16 (#literals: 42)
#kLinear1: 46 (#enforced: 46)
#kLinear3: 4
#kLinearN: 19 (#terms: 121)

Starting presolve at 0.00s
The solution hint is complete, but it is infeasible! we will try to repair it.
[Scaling] Floating point objective has 23 terms with magnitude in [1.41421, 3.16228] average = 2.17149
[Scaling] Objective coefficient relative error: 1.0787e-06
[Scaling] Objective worst-case absolute error: 1.83062e-05
[Scaling] Objective scaling factor: 65536
  2.13e-05s  0.00e+00d  [DetectDominanceRelations]
  3.20e-04s  0.00e+00d  [PresolveToFixPoint] #num_loops=2 #num_dual_strengthening=1
  5.88e-06s  0.00e+00d  [ExtractEncodingFromLinear] #potential_supersets=27
  7.63e-06s  0.00e+00d  [DetectDuplicateColumns]
  1.78e-05s  0.00e+00d  [DetectDuplicateConstraints]
[Symmetry] Graph for symmetry has 182 nodes and 327 arcs.
[Symmetry] Symmetry computation done. time: 6.0809e-05 dtime: 5.225e-05
  2.16e-05s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  3.48e-04s  5.13e-05d  [Probe] #probed=44 #fixed_bools=2 #new_bounds=9 #new_binary_clauses=4
  2.74e-05s  1.12e-05d  [MaxClique] Merged 21 constraints with 60 literals into 15 constraints with 48 literals
  1.84e-05s  0.00e+00d  [DetectDominanceRelations]
  1.99e-04s  0.00e+00d  [PresolveToFixPoint] #num_loops=2 #num_dual_strengthening=1
  2.09e-05s  0.00e+00d  [ProcessAtMostOneAndLinear]
  1.52e-05s  0.00e+00d  [DetectDuplicateConstraints] #duplicates=1
  1.10e-05s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  1.76e-05s  3.24e-07d  [DetectDominatedLinearConstraints] #relevant_constraints=11 #num_inclusions=5
  2.10e-06s  0.00e+00d  [DetectDifferentVariables]
  4.14e-05s  7.53e-07d  [ProcessSetPPC] #relevant_constraints=22 #num_inclusions=18
  1.63e-05s  0.00e+00d  [TransformClausesToExactlyOne] #num_amos=13
  2.80e-05s  0.00e+00d  [DetectEncodedComplexDomains]
  3.47e-06s  0.00e+00d  [FindAlmostIdenticalLinearConstraints]
  9.37e-06s  3.35e-06d  [FindBigAtMostOneAndLinearOverlap]
  5.00e-06s  2.89e-06d  [FindBigVerticalLinearOverlap]
  1.97e-06s  1.95e-07d  [FindBigHorizontalLinearOverlap] #linears=5
  1.14e-06s  0.00e+00d  [MergeClauses]
  1.58e-05s  0.00e+00d  [DetectDominanceRelations]
  1.11e-04s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  1.25e-05s  0.00e+00d  [DetectDominanceRelations]
  9.46e-05s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  4.43e-06s  0.00e+00d  [DetectDuplicateColumns]
  1.10e-05s  0.00e+00d  [DetectDuplicateConstraints]
[Symmetry] Graph for symmetry has 149 nodes and 236 arcs.
[Symmetry] Symmetry computation done. time: 5.7309e-05 dtime: 6.347e-05
[Symmetry] #generators: 1, average support size: 38
[Symmetry] 19 orbits on 38 variables with sizes: 2,2,2,2,2,2,2,2,2,2,...
[Symmetry] Num fixable by intersecting at_most_one with orbits: 2 largest_orbit: 2
[SAT presolve] num removable Booleans: 0 / 21
[SAT presolve] num trivial clauses: 0
[SAT presolve] [0s] clauses:4 literals:8 vars:8 one_side_vars:8 simple_definition:0 singleton_clauses:0
[SAT presolve] [4.015e-06s] clauses:4 literals:8 vars:8 one_side_vars:8 simple_definition:0 singleton_clauses:0
[SAT presolve] [6.239e-06s] clauses:4 literals:8 vars:8 one_side_vars:8 simple_definition:0 singleton_clauses:0
  1.67e-05s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  2.55e-04s  3.60e-05d  [Probe] #probed=37 #fixed_bools=1 #new_bounds=6 #new_binary_clauses=13
  2.90e-05s  6.31e-06d  [MaxClique]
  1.69e-05s  0.00e+00d  [DetectDominanceRelations]
  1.37e-04s  0.00e+00d  [PresolveToFixPoint] #num_loops=2 #num_dual_strengthening=1
  1.57e-05s  0.00e+00d  [ProcessAtMostOneAndLinear]
  9.86e-06s  0.00e+00d  [DetectDuplicateConstraints]
  7.27e-06s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  1.40e-05s  2.17e-07d  [DetectDominatedLinearConstraints] #relevant_constraints=10 #num_inclusions=5
  1.83e-06s  0.00e+00d  [DetectDifferentVariables]
  9.18e-06s  1.85e-07d  [ProcessSetPPC] #relevant_constraints=18
  1.45e-05s  0.00e+00d  [TransformClausesToExactlyOne] #num_amos=12
  1.46e-05s  0.00e+00d  [DetectEncodedComplexDomains]
  2.25e-06s  0.00e+00d  [FindAlmostIdenticalLinearConstraints]
  7.59e-06s  2.96e-06d  [FindBigAtMostOneAndLinearOverlap]
  4.51e-06s  2.16e-06d  [FindBigVerticalLinearOverlap]
  1.81e-06s  1.65e-07d  [FindBigHorizontalLinearOverlap] #linears=5
  8.50e-07s  0.00e+00d  [MergeClauses]
  1.51e-05s  0.00e+00d  [DetectDominanceRelations]
  9.19e-05s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  1.22e-05s  0.00e+00d  [DetectDominanceRelations]
  8.04e-05s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  4.08e-06s  0.00e+00d  [DetectDuplicateColumns]
  8.02e-06s  0.00e+00d  [DetectDuplicateConstraints]
[Symmetry] Graph for symmetry has 130 nodes and 189 arcs.
[Symmetry] Symmetry computation done. time: 2.2043e-05 dtime: 2.168e-05
[SAT presolve] num removable Booleans: 0 / 18
[SAT presolve] num trivial clauses: 0
[SAT presolve] [0s] clauses:6 literals:12 vars:9 one_side_vars:9 simple_definition:0 singleton_clauses:0
[SAT presolve] [3.366e-06s] clauses:6 literals:12 vars:9 one_side_vars:9 simple_definition:0 singleton_clauses:0
[SAT presolve] [5.306e-06s] clauses:6 literals:12 vars:9 one_side_vars:9 simple_definition:0 singleton_clauses:0
  1.44e-05s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  2.08e-04s  3.16e-05d  [Probe] #probed=36 #new_binary_clauses=14
  3.15e-05s  7.83e-06d  [MaxClique] Merged 12 constraints with 32 literals into 11 constraints with 30 literals
  1.69e-05s  0.00e+00d  [DetectDominanceRelations]
  1.04e-04s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  1.57e-05s  0.00e+00d  [ProcessAtMostOneAndLinear]
  9.47e-06s  0.00e+00d  [DetectDuplicateConstraints]
  7.04e-06s  0.00e+00d  [DetectDuplicateConstraintsWithDifferentEnforcements]
  1.38e-05s  2.17e-07d  [DetectDominatedLinearConstraints] #relevant_constraints=10 #num_inclusions=5
  1.75e-06s  0.00e+00d  [DetectDifferentVariables]
  8.97e-06s  1.76e-07d  [ProcessSetPPC] #relevant_constraints=17
  1.33e-05s  0.00e+00d  [TransformClausesToExactlyOne] #num_amos=11
  1.43e-05s  0.00e+00d  [DetectEncodedComplexDomains]
  2.25e-06s  0.00e+00d  [FindAlmostIdenticalLinearConstraints]
  7.19e-06s  2.93e-06d  [FindBigAtMostOneAndLinearOverlap]
  4.40e-06s  2.15e-06d  [FindBigVerticalLinearOverlap]
  1.79e-06s  1.65e-07d  [FindBigHorizontalLinearOverlap] #linears=5
  7.84e-07s  0.00e+00d  [MergeClauses]
  1.52e-05s  0.00e+00d  [DetectDominanceRelations]
  9.29e-05s  0.00e+00d  [PresolveToFixPoint] #num_loops=1 #num_dual_strengthening=1
  6.83e-07s  0.00e+00d  [MergeNoOverlap]
  4.72e-07s  0.00e+00d  [MergeNoOverlap2D]
  1.31e-05s  0.00e+00d  [ExpandObjective] #entries=54 #tight_variables=21 #tight_constraints=6

Presolve summary:
  - 5 affine relations were detected.
  - rule 'TODO linear inclusion: superset is equality' was applied 15 times.
  - rule 'affine: new relation' was applied 5 times.
  - rule 'at_most_one: removed literals' was applied 10 times.
  - rule 'at_most_one: transformed into max clique' was applied 2 times.
  - rule 'deductions: 46 stored' was applied 1 time.
  - rule 'duplicate: removed constraint' was applied 1 time.
  - rule 'enforcement: false literal' was applied 5 times.
  - rule 'enforcement: true literal' was applied 5 times.
  - rule 'exactly_one: removed literals' was applied 5 times.
  - rule 'exactly_one: simplified objective' was applied 6 times.
  - rule 'linear: divide by GCD' was applied 1 time.
  - rule 'linear: empty' was applied 15 times.
  - rule 'linear: enforcement literal in expression' was applied 10 times.
  - rule 'linear: fixed or dup variables' was applied 26 times.
  - rule 'linear: positive at most one' was applied 5 times.
  - rule 'linear: positive equal one' was applied 7 times.
  - rule 'linear: remapped using affine relations' was applied 19 times.
  - rule 'linear: simplified rhs' was applied 8 times.
  - rule 'objective: shifted cost with exactly ones' was applied 1 time.
  - rule 'presolve: 10 unused variables removed.' was applied 1 time.
  - rule 'presolve: iteration' was applied 3 times.
  - rule 'setppc: exactly_one included in linear' was applied 5 times.
  - rule 'setppc: reduced linear coefficients' was applied 4 times.
  - rule 'setppc: removed dominated constraints' was applied 2 times.
  - rule 'setppc: removed trivial linear constraint' was applied 1 time.
  - rule 'symmetry: fixed to false in general orbit' was applied 2 times.
  - rule 'variables: both boolean and its negation fix the same variable' was applied 5 times.
  - rule 'variables: detect fully reified value encoding' was applied 23 times.
  - rule 'variables: detect half reified value encoding' was applied 51 times.

Presolved optimization model '': (model_fingerprint: 0x81549902c3cf4bbe)
#Variables: 31 (#bools: 9 in objective) (21 primary variables)
  - 18 Booleans in [0,1]
  - 2 in [0][2,4]
  - 1 in [0,3]
  - 10 in [0,4]
#kAtMostOne: 5 (#literals: 18)
#kBoolAnd: 5 (#enforced: 5) (#literals: 11)
#kExactlyOne: 6 (#literals: 21)
#kLinear1: 26 (#enforced: 26)
#kLinear2: 2
#kLinear3: 1
#kLinearN: 7 (#terms: 41)
[Symmetry] Graph for symmetry has 114 nodes and 187 arcs.
[Symmetry] Symmetry computation done. time: 2.2486e-05 dtime: 2.144e-05

Preloading model.
#Bound   0.00s best:inf   next:[7.65686035,16.6584015] initial_domain
The solution hint is complete, but it is infeasible! we will try to repair it.
#Model   0.00s var:31/31 constraints:52/52

Starting search at 0.00s with 8 workers.
6 full problem subsolvers: [core, default_lp, max_lp, no_lp, quick_restart, reduced_costs]
2 first solution subsolvers: [fj, fs_random_no_lp]
9 interleaved subsolvers: [feasibility_pump, graph_arc_lns, graph_cst_lns, graph_dec_lns, graph_var_lns, ls, rins/rens, rnd_cst_lns, rnd_var_lns]
3 helper subsolvers: [neighborhood_helper, synchronization_agent, update_gap_integral]

#1       0.01s best:8.48529053 next:[7.65686035,8.48527527] no_lp [hint] (fixed_bools=0/18)
#Done    0.01s no_lp
#Done    0.01s default_lp [hint]

Task timing                   n [     min,      max]      avg      dev     time         n [     min,      max]      avg      dev    dtime
              'core':         1 [942.00us, 942.00us] 942.00us   0.00ns 942.00us         2 [ 16.92us,  37.12us]  27.02us  10.10us  54.04us
        'default_lp':         1 [  1.03ms,   1.03ms]   1.03ms   0.00ns   1.03ms         1 [ 39.61us,  39.61us]  39.61us   0.00ns  39.61us
  'feasibility_pump':         1 [232.36us, 232.36us] 232.36us   0.00ns 232.36us         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
                'fj':         1 [247.97us, 247.97us] 247.97us   0.00ns 247.97us         1 [ 61.25us,  61.25us]  61.25us   0.00ns  61.25us
   'fs_random_no_lp':         1 [523.01us, 523.01us] 523.01us   0.00ns 523.01us         1 [ 37.13us,  37.13us]  37.13us   0.00ns  37.13us
     'graph_arc_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
     'graph_cst_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
     'graph_dec_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
     'graph_var_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
                'ls':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
            'max_lp':         1 [962.53us, 962.53us] 962.53us   0.00ns 962.53us         1 [ 37.14us,  37.14us]  37.14us   0.00ns  37.14us
             'no_lp':         1 [884.99us, 884.99us] 884.99us   0.00ns 884.99us         2 [  6.16us,  40.71us]  23.43us  17.27us  46.87us
     'quick_restart':         1 [917.25us, 917.25us] 917.25us   0.00ns 917.25us         1 [ 39.14us,  39.14us]  39.14us   0.00ns  39.14us
     'reduced_costs':         1 [834.75us, 834.75us] 834.75us   0.00ns 834.75us         1 [ 39.86us,  39.86us]  39.86us   0.00ns  39.86us
         'rins/rens':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
       'rnd_cst_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns
       'rnd_var_lns':         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns         0 [  0.00ns,   0.00ns]   0.00ns   0.00ns   0.00ns

Search stats          Bools  Conflicts  Branches  Restarts  BacktrackToRoot  Backtrack  BoolPropag  IntegerPropag
             'core':     18          0        44         0               42         42         223            433
       'default_lp':     18          1        37         0               37         37         175            332
  'fs_random_no_lp':     18          0        36         0               36         36         149            288
           'max_lp':     18          0        36         0               36         36         149            349
            'no_lp':     18          2        43         0               39         39         204            394
    'quick_restart':     18          0        36         0               36         36         149            288
    'reduced_costs':     18          0        36         0               36         36         149            349

SAT formula           Fixed  Equiv  Total  VarLeft  BinaryClauses  PermanentClauses  TemporaryClauses
             'core':     10      7     18        1             28                 0                 0
       'default_lp':     18      0     18        0             54                 5                 0
  'fs_random_no_lp':      0      0     18       18             48                 6                 0
           'max_lp':      0      0     18       18             48                 6                 0
            'no_lp':     18      5     18       -5             26                -5                 0
    'quick_restart':      0      0     18       18             48                 6                 0
    'reduced_costs':      0      0     18       18             48                 6                 0

SAT stats             ClassicMinim  LitRemoved  LitRemovedBinary  LitLearned  LitForgotten  Subsumed
             'core':             0           0                 0           0             0         0
       'default_lp':             0           0                 0           1             0         1
  'fs_random_no_lp':             0           0                 0           0             0         0
           'max_lp':             0           0                 0           0             0         0
            'no_lp':             0           0                 0           1             0         0
    'quick_restart':             0           0                 0           0             0         0
    'reduced_costs':             0           0                 0           0             0         0

Vivification          Clauses  Decisions  LitTrue  Subsumed  LitRemoved  DecisionReused  Conflicts
             'core':        0          0        0         0           0               0          0
       'default_lp':        0          0        0         0           0               0          0
  'fs_random_no_lp':        0          0        0         0           0               0          0
           'max_lp':        0          0        0         0           0               0          0
            'no_lp':        0          0        0         0           0               0          0
    'quick_restart':        0          0        0         0           0               0          0
    'reduced_costs':        0          0        0         0           0               0          0

Clause deletion       at_true  l_and_not(l)  to_binary  sub_conflict  sub_extra  sub_decisions  sub_eager  sub_vivify  sub_probing  sub_inpro  blocked  eliminated  forgotten  promoted  conflicts
             'core':        0             5          1             0          0              0          0           0            0          0        0           0          0         0          0
       'default_lp':        0             0          0             0          0              0          1           0            0          0        0           0          0         0          1
  'fs_random_no_lp':        0             0          0             0          0              0          0           0            0          0        0           0          0         0          0
           'max_lp':        0             0          0             0          0              0          0           0            0          0        0           0          0         0          0
            'no_lp':        1             1          3             0          0              1          0           0            0          0        0           0          0         0          2
    'quick_restart':        0             0          0             0          0              0          0           0            0          0        0           0          0         0          0
    'reduced_costs':        0             0          0             0          0              0          0           0            0          0        0           0          0         0          0

Lp stats            Component  Iterations  AddedCuts  OPTIMAL  DUAL_F.  DUAL_U.
     'default_lp':          1           4          0        2        0        0
         'max_lp':          1           0          0        0        0        0
  'quick_restart':          1           4          0        2        0        0
  'reduced_costs':          1           8          0        2        0        0

Lp dimension        Final dimension of first component
     'default_lp':      5 rows, 25 columns, 33 entries
         'max_lp':    66 rows, 31 columns, 186 entries
  'quick_restart':      5 rows, 25 columns, 33 entries
  'reduced_costs':      9 rows, 31 columns, 48 entries

Lp debug            CutPropag  CutEqPropag  Adjust  Overflow  Bad  BadScaling
     'default_lp':          0            0       0         0    0           0
         'max_lp':          0            0       0         0    0           0
  'quick_restart':          0            0       0         0    0           0
  'reduced_costs':          0            0       0         0    0           0

Lp pool             Constraints  Updates  Simplif  Merged  Shortened  Split  Strengthened  Cuts/Call
     'default_lp':           42        0        0       0          0      0             0        0/0
         'max_lp':           66        0        0       0          0      0             0        0/0
  'quick_restart':           42        0        0       0          0      0             0        0/0
  'reduced_costs':           66        0        0       0          0      0             0        0/0

LNS stats           Improv/Calls  Closed  Difficulty  TimeLimit
  'graph_arc_lns':           0/0      0%    5.00e-01       0.10
  'graph_cst_lns':           0/0      0%    5.00e-01       0.10
  'graph_dec_lns':           0/0      0%    5.00e-01       0.10
  'graph_var_lns':           0/0      0%    5.00e-01       0.10
      'rins/rens':           0/0      0%    5.00e-01       0.10
    'rnd_cst_lns':           0/0      0%    5.00e-01       0.10
    'rnd_var_lns':           0/0      0%    5.00e-01       0.10

LS stats         Batches  Restarts/Perturbs  LinMoves  GenMoves  CompoundMoves  Bactracks  WeightUpdates  ScoreComputed
  'fj_restart':        1                  1        42         0              0          0             34            285

Solutions (1)    Num   Rank
       'no_lp':    2  [0,1]

Objective bounds     Num
  'initial_domain':    1

Solution repositories    Added  Queried  Synchro
    'alternative_path':      1        0        1
      'best_solutions':      4        0        4
   'fj solution hints':      0        0        0
        'lp solutions':      0        0        0
                'pump':      0        0

Improving bounds shared    Num  Sym
                 'no_lp':   15    0

Clauses shared        #Exported  #Imported  #BinaryRead  #BinaryTotal
             'core':          1          0            4             4
       'default_lp':          0          0            3             4
  'fs_random_no_lp':          0          0            0             4
           'max_lp':          0          0            0             4
            'no_lp':          3          0            3             4
    'quick_restart':          0          0            0             4
    'reduced_costs':          0          0            0             4

LRAT_status: NA
[Scaling] scaled_objective_bound: 8.48529 corrected_bound: 8.48529 delta: 1.08703e-06
CpSolverResponse summary:
status: OPTIMAL
objective: 8.485281374238571
best_bound: 8.485281374238571
integers: 26
booleans: 18
conflicts: 0
branches: 36
propagations: 149
integer_propagations: 288
restarts: 0
lp_iterations: 0
walltime: 0.0103299
usertime: 0.0103299
deterministic_time: 0.000518134
gap_integral: 0.00051369
solution_fingerprint: 0x32d6c99bc4018a9b

[7]:
../_images/notebooks_a02_WindFarmNetwork_31_1.svg

Method: plot() and Variants

These methods help you visualize different stages of the optimization:

  • plot_location(): plot turbine/substation coordinates and borders

  • plot(): plot optimized electrical network

For more details, see the Plotting tutorial.

[8]:
wfn.plot_location()
wfn.plot() # wfn will do the same on notebooks (and if no G is available it will display L)
[8]:
<Axes: >
../_images/notebooks_a02_WindFarmNetwork_34_1.svg
../_images/notebooks_a02_WindFarmNetwork_34_2.svg

Method: cost() and length()

Returns the total cost and cable length of the optimized network.

[9]:
print("Network cost:", wfn.cost())
print("Network length:", wfn.length())
Network cost: 14424.97833620557
Network length: 8.485281374238571

Method: terse_links()

A terse link is a compact way to describe how each turbine is connected in the electrical network. It’s just a list (or array) where:

  • Each position i represents turbine i

  • The value at position i is the node that turbine i connects to (this could be another turbine or a substation)

[10]:
terse = wfn.terse_links()
print("Terse link array:", terse)
Terse link array: [ 1  2  3  4 -1]

Method: update_from_terse_links()

update_from_terse_links() allows you to reconstruct the network from a known terse_link, optionally updating coordinates. This method assumes a valid and feasible network, so it’s your responsibility to ensure that:

  • The connections form a proper feeder tree

  • Every turbine is (indirectly or directly) connected to a substation

  • Capacity constraints are not violated

Suppose we have a wind farm with:

  • 5 turbines → nodes 0, 1, 2, 3, 4

  • 1 substation → node -1 (Note: In OptiWindNet, substations are assigned negative indices)

We want the following connections:

  • Turbine 0 → Substation (-1)

  • Turbine 1 → Turbine 0

  • Turbine 2 → Substation (-1)

  • Turbine 3 → Turbine 2

  • Turbine 4 → Turbine 3

This gives us the terse_links array:

```python terse_links = [-1, 0, -1, 2, 3]

[11]:
new_terse_links = np.array([-1, 0, -1, 2, 3])

# Apply the new configuration
wfn.update_from_terse_links(new_terse_links)

# Visualize the updated network (cable routing)
wfn

[11]:
../_images/notebooks_a02_WindFarmNetwork_43_0.svg

Method: gradient()

This method computes the gradient of the cost or length with respect to turbine/substation positions. Useful for hybrid optimization or sensitivity analysis. > Note: default of gradient_type is length.

[12]:
print('--- gradient_type=length ---\n')
grad_turb, grad_subs = wfn.gradient()
print("Gradient (w.r.t. turbines):\n", grad_turb, "\n")
print("Gradient (w.r.t. substations):\n", grad_subs)
print('\n')
print('--- gradient_type=length ---\n')
grad_turb, grad_subs = wfn.gradient(gradient_type='cost')
print("Gradient (w.r.t. turbines):\n", grad_turb, "\n")
print("Gradient (w.r.t. substations):\n", grad_subs)
--- gradient_type=length ---

Gradient (w.r.t. turbines):
 [[-1.41421356  0.        ]
 [ 0.70710678  0.70710678]
 [-0.70710678  0.29289322]
 [ 0.          1.41421356]
 [ 0.70710678 -0.70710678]]

Gradient (w.r.t. substations):
 [[ 0.70710678 -1.70710678]]


--- gradient_type=length ---

Gradient (w.r.t. turbines):
 [[-2121.32034356     0.        ]
 [ 1060.66017178  1060.66017178]
 [-1060.66017178   739.33982822]
 [    0.          2121.32034356]
 [ 1060.66017178 -1060.66017178]]

Gradient (w.r.t. substations):
 [[ 1060.66017178 -2860.66017178]]

Method: get_network()

This method returns the final optimized network as a structured NumPy array, where each row represents an edge in the network.

Each edge includes detailed attributes such as:

  • ``src``: index of the source node

  • ``tgt``: index of the target (destination node)

  • ``length``: physical cable length

  • ``load``: electrical load carried through the cable (number of turbines)

  • ``cable``: index of the cable type used (e.g., 0 for first type in cable list)

  • ``cost``: cost associated with the used cable (if cost is provided by the user)

[13]:
network_data = wfn.get_network()
network_data[:2]  # preview only first few edges
[13]:
array([(1,  0, 1.41421356, 1., 0), (0, -1, 2.82842712, 2., 0)],
      dtype=[('src', '<i8'), ('tgt', '<i8'), ('length', '<f8'), ('load', '<f8'), ('cable', '<i8')])

Method: add_buffer()

This method redefines the border and obstacles by expanding the borders and shrinking the obstacles; useful when turbines are near edges or when integrating with tools like TopFarm|

[14]:
wfn.add_buffer(buffer_dist=0.5)
Buffering by 0.50 completely removed the obstacle at index 0. For visual comparison use plot_original_vs_buffered().
[15]:
wfn.plot_original_vs_buffered()
[15]:
<Axes: title={'center': 'Original and Buffered Shapes'}>
../_images/notebooks_a02_WindFarmNetwork_53_1.svg
[16]:
wfn.optimize()
wfn
[16]:
../_images/notebooks_a02_WindFarmNetwork_54_0.svg

In this section:

we explored the most useful methods of the WindFarmNetwork class:

Method

Purpose

optimize()

Run optimization with a router

plot()

Visualize the network

cost(), length()

Get total cost and length

terse_links()

Get compact link encoding

update_from_terse_links()

Apply terse links manually

gradient()

Compute network’s gradient

get_network()

Export the optimized network data

add_buffer()

Expand border - Shrink obstacles

For deeper insights into individual methods, refer to the dedicated notebooks provided.