{
"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": [
""
],
"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": "53cb6a4e-57be-40a4-a0eb-7d95bc3c181b",
"metadata": {
"scrolled": true
},
"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",
"RUN!\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",
"2320 rows, 1722 cols, 8634 nonzeros 0s\n",
"\n",
"MIP start solution is feasible, objective value is 113076.197044\n",
"\n",
"Solving MIP model with:\n",
" 2320 rows\n",
" 1722 cols (842 binary, 880 integer, 0 implied int., 0 continuous, 0 domain fixed)\n",
" 8634 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% -21710.457804 113076.197044 119.20% 0 0 0 0 0.1s\n",
" 0 0 0 0.00% 103058.96252 113076.197044 8.86% 0 0 3 1337 0.2s\n",
" L 0 0 0 0.00% 104464.184489 108377.625532 3.61% 1159 68 110 3028 2.5s\n",
"\n",
"7.5% inactive integer columns, restarting\n",
"Model after restart has 2189 rows, 1591 cols (775 bin., 816 int., 0 impl., 0 cont., 0 dom.fix.), and 8087 nonzeros\n",
"\n",
" 0 0 0 0.00% 104464.185655 108377.625532 3.61% 45 0 0 11293 7.0s\n",
" 0 0 0 0.00% 104464.185655 108377.625532 3.61% 45 44 1 11755 7.0s\n",
" 0 0 0 0.00% 104464.185655 108377.625532 3.61% 45 44 82 22212 12.8s\n",
" 16 13 0 1.17% 104581.335462 108377.625532 3.50% 63 46 239 81564 21.2s\n",
" 39 32 0 1.19% 104581.335462 108377.625532 3.50% 220 51 851 120401 26.5s\n",
" 145 80 19 1.54% 104581.335462 108377.625532 3.50% 2308 83 4160 149709 33.7s\n",
" L 161 93 19 1.58% 104627.611389 108301.102486 3.39% 2240 88 4334 152193 35.7s\n",
" L 275 115 35 3.75% 104636.344814 107622.069286 2.77% 918 81 6037 169707 39.8s\n",
" 428 199 53 4.90% 104651.947562 107622.069286 2.76% 860 85 10070 196590 44.8s\n",
" 605 297 75 6.59% 104733.8315 107622.069286 2.68% 945 80 9565 222478 50.0s\n",
" 774 403 87 8.40% 104812.054462 107622.069286 2.61% 544 68 9898 248602 55.1s\n",
" 956 479 124 8.51% 104848.88925 107622.069286 2.58% 792 90 9879 274146 60.0s\n",
"\n",
"Solving report\n",
" Status Time limit reached\n",
" Primal bound 107622.069286\n",
" Dual bound 104848.88925\n",
" Gap 2.58% (tolerance: 0.5%)\n",
" P-D integral 2.09509593034\n",
" Solution status feasible\n",
" 107622.069286 (objective)\n",
" 0 (bound viol.)\n",
" 0 (int. viol.)\n",
" 0 (row viol.)\n",
" Timing 60.00 (total)\n",
" 0.00 (presolve)\n",
" 0.00 (solve)\n",
" 0.00 (postsolve)\n",
" Max sub-MIP depth 5\n",
" Nodes 956\n",
" Repair LPs 0 (0 feasible; 0 iterations)\n",
" LP iterations 274146 (total)\n",
" 144307 (strong br.)\n",
" 11085 (separation)\n",
" 28964 (heuristics)\n",
"WARNING: Loading a feasible but suboptimal solution. Please set\n",
"load_solution=False and check results.termination_condition and\n",
"results.found_feasible_solution() before loading a solution.\n"
]
},
{
"data": {
"text/plain": [
"SolutionInfo(runtime=, bound=104848.88924958107, objective=107622.0692857606, relgap=0.02576776356916277, 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": "28ea1365-a5e5-4412-bb68-dfd8b6a13151",
"metadata": {},
"outputs": [],
"source": [
"S, G = solver.get_solution()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8766e187-1ae9-4b28-8985-6c874bd54b88",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"svgplot(G)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}