{
"cells": [
{
"cell_type": "markdown",
"id": "b7bacd8f-c90c-40ae-bd2b-de482bc92d3a",
"metadata": {},
"source": [
"## Constructor heuristic examples"
]
},
{
"cell_type": "markdown",
"id": "4da35f36-8503-4f78-ab0a-87f4425680b5",
"metadata": {},
"source": [
"`constructor()` is the unified constructive heuristic entry point. The legacy `EW_presolver()` is essentially represented by `constructor()` with `method='biased_EW'` and `weigh_detours=False`.\n",
"\n",
"This notebook compares a few constructor settings on the same location and then converts the topology **S** into routed graphs **G** using `PathFinder`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6fe1c44e-76f6-46e2-bb16-bdd61d2b3bdb",
"metadata": {},
"outputs": [],
"source": [
"from optiwindnet.importer import load_repository\n",
"from optiwindnet.mesh import make_planar_embedding\n",
"from optiwindnet.pathfinding import PathFinder\n",
"from optiwindnet.heuristics import constructor\n",
"from optiwindnet.interarraylib import G_from_S, calcload\n",
"from optiwindnet.svg import svgplot"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "42d0e6e7-28c3-4b26-b3fc-6e58c4e3af15",
"metadata": {},
"outputs": [],
"source": [
"locations = load_repository()"
]
},
{
"cell_type": "markdown",
"id": "63150136-1332-47f8-b721-2be9b9d9aab7",
"metadata": {},
"source": [
"### Simple example"
]
},
{
"cell_type": "markdown",
"id": "e22c7e4b-1c67-4277-9ddc-38c30c9078fa",
"metadata": {},
"source": [
"Load Hollandse Kust Zuid"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ae43a7f9-2979-4961-ae79-7d76e32bf96c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"L = locations.kustzuid\n",
"svgplot(L)"
]
},
{
"cell_type": "markdown",
"id": "24a4e9fe-9505-4230-90a8-b0d25f126bb5",
"metadata": {},
"source": [
"Optimize Hollandse Kust Zuid"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1d2c9948-56bf-4d6d-b174-d44e5d909976",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P, A = make_planar_embedding(L)\n",
"S = constructor(A, capacity=8)\n",
"G_tent = G_from_S(S, A)\n",
"svgplot(G_tent)"
]
},
{
"cell_type": "markdown",
"id": "96a91de1-e2d7-47b8-b629-1ab90e16963e",
"metadata": {},
"source": [
"Route the feeders so as to avoid crossings"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8bc6db9b-e395-4339-9643-525a618a39d1",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"H = PathFinder(G_tent, P, A).create_detours()\n",
"svgplot(H)"
]
},
{
"cell_type": "markdown",
"id": "065f48a3-36c1-438c-a0be-ebc2e21fd87a",
"metadata": {},
"source": [
"### Constructor methods and parameters"
]
},
{
"cell_type": "markdown",
"id": "b0f19a5e-390e-45ed-a399-a291886b0a61",
"metadata": {},
"source": [
"Load Merkur"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "91b98c0d-33b4-4567-8912-242ad28b00da",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"L = locations.merkur\n",
"svgplot(L)"
]
},
{
"cell_type": "markdown",
"id": "4a1425b9-1713-4117-aa77-bb640d2f0e5d",
"metadata": {},
"source": [
"Compare solutions obtained with different arguments"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "8ca3c0d9-d55a-4d98-a70c-41fa62c7c9c3",
"metadata": {},
"outputs": [],
"source": [
"P, A = make_planar_embedding(L)\n",
"capacity = 9\n",
"\n",
"settings = {\n",
" 'default rootlust': {},\n",
" 'rootlust (OBEW rootlust style)': dict(\n",
" method='rootlust',\n",
" # matching OBEW's rootlust is capacity-dependent\n",
" rootlust_=(0.0, 0.6 * (capacity - 1) / capacity), \n",
" ),\n",
" 'EW presolver style': dict(\n",
" method='biased_EW',\n",
" weigh_detours=False,\n",
" ),\n",
" 'biased_EW (OBEW style)': dict(\n",
" method='biased_EW',\n",
" # straight_feeder_route=False,\n",
" # weigh_detours=True,\n",
" ),\n",
" 'straight feeders (CPEW style)': dict(\n",
" method='biased_EW',\n",
" straight_feeder_route=True,\n",
" weigh_detours=False,\n",
" ),\n",
" 'radial (NBEW style)': dict(\n",
" method='radial_EW',\n",
" straight_feeder_route=True,\n",
" weigh_detours=False,\n",
" ),\n",
" 'radial (segmented feeders)': dict(\n",
" method='radial_EW',\n",
" # straight_feeder_route=False,\n",
" # weigh_detours=True,\n",
" ),\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "01b14031-f272-4ec3-9e32-0c112247eac3",
"metadata": {},
"outputs": [],
"source": [
"solutions = {}\n",
"for label, kwargs in settings.items():\n",
" S = constructor(A, capacity=capacity, **kwargs)\n",
" G_tent = G_from_S(S, A)\n",
" G = PathFinder(G_tent, planar=P, A=A).create_detours()\n",
" solutions[label] = G"
]
},
{
"cell_type": "markdown",
"id": "1cd386bf-a866-419e-a0a9-461da22e78a8",
"metadata": {},
"source": [
"Visualize the variants"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "9b7a48de-3bfa-4e7b-8a53-67cce458b140",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"default rootlust\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"rootlust (OBEW rootlust style)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"EW presolver style\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"biased_EW (OBEW style)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"straight feeders (CPEW style)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"radial (NBEW style)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"radial (segmented feeders)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"for label, G in solutions.items():\n",
" print(label)\n",
" display(svgplot(G))"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}