{ "cells": [ { "cell_type": "markdown", "id": "c2c6a4f3-7a9f-417d-b8c7-c9215da5f142", "metadata": {}, "source": [ "This is used in the paper **Flexible cable routing framework for wind farm collection system optimization**." ] }, { "cell_type": "code", "execution_count": 1, "id": "bdf5ac5d-ce06-4425-94be-2793edcbf33e", "metadata": {}, "outputs": [], "source": [ "from importlib.resources import files\n", "import dill" ] }, { "cell_type": "code", "execution_count": 2, "id": "ff8b4268-f6cd-4f4a-82d1-200f208fe9c2", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.interarraylib import G_from_S\n", "from optiwindnet.svg import svgplot\n", "from optiwindnet.mesh import make_planar_embedding\n", "from optiwindnet.baselines.hgs import hgs_multiroot\n", "from optiwindnet.importer import L_from_yaml\n", "from optiwindnet.pathfinding import PathFinder\n", "from optiwindnet.MILP import solver_factory, ModelOptions\n", "from optiwindnet.heuristics import EW_presolver\n", "from optiwindnet.interarraylib import as_normalized" ] }, { "cell_type": "code", "execution_count": 3, "id": "35bb73d8-26c0-4132-bfae-d9438f94e6fe", "metadata": {}, "outputs": [], "source": [ "solver = solver_factory('gurobi')" ] }, { "cell_type": "markdown", "id": "e2c8bb22-2a1f-4fb1-bafd-bbc3528057f4", "metadata": {}, "source": [ "## Reference solution" ] }, { "cell_type": "markdown", "id": "e8ec0a99-6d06-4d36-9da8-ed28a8831646", "metadata": {}, "source": [ "Taylor, P., Yue, H., Campos-Gaona, D., Anaya-Lara, O., & Jia, C. (2023). Wind farm array cable layout optimisation for complex offshore sites—A decomposition based heuristic approach. IET Renewable Power Generation, 17(2), 243–259. https://doi.org/10.1049/rpg2.12593" ] }, { "cell_type": "code", "execution_count": 4, "id": "2b6f398d-6333-4090-a329-cd5a0d7a2b47", "metadata": {}, "outputs": [], "source": [ "G_ref = dill.load(open('data/taylor_2023_paper_routeset.dill', 'rb'))" ] }, { "cell_type": "code", "execution_count": 5, "id": "37fbe442-9722-4d7f-918f-c97a7e9ed5e1", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 104312.0 m(+2) α: 7, β: 6κ = 12, T = 122" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(G_ref)" ] }, { "cell_type": "markdown", "id": "8308f53d-4b45-4c3d-9b71-26ff4b4ef519", "metadata": {}, "source": [ "## Start here" ] }, { "cell_type": "code", "execution_count": 6, "id": "ed9067bb-250e-4a1a-981b-f586bc7f5985", "metadata": {}, "outputs": [], "source": [ "L = L_from_yaml(files('optiwindnet.data') / 'Taylor-2023.yaml')" ] }, { "cell_type": "code", "execution_count": 7, "id": "b6fab52e-aa7a-4b9b-bedd-9735db54e982", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] }, { "cell_type": "code", "execution_count": 8, "id": "d2ae9456-39d5-41c9-9677-d3a280301142", "metadata": {}, "outputs": [], "source": [ "P, A = make_planar_embedding(L)" ] }, { "cell_type": "code", "execution_count": 9, "id": "e5f363b2-9bd7-401a-a3d1-ec7d2104ac32", "metadata": {}, "outputs": [], "source": [ "Sʹ = EW_presolver(A, 12)" ] }, { "cell_type": "code", "execution_count": 10, "id": "f86b15bc-08d9-4df8-9e25-307c385735a4", "metadata": {}, "outputs": [], "source": [ "Gʹ = G_from_S(Sʹ, A)" ] }, { "cell_type": "code", "execution_count": 11, "id": "ebda5bc7-f34b-441e-9d7b-ece1045270e3", "metadata": {}, "outputs": [], "source": [ "Hʹ = PathFinder(Gʹ, planar=P, A=A).create_detours()" ] }, { "cell_type": "code", "execution_count": 12, "id": "78bb3327-0d08-4e31-b762-0aa47bd62561", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 105984.0 m(+3) α: 7, β: 7κ = 12, T = 122" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(Hʹ)" ] }, { "cell_type": "code", "execution_count": 13, "id": "da07d6bd-3a4d-43bb-97cd-b4f8823a753b", "metadata": {}, "outputs": [], "source": [ "Sʹ = hgs_multiroot(as_normalized(A), capacity=12, time_limit=0.6)" ] }, { "cell_type": "code", "execution_count": 14, "id": "0dd2ed68-34c4-474e-875c-a2ac22fe8fc7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.24, 0.45)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sʹ.graph['solution_time']" ] }, { "cell_type": "code", "execution_count": 15, "id": "9d4d334a-a4bf-4c4b-84a2-8d85b231028f", "metadata": {}, "outputs": [], "source": [ "Gʹ = G_from_S(Sʹ, A)" ] }, { "cell_type": "code", "execution_count": 16, "id": "f183ffad-4e86-4a3b-9341-eddd42f43995", "metadata": {}, "outputs": [], "source": [ "Hʹ = PathFinder(Gʹ, planar=P, A=A).create_detours()" ] }, { "cell_type": "code", "execution_count": 17, "id": "b6a8053b-e74d-430a-9c13-cf478084d58f", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 103544.0 m(+0) α: 5, β: 6κ = 12, T = 122" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(Hʹ)" ] }, { "cell_type": "code", "execution_count": 18, "id": "9216760f-8edc-4d79-bab0-4baab6a5ce41", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.007366473452870892" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - Hʹ.size(weight='length')/G_ref.size(weight='length')" ] }, { "cell_type": "code", "execution_count": 19, "id": "1d961d96-a63c-43c4-a283-78e40b6e8d66", "metadata": {}, "outputs": [], "source": [ "solver.set_problem(\n", " P, A,\n", " capacity=Sʹ.graph['capacity'],\n", " model_options=ModelOptions(\n", " topology=\"branched\",\n", " feeder_route=\"segmented\",\n", " feeder_limit=\"unlimited\",\n", " ),\n", " warmstart=Sʹ,\n", ")" ] }, { "cell_type": "code", "execution_count": 20, "id": "d4deede9-2051-4318-b240-f0e790a38daf", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter OutputFlag to value 1\n", "Gurobi Optimizer version 12.0.3 build v12.0.3rc0 (win64 - Windows 11.0 (26100.2))\n", "\n", "CPU model: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz, instruction set [SSE2|AVX|AVX2|AVX512]\n", "Thread count: 8 physical cores, 16 logical processors, using up to 16 threads\n", "\n", "Non-default parameters:\n", "TimeLimit 5\n", "MIPGap 0.001\n", "MIPFocus 1\n", "RINS 100\n", "VarBranch 1\n", "CutPasses 4\n", "\n", "Academic license 937681 - for non-commercial use only - registered to ma___@dtu.dk\n", "Optimize a model with 4322 rows, 2896 columns and 16328 nonzeros\n", "Model fingerprint: 0x8af4f963\n", "Variable types: 0 continuous, 2896 integer (1448 binary)\n", "Coefficient statistics:\n", " Matrix range [1e+00, 1e+01]\n", " Objective range [4e+02, 9e+03]\n", " Bounds range [1e+00, 1e+01]\n", " RHS range [1e+00, 1e+02]\n", "\n", "Loaded user MIP start with objective 103544\n", "\n", "Presolve removed 531 rows and 0 columns\n", "Presolve time: 0.03s\n", "Presolved: 3791 rows, 2896 columns, 13820 nonzeros\n", "Variable types: 0 continuous, 2896 integer (1448 binary)\n", "\n", "Root relaxation: objective 9.983546e+04, 2945 iterations, 0.06 seconds (0.07 work units)\n", "\n", " Nodes | Current Node | Objective Bounds | Work\n", " Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n", "\n", " 0 0 99835.4625 0 131 103543.724 99835.4625 3.58% - 0s\n", "H 0 0 102928.08101 99835.4625 3.00% - 0s\n", "H 0 0 102579.91095 99835.4625 2.68% - 0s\n", "H 0 0 102564.80595 99835.4625 2.66% - 0s\n", "H 0 0 101945.23428 100385.045 1.53% - 0s\n", "H 0 0 101941.50091 100385.045 1.53% - 0s\n", "H 0 0 101792.05306 100385.045 1.38% - 0s\n", " 0 0 100385.045 0 269 101792.053 100385.045 1.38% - 0s\n", "H 0 0 101449.42419 100385.045 1.05% - 0s\n", "H 0 0 101320.93030 100385.045 0.92% - 0s\n", "H 0 0 101002.99294 100459.087 0.54% - 0s\n", "H 0 0 100997.84062 100459.087 0.53% - 0s\n", " 0 0 100459.087 0 221 100997.841 100459.087 0.53% - 0s\n", " 0 0 100460.601 0 233 100997.841 100460.601 0.53% - 0s\n", " 0 0 100460.602 0 233 100997.841 100460.602 0.53% - 0s\n", " 0 0 100484.376 0 222 100997.841 100484.376 0.51% - 0s\n", " 0 0 100484.376 0 147 100997.841 100484.376 0.51% - 0s\n", "H 0 0 100944.96471 100484.376 0.46% - 0s\n", " 0 0 100484.670 0 231 100944.965 100484.670 0.46% - 0s\n", " 0 0 100487.927 0 233 100944.965 100487.927 0.45% - 0s\n", " 0 0 100488.213 0 215 100944.965 100488.213 0.45% - 0s\n", " 0 0 100488.246 0 215 100944.965 100488.246 0.45% - 0s\n", " 0 0 100498.562 0 265 100944.965 100498.562 0.44% - 0s\n", " 0 0 100499.797 0 296 100944.965 100499.797 0.44% - 0s\n", " 0 0 100500.291 0 283 100944.965 100500.291 0.44% - 0s\n", " 0 0 100500.306 0 299 100944.965 100500.306 0.44% - 0s\n", "H 0 0 100919.34129 100500.306 0.42% - 1s\n", "H 0 0 100917.57961 100500.306 0.41% - 1s\n", "H 0 0 100901.68653 100514.234 0.38% - 1s\n", "H 0 0 100894.06812 100514.234 0.38% - 1s\n", " 0 0 100514.234 0 229 100894.068 100514.234 0.38% - 1s\n", " 0 0 100517.593 0 260 100894.068 100517.593 0.37% - 1s\n", " 0 0 100518.294 0 276 100894.068 100518.294 0.37% - 1s\n", " 0 0 100518.365 0 285 100894.068 100518.365 0.37% - 1s\n", " 0 0 100518.365 0 282 100894.068 100518.365 0.37% - 1s\n", "H 0 0 100871.45809 100518.365 0.35% - 1s\n", "H 0 0 100863.60197 100518.365 0.34% - 1s\n", " 0 0 100520.841 0 258 100863.602 100520.841 0.34% - 1s\n", " 0 0 100520.841 0 133 100863.602 100520.841 0.34% - 1s\n", " 0 0 100520.841 0 228 100863.602 100520.841 0.34% - 1s\n", " 0 0 100520.841 0 161 100863.602 100520.841 0.34% - 1s\n", " 0 0 100520.841 0 257 100863.602 100520.841 0.34% - 1s\n", " 0 0 100521.478 0 246 100863.602 100521.478 0.34% - 1s\n", " 0 0 100521.527 0 258 100863.602 100521.527 0.34% - 1s\n", " 0 0 100522.902 0 265 100863.602 100522.902 0.34% - 1s\n", " 0 0 100522.954 0 270 100863.602 100522.954 0.34% - 1s\n", " 0 0 100524.972 0 241 100863.602 100524.972 0.34% - 1s\n", " 0 0 100525.199 0 244 100863.602 100525.199 0.34% - 1s\n", " 0 0 100525.262 0 235 100863.602 100525.262 0.34% - 1s\n", " 0 0 100525.833 0 261 100863.602 100525.833 0.33% - 1s\n", " 0 2 100525.864 0 261 100863.602 100525.864 0.33% - 1s\n", "H 39 48 100853.92852 100531.675 0.32% 104 2s\n", "H 157 151 100853.01366 100531.675 0.32% 63.1 2s\n", "H 158 151 100840.13267 100531.675 0.31% 63.3 2s\n", "H 587 398 100836.08865 100537.148 0.30% 49.5 3s\n", "H 598 419 100823.57443 100537.148 0.28% 49.5 3s\n", "H 706 443 100796.21047 100537.148 0.26% 49.5 3s\n", "H 978 583 100794.97109 100548.611 0.24% 46.1 4s\n", "\n", "Cutting planes:\n", " Gomory: 10\n", " Lift-and-project: 1\n", " Implied bound: 4\n", " MIR: 44\n", " StrongCG: 5\n", " Flow cover: 37\n", " Flow path: 1\n", " Inf proof: 6\n", " Network: 7\n", " Relax-and-lift: 2\n", "\n", "Explored 2155 nodes (95704 simplex iterations) in 5.02 seconds (3.60 work units)\n", "Thread count was 16 (of 16 available processors)\n", "\n", "Solution count 10: 100795 100796 100824 ... 100894\n", "\n", "Time limit reached\n", "Best objective 1.007949710936e+05, best bound 1.005572361407e+05, gap 0.2359%\n", "WARNING: Loading a SolverResults object with an 'aborted' status, but\n", "containing a solution\n" ] }, { "data": { "text/plain": [ "SolutionInfo(runtime=5.0290000438690186, bound=100557.23614067948, objective=100794.97109360032, relgap=0.002358599346192314, termination='maxTimeLimit')" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "solver.solve(\n", " mip_gap=0.001,\n", " time_limit=5,\n", " verbose=True,\n", " options=dict(\n", " mipfocus=1,\n", " RINS=100,\n", " CutPasses=4,\n", " VarBranch=1,\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 21, "id": "7a78a9e7-721d-42d4-8a6f-ccd3f1ea8ac9", "metadata": {}, "outputs": [], "source": [ "S, G = solver.get_solution()" ] }, { "cell_type": "code", "execution_count": 22, "id": "3983390d-107d-4664-b804-3794708e23ef", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 100795.0 m(+1) α: 6, β: 6κ = 12, T = 122" ], "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(G)" ] }, { "cell_type": "code", "execution_count": 23, "id": "08f5b4da-6779-459e-acf3-10eb45a5d307", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.03371769751959075" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - G.size(weight='length')/G_ref.size(weight='length')" ] }, { "cell_type": "code", "execution_count": 24, "id": "582d5e10-904c-4619-992d-a7c5f5bae5c8", "metadata": {}, "outputs": [], "source": [ "with open('Taylor_comparison_κ_12_branched_our.dill', 'wb') as outfile:\n", " dill.dump(G, outfile)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }