{ "cells": [ { "cell_type": "markdown", "id": "5848a926-0ca5-4ce4-ada8-2cc9a7d784b1", "metadata": {}, "source": [ "## HiGHS example" ] }, { "cell_type": "code", "execution_count": 1, "id": "a261ff8d-2072-411a-8e0f-1a3cf121d74f", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.importer import load_repository\n", "from optiwindnet.svg import svgplot\n", "from optiwindnet.mesh import make_planar_embedding\n", "from optiwindnet.interarraylib import G_from_S\n", "from optiwindnet.heuristics import EW_presolver\n", "from optiwindnet.MILP import solver_factory, ModelOptions" ] }, { "cell_type": "markdown", "id": "2cb613dc-7548-48b2-8083-6f1d8024eadb", "metadata": {}, "source": [ "### Initialize Triton" ] }, { "cell_type": "code", "execution_count": 2, "id": "d1a64ce6-29ab-475b-8418-af899d232369", "metadata": {}, "outputs": [], "source": [ "locations = load_repository()" ] }, { "cell_type": "code", "execution_count": 3, "id": "4dfc0c8c-9a68-49bc-9758-b81fa31b19b2", "metadata": {}, "outputs": [], "source": [ "L = locations.triton\n", "capacity = 8" ] }, { "cell_type": "code", "execution_count": 4, "id": "e8043bfe-ba94-41a5-8030-45c3bde4a60a", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] }, { "cell_type": "markdown", "id": "047ae1e4-eb0c-40ad-8b2d-690ccc9602d1", "metadata": {}, "source": [ "### Optimize Triton" ] }, { "cell_type": "code", "execution_count": 5, "id": "a31972ff-ea2c-4328-a7ad-fdb07685a3e7", "metadata": {}, "outputs": [], "source": [ "P, A = make_planar_embedding(L)" ] }, { "cell_type": "markdown", "id": "31a73ca3-01eb-46bc-9909-de5211f4ec4e", "metadata": {}, "source": [ "Initial heuristic solution to warm-start the solver:" ] }, { "cell_type": "code", "execution_count": 6, "id": "d43133d0-dbd1-4146-840d-dc2570b82483", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 113076 m(+1) G09: 8, F18: 5κ = 8, T = 90" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sʹ = EW_presolver(A, capacity=capacity)\n", "Gʹ = G_from_S(Sʹ, A)\n", "svgplot(Gʹ)" ] }, { "cell_type": "code", "execution_count": 7, "id": "2b6165d5-f5a4-4267-95a1-e46fddad960e", "metadata": {}, "outputs": [], "source": [ "solver = solver_factory('highs')" ] }, { "cell_type": "code", "execution_count": 8, "id": "dbd760d9-b6b3-4969-8e2b-b839dfb4ac3e", "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": 9, "id": "8c40f62e-e0aa-4b51-87c0-62cb469a1f62", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running HiGHS 1.11.0 (git hash: n/a): Copyright (c) 2025 HiGHS under MIT licence terms\n", "MIP has 2618 rows; 1764 cols; 9660 nonzeros; 1764 integer variables (882 binary)\n", "Coefficient ranges:\n", " Matrix [1e+00, 8e+00]\n", " Cost [8e+02, 1e+04]\n", " Bound [1e+00, 8e+00]\n", " RHS [1e+00, 9e+01]\n", "Assessing feasibility of MIP using primal feasibility and integrality tolerance of 1e-06\n", "Solution has num max sum\n", "Col infeasibilities 0 0 0\n", "Integer infeasibilities 0 0 0\n", "Row infeasibilities 0 0 0\n", "Row residuals 0 0 0\n", "Presolving model\n", "2618 rows, 1764 cols, 9660 nonzeros 0s\n", "2326 rows, 1722 cols, 8665 nonzeros 0s\n", "\n", "MIP start solution is feasible, objective value is 113076.197044\n", "\n", "Solving MIP model with:\n", " 2326 rows\n", " 1722 cols (842 binary, 880 integer, 0 implied int., 0 continuous, 0 domain fixed)\n", " 8665 nonzeros\n", "\n", "Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;\n", " H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;\n", " I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;\n", " z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point\n", "\n", " Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work \n", "Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time\n", "\n", " 0 0 0 0.00% 18952.945815 113076.197044 83.24% 0 0 0 0 0.1s\n", " 0 0 0 0.00% 103058.96252 113076.197044 8.86% 0 0 2 1242 0.2s\n", " L 0 0 0 0.00% 104703.625168 109307.825317 4.21% 3057 86 138 3358 3.0s\n", " 0 0 0 0.00% 104703.653689 109307.825317 4.21% 3057 57 187 14528 8.6s\n", "\n", "6.8% inactive integer columns, restarting\n", "Model after restart has 2206 rows, 1602 cols (780 bin., 822 int., 0 impl., 0 cont., 0 dom.fix.), and 8178 nonzeros\n", "\n", " 0 0 0 0.00% 104703.653689 109307.825317 4.21% 57 0 0 14528 8.7s\n", " 0 0 0 0.00% 104703.653689 109307.825317 4.21% 57 55 5 15003 8.7s\n", " 22 19 0 0.40% 104739.582671 109307.825317 4.18% 97 57 687 79329 16.5s\n", " 60 32 4 0.42% 104739.582671 109307.825317 4.18% 656 64 1794 121487 21.8s\n", " L 64 27 5 1.28% 104739.582671 107975.453107 3.00% 770 73 1888 122055 23.6s\n", " L 93 32 9 3.94% 104739.582671 107387.202847 2.47% 1747 53 2804 131213 25.7s\n", " 239 111 29 4.79% 104873.667389 107387.202847 2.34% 2329 93 5906 158874 31.0s\n", " 324 156 38 4.95% 104913.716994 107387.202847 2.30% 1708 121 7813 181292 37.4s\n", " 401 211 40 5.07% 104954.685446 107387.202847 2.27% 1403 111 9353 207327 46.6s\n", " 546 304 47 5.19% 104975.197054 107387.202847 2.25% 1484 88 9480 234736 51.7s\n", " L 623 329 56 5.37% 104980.769957 107307.710638 2.17% 693 100 9944 251849 58.9s\n", " 659 343 65 5.37% 104980.769957 107307.710638 2.17% 667 102 9669 260551 60.0s\n", "\n", "Solving report\n", " Status Time limit reached\n", " Primal bound 107307.710638\n", " Dual bound 104980.769957\n", " Gap 2.17% (tolerance: 0.5%)\n", " P-D integral 1.97954174207\n", " Solution status feasible\n", " 107307.710638 (objective)\n", " 0 (bound viol.)\n", " 3.06354941415e-12 (int. viol.)\n", " 0 (row viol.)\n", " Timing 60.01 (total)\n", " 0.00 (presolve)\n", " 0.00 (solve)\n", " 0.00 (postsolve)\n", " Max sub-MIP depth 5\n", " Nodes 659\n", " Repair LPs 0 (0 feasible; 0 iterations)\n", " LP iterations 260551 (total)\n", " 138596 (strong br.)\n", " 16988 (separation)\n", " 35797 (heuristics)\n" ] }, { "data": { "text/plain": [ "SolutionInfo(runtime=60.02319720000014, bound=104980.76995741787, objective=107307.71063789072, relgap=0.02168474815686916, termination='maxTimeLimit')" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "solver.solve(\n", " mip_gap=0.005,\n", " time_limit=60,\n", " verbose=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "id": "d8cfe3a7-ff6f-4dca-b63e-1a1f81cc8852", "metadata": {}, "outputs": [], "source": [ "S, G = solver.get_solution()" ] }, { "cell_type": "code", "execution_count": 11, "id": "d4231ba4-8972-4125-ab10-4e965e7339a5", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Σλ = 107308 m(+0) G09: 7, F18: 5κ = 8, T = 90" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(G)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }