{
"cells": [
{
"cell_type": "markdown",
"id": "3ce77085-3338-46b2-8784-de1187f43f25",
"metadata": {},
"source": [
"## Hybrid Genetic Search meta-heuristic example"
]
},
{
"cell_type": "markdown",
"id": "5003abe0-384b-46d8-87e0-934500cc0496",
"metadata": {},
"source": [
"The meta-heuristic used is [vidalt/HGS-CVRP: Modern implementation of the hybrid genetic search (HGS) algorithm specialized to the capacitated vehicle routing problem (CVRP). This code also includes an additional neighborhood called SWAP\\*.](https://github.com/vidalt/HGS-CVRP)"
]
},
{
"cell_type": "markdown",
"id": "71a324a5-727c-40a0-b4df-72d522633b16",
"metadata": {},
"source": [
"HGS-CVRP 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.\n",
"\n",
"If a routeset is desired, use *PathFinder*."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "672c7061-abbf-4da0-9236-232dde141ac9",
"metadata": {},
"outputs": [],
"source": [
"from optiwindnet.importer import load_repository\n",
"from optiwindnet.svg import svgplot\n",
"from optiwindnet.baselines.hgs import hgs_multiroot\n",
"from optiwindnet.mesh import make_planar_embedding\n",
"from optiwindnet.pathfinding import PathFinder\n",
"from optiwindnet.interarraylib import G_from_S, as_normalized"
]
},
{
"cell_type": "markdown",
"id": "92bfd6df-c545-48d2-b4d0-e69a1a6c473b",
"metadata": {},
"source": [
"### Load Hornsea"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "51e1e821-a0ea-47c3-a197-4b625bbf3a3b",
"metadata": {},
"outputs": [],
"source": [
"locations = load_repository()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "36ac83fb-02db-4640-b7a5-891715f70b83",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"L = locations.hornsea\n",
"svgplot(L)"
]
},
{
"cell_type": "markdown",
"id": "c7d1dd72-c13b-4454-8754-9098e2faf9a8",
"metadata": {},
"source": [
"### Optimize Hornsea"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "37c0ec1f-bcc2-4025-92bc-613fdebbf1b1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0.24, 0.34, 0.28)\n"
]
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P, A = make_planar_embedding(L)\n",
"S = hgs_multiroot(as_normalized(A), capacity=7, time_limit=0.5)\n",
"print(S.graph['solution_time'])\n",
"G = G_from_S(S, A)\n",
"svgplot(G)"
]
},
{
"cell_type": "markdown",
"id": "e8aa52ec-ba4f-41bd-9bb0-f6655fcc6aab",
"metadata": {},
"source": [
"### Route the feeders so as to avoid crossings"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cf958a39-99fe-48d6-891c-8ccb1688b261",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"H = PathFinder(G, P, A).create_detours()\n",
"svgplot(H)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}