{ "cells": [ { "cell_type": "markdown", "id": "171e1a75-257f-4ef5-a98c-667b9460663d", "metadata": {}, "source": [ "# 3.6.3 Taylor et al 2023" ] }, { "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": 5, "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": 6, "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": 6, "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": 7, "id": "ed9067bb-250e-4a1a-981b-f586bc7f5985", "metadata": {}, "outputs": [], "source": [ "L = L_from_yaml(files('optiwindnet.data') / 'Taylor-2023.yaml')" ] }, { "cell_type": "code", "execution_count": 8, "id": "b6fab52e-aa7a-4b9b-bedd-9735db54e982", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] }, { "cell_type": "code", "execution_count": 9, "id": "d2ae9456-39d5-41c9-9677-d3a280301142", "metadata": {}, "outputs": [], "source": [ "P, A = make_planar_embedding(L)" ] }, { "cell_type": "code", "execution_count": 10, "id": "e5f363b2-9bd7-401a-a3d1-ec7d2104ac32", "metadata": {}, "outputs": [], "source": [ "Sʹ = EW_presolver(A, 12)" ] }, { "cell_type": "code", "execution_count": 11, "id": "f86b15bc-08d9-4df8-9e25-307c385735a4", "metadata": {}, "outputs": [], "source": [ "Gʹ = G_from_S(Sʹ, A)" ] }, { "cell_type": "code", "execution_count": 12, "id": "ebda5bc7-f34b-441e-9d7b-ece1045270e3", "metadata": {}, "outputs": [], "source": [ "Hʹ = PathFinder(Gʹ, planar=P, A=A).create_detours()" ] }, { "cell_type": "code", "execution_count": 13, "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": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(Hʹ)" ] }, { "cell_type": "code", "execution_count": 33, "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": 34, "id": "0dd2ed68-34c4-474e-875c-a2ac22fe8fc7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.21, 0.6)" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sʹ.graph['solution_time']" ] }, { "cell_type": "code", "execution_count": 35, "id": "9d4d334a-a4bf-4c4b-84a2-8d85b231028f", "metadata": {}, "outputs": [], "source": [ "Gʹ = G_from_S(Sʹ, A)" ] }, { "cell_type": "code", "execution_count": 36, "id": "f183ffad-4e86-4a3b-9341-eddd42f43995", "metadata": {}, "outputs": [], "source": [ "Hʹ = PathFinder(Gʹ, planar=P, A=A).create_detours()" ] }, { "cell_type": "code", "execution_count": 37, "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": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(Hʹ)" ] }, { "cell_type": "code", "execution_count": 38, "id": "9216760f-8edc-4d79-bab0-4baab6a5ce41", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.007366473452870892" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - Hʹ.size(weight='length')/G_ref.size(weight='length')" ] }, { "cell_type": "code", "execution_count": 41, "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": 42, "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.2 build v12.0.2rc0 (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 8\n", "MIPGap 0.001\n", "MIPFocus 1\n", "RINS 100\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: 0x6806bfea\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, 2964 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 133 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", " 0 0 100368.359 0 254 102564.806 100368.359 2.14% - 0s\n", "H 0 0 102551.56574 100368.359 2.13% - 0s\n", "H 0 0 102228.89260 100368.359 1.82% - 0s\n", "H 0 0 100984.60041 100368.359 0.61% - 0s\n", " 0 0 100458.078 0 180 100984.600 100458.078 0.52% - 0s\n", " 0 0 100462.084 0 247 100984.600 100462.084 0.52% - 0s\n", " 0 0 100462.092 0 247 100984.600 100462.092 0.52% - 0s\n", "H 0 0 100944.96471 100481.592 0.46% - 0s\n", "H 0 0 100938.87391 100481.592 0.45% - 0s\n", "H 0 0 100928.96611 100481.592 0.44% - 0s\n", " 0 0 100485.047 0 237 100928.966 100485.047 0.44% - 0s\n", " 0 0 100485.047 0 140 100928.966 100485.047 0.44% - 0s\n", "H 0 0 100874.89356 100485.047 0.39% - 0s\n", " 0 0 100485.974 0 233 100874.894 100485.974 0.39% - 0s\n", " 0 0 100489.631 0 230 100874.894 100489.631 0.38% - 0s\n", " 0 0 100490.141 0 262 100874.894 100490.141 0.38% - 0s\n", " 0 0 100490.245 0 276 100874.894 100490.245 0.38% - 0s\n", " 0 0 100490.249 0 274 100874.894 100490.249 0.38% - 0s\n", " 0 0 100498.221 0 274 100874.894 100498.221 0.37% - 0s\n", " 0 0 100498.900 0 272 100874.894 100498.900 0.37% - 0s\n", " 0 0 100499.226 0 291 100874.894 100499.226 0.37% - 0s\n", " 0 0 100499.247 0 290 100874.894 100499.247 0.37% - 0s\n", " 0 0 100514.756 0 279 100874.894 100514.756 0.36% - 1s\n", " 0 0 100516.069 0 282 100874.894 100516.069 0.36% - 1s\n", " 0 0 100516.632 0 293 100874.894 100516.632 0.36% - 1s\n", " 0 0 100516.675 0 294 100874.894 100516.675 0.36% - 1s\n", " 0 0 100519.122 0 293 100874.894 100519.122 0.35% - 1s\n", "H 0 0 100863.60197 100519.122 0.34% - 1s\n", " 0 0 100519.124 0 132 100863.602 100519.124 0.34% - 1s\n", " 0 0 100519.124 0 214 100863.602 100519.124 0.34% - 1s\n", " 0 0 100519.124 0 278 100863.602 100519.124 0.34% - 1s\n", " 0 0 100519.940 0 257 100863.602 100519.940 0.34% - 1s\n", " 0 0 100520.334 0 275 100863.602 100520.334 0.34% - 1s\n", " 0 0 100520.334 0 283 100863.602 100520.334 0.34% - 1s\n", " 0 0 100522.985 0 276 100863.602 100522.985 0.34% - 1s\n", " 0 0 100523.521 0 275 100863.602 100523.521 0.34% - 1s\n", " 0 0 100523.634 0 252 100863.602 100523.634 0.34% - 1s\n", " 0 0 100523.653 0 284 100863.602 100523.653 0.34% - 1s\n", " 0 0 100524.716 0 271 100863.602 100524.716 0.34% - 2s\n", " 0 0 100524.919 0 280 100863.602 100524.919 0.34% - 2s\n", " 0 0 100524.930 0 279 100863.602 100524.930 0.34% - 2s\n", " 0 0 100525.751 0 301 100863.602 100525.751 0.33% - 2s\n", " 0 2 100525.781 0 301 100863.602 100525.781 0.33% - 2s\n", "H 20 24 100861.75440 100535.529 0.32% 130 2s\n", "H 151 149 100859.33874 100535.645 0.32% 64.7 2s\n", "H 152 149 100817.57859 100535.645 0.28% 65.1 2s\n", "H 201 189 100812.50451 100538.090 0.27% 56.1 2s\n", "H 253 222 100809.68529 100538.090 0.27% 52.9 3s\n", " 2173 1263 100565.216 9 168 100809.685 100549.749 0.26% 38.9 5s\n", "H 2196 1214 100795.05728 100549.749 0.24% 38.5 6s\n", "H 2361 1255 100778.04543 100561.622 0.21% 42.2 6s\n", "\n", "Cutting planes:\n", " Gomory: 25\n", " Implied bound: 20\n", " MIR: 128\n", " StrongCG: 4\n", " Flow cover: 132\n", " Flow path: 13\n", " Inf proof: 7\n", " Network: 9\n", " RLT: 1\n", " Relax-and-lift: 1\n", " BQP: 1\n", "\n", "Explored 4029 nodes (189142 simplex iterations) in 8.03 seconds (5.70 work units)\n", "Thread count was 16 (of 16 available processors)\n", "\n", "Solution count 10: 100778 100795 100810 ... 100929\n", "\n", "Time limit reached\n", "Best objective 1.007780454345e+05, best bound 1.005738000083e+05, gap 0.2027%\n", "WARNING: Loading a SolverResults object with an 'aborted' status, but\n", "containing a solution\n" ] }, { "data": { "text/plain": [ "SolutionInfo(runtime=8.032000064849854, bound=100573.80000832163, objective=100778.04543446109, relgap=0.0020266857256354687, termination='maxTimeLimit')" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "solver.solve(\n", " mip_gap=0.001,\n", " time_limit=8,\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": 43, "id": "7a78a9e7-721d-42d4-8a6f-ccd3f1ea8ac9", "metadata": {}, "outputs": [], "source": [ "S, G = solver.get_solution()" ] }, { "cell_type": "code", "execution_count": 44, "id": "3983390d-107d-4664-b804-3794708e23ef", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 100778.0 m(+1) α: 7, β: 5κ = 12, T = 122" ], "text/plain": [ "" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(G)" ] }, { "cell_type": "code", "execution_count": 46, "id": "08f5b4da-6779-459e-acf3-10eb45a5d307", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.033879957250474324" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - G.size(weight='length')/G_ref.size(weight='length')" ] }, { "cell_type": "code", "execution_count": 48, "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 }