HGSRouter example¶

This notebook uses OptiWindNet to route the collector system cables via HGSRouter.

🧬 HGS (Hybrid Genetic Search)¶

HGSRouter is a metaheuristic based router that applies Hybrid Genetic Search (HGS) to optimize electrical network of a defined turbine-layout as a Capacitated Vehicle Routing Problem (CVRP). It can handle both single and multiple substations and is well-suited for fast and high-quality networks.

This router is slower than EWRouter but typically yields better-quality solutions, especially for medium and large windfarms with one substation.

🔧 Constructor: HGSRouter(...)¶

Required arguments:

Argument

Type

Description

time_limit

int

Time limit (in seconds) which controls how long the genetic algorithm can search for better solutions.

Optional arguments:

Argument

Type

Description

feeder_limit

int or None

Maximum number of feeders.

max_retries

int

Maximum number of retries if a feasible solution is not found (default: 10). Total runtime may reach up to (max_retries + 1) * time_limit in the worst case.

balanced

bool

If True, balances the number of turbines per feeder.

seed

int

Set random seed (default: None, meaning new seed).

verbose

bool

If True, prints routing details and warnings.

✅ Example

wf = WindFarmNetwork(...)
wf.optimize(
    router=HGSRouter(
        time_limit=60,
        feeder_limit=10,
        balanced=True,
    )
)
  • HGSRouter trades speed for higher-quality networks and is particularly useful when:

    • A better solution is worth longer runtime (compared to EWRouter)

    • The number of turbines connected to each feeder needs to be balanced

  • In multi-substation networks, the solver can only enforce a feeder_limit that is the minimum feasible number. The parameter may also be omitted (meaning unlimited feeders).

This router uses vidalt/HGS-CVRP: Modern implementation of the hybrid genetic search (HGS) algorithm specialized to the capacitated vehicle routing problem (CVRP).

HGSRouter can only produce radial topologies. Since a radial topology is a special case of the branched topology, solutions produced by this method can be used to warm-start both branched- and radial-topology models.

Load data¶

import required modules

[1]:
from optiwindnet.api import WindFarmNetwork, HGSRouter

Create an instance of wfn using .from_pbf()

[2]:
wfn = WindFarmNetwork.from_pbf(filepath='data/DTU_letters.osm.pbf', cables= [(7, 2000.0)])
wfn
[2]:
../_images/notebooks_b02_HGSRouter_12_0.svg

Optimize with HGSRouter¶

[3]:
res = wfn.optimize(router=HGSRouter(time_limit=3))
wfn.length()
[3]:
1596.1580407347585

Get solution_time¶

We can see the solution time for HGS using:

[4]:
wfn.S.graph['solution_time']
[4]:
0.02

It prints the computation time for each HGS algorithm call (which run in parallel in multi-core systems); each call handling one substation and its turbine cluster. The router partitions the turbines automatically in clusters, with the constraint of keeping the total number of feeders at the minimum.

Choosing time_limit wisely¶

Based on the solution times observed in the previous step, we can make an informed decision about the time limit for the HGS router. If increasing the time limit does not significantly improve the solution (e.g., does not result in a noticeably shorter cable length), we can consider reducing it to save computational resources. In this case, a time limit of 0.1 second appears to be sufficient, as it is well above all the solution times.

[5]:
wfn.optimize(router=HGSRouter(time_limit=0.1))
wfn.S.graph['solution_time']
[5]:
0.02

Check the length¶

We can see that, as expected, reducing the time limit from 10 seconds to 1 seconds has not affected the resultant length.

[6]:
wfn.length()
[6]:
1596.1580407347585

Plot the Optimized Network Graph¶

[7]:
wfn
[7]:
../_images/notebooks_b02_HGSRouter_25_0.svg