{ "cells": [ { "cell_type": "markdown", "id": "fbed597e", "metadata": {}, "source": [ "# EWRouter example" ] }, { "cell_type": "markdown", "id": "c7f58b02", "metadata": {}, "source": [ "This notebook uses `OptiWindNet` to route the collector system cables via `EWRouter`." ] }, { "cell_type": "markdown", "id": "eb6066d8", "metadata": {}, "source": [ "### ⚡ EWRouter (Esau-Williams Heuristic)" ] }, { "cell_type": "markdown", "id": "6b901e0f", "metadata": {}, "source": [ "`EWRouter` is a *fast and lightweight heuristic router* based on the *Esau-Williams algorithm*. It builds a spanning tree that connects turbines to substations while respecting cable capacity constraints. This method is especially suitable for electrical network optimization in *quick prototyping* and *large-scale turbine layouts* where optimization speed is more important than global optimality.\n", "\n", "> `EWRouter` is the default router used in `WindFarmNetwork`. If no router is specified when creating a `WindFarmNetwork` instance, `.optimize()` will automatically run with `EWRouter`." ] }, { "cell_type": "markdown", "id": "3be8e42a", "metadata": {}, "source": [ "#### 🔧 Constructor: `EWRouter(...)`" ] }, { "cell_type": "markdown", "id": "06c495e2", "metadata": {}, "source": [ "**Required arguments:**\n", "\n", "* None -> You can instantiate `EWRouter()` without any arguments.\n", "\n", "**Optional arguments:**\n", "\n", "| Argument | Type | Description |\n", "| -------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n", "| `maxiter` | `int` | Maximum number of iterations (default: `10000`). Controls how long the heuristic explores the search space. |\n", "| `feeder_route` | `str` | Routing style:
• `\"segmented\"` *(default)*
• `\"straight\"` |\n", "| `verbose` | `bool` | If `True`, prints potential warnings during routing (default: `False`). |\n", "\n", "**✅ Example**\n", "\n", "```python\n", "# Implicit use of EWRouter as default\n", "wf = WindFarmNetwork(cables=..., turbinesC=..., substationsC=...)\n", "wf.optimize() # Uses EWRouter by default\n", "\n", "# Explicitly use with custom options\n", "router = EWRouter(feeder_route='straight', maxiter=5000)\n", "wf = WindFarmNetwork(cables=..., turbinesC=..., substationsC=..., router=router)\n", "wf.optimize()\n", "```\n", "\n", ">While `EWRouter` is very efficient, it’s a *heuristic* and does *not guarantee globally optimal* solutions. Use it when you need speed or when solving large problems where exact methods are too slow." ] }, { "cell_type": "code", "execution_count": 1, "id": "c42a3703-113b-4aee-8dfb-a0b3b54663e6", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.api import WindFarmNetwork, EWRouter" ] }, { "cell_type": "markdown", "id": "54a4dcb5", "metadata": {}, "source": [ "create an instance of `wfn` using `.from_pbf()`\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "1c6f3015", "metadata": {}, "outputs": [], "source": [ "wfn = WindFarmNetwork.from_pbf(filepath='data/DTU_letters.osm.pbf', cables=[(7, 2000.0)])" ] }, { "cell_type": "code", "execution_count": 3, "id": "c838598f", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wfn" ] }, { "cell_type": "markdown", "id": "5d38a18d-ab5e-4b03-ae74-9ccb4dedbe07", "metadata": {}, "source": [ "### Optimize with EWRouter" ] }, { "cell_type": "markdown", "id": "d77b7cc6", "metadata": {}, "source": [ "#### Optimize with default settings." ] }, { "cell_type": "code", "execution_count": 4, "id": "7884b794", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1647.108905210097\n" ] }, { "data": { "image/svg+xml": [ "3 294 218 €Σλ = 1 647.1 m(+2) [-1]: 8κ = 7, T = 40" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "router = EWRouter()\n", "res = wfn.optimize(router=router)\n", "print(wfn.length())\n", "wfn" ] }, { "cell_type": "markdown", "id": "49c807c9", "metadata": {}, "source": [ "#### Optimize with user-defined settings." ] }, { "cell_type": "code", "execution_count": 5, "id": "98fc84a8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1707.0505869707563\n" ] }, { "data": { "image/svg+xml": [ "3 414 101 €Σλ = 1 707.1 m(+3) [-1]: 9κ = 7, T = 40" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "router = EWRouter( \n", " maxiter=20000,\n", " feeder_route='straight',\n", " verbose=True)\n", "res = wfn.optimize(router=router)\n", "print(wfn.length())\n", "wfn" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }