{ "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 constructor\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": [ "Σλ = 111 864 m(+2) G09: 9, F18: 5κ = 8, T = 90" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sʹ = constructor(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": [ { "data": { "text/plain": [ "SolutionInfo(runtime=60.00697207450867, bound=104851.8677732182, objective=106882.72685312979, relgap=0.01900081649958507, 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": [ "Σλ = 106 883 m(+0) G09: 6, F18: 6κ = 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 }