{
"cells": [
{
"cell_type": "markdown",
"id": "bed2fae1-baf6-4b30-bc89-faef27a81f9a",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"# 3.2 Comparison with MILP model from literature"
]
},
{
"cell_type": "markdown",
"id": "9105c12f-0648-4bef-ba89-e3c886b940d5",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"This is used in the paper **Flexible cable routing framework for wind farm collection system optimization**."
]
},
{
"cell_type": "markdown",
"id": "10656839-cd80-4a33-bc6d-7ddba2381c67",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Preamble"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2a6b52ed-e380-46ea-97e2-dce5bc73670a",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"import urllib.request\n",
"import lzma\n",
"import shutil\n",
"import os\n",
"from pathlib import Path\n",
"import numpy as np\n",
"import xarray as xr"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "39744153-45ea-4420-b5d4-30e8c542d959",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"from optiwindnet.db import database_connection, G_from_routeset, NodeSet, RouteSet\n",
"from optiwindnet.plotting import gplot"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "62a9e082-965e-45ed-9dcf-760d1457ce96",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
"\n",
"%config InlineBackend.figure_formats = ['svg']\n",
"plt.rcParams['svg.fonttype'] = 'none'\n",
"\n",
"style = Path('mplstyles/jupyter_dark.mplstyle')\n",
"style.is_file() and plt.style.use(style)"
]
},
{
"cell_type": "markdown",
"id": "1c115d48-47ab-4774-9340-35765926afc6",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6623c217-c0a3-4d97-b1dc-12bcae58caa4",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"def fetch_zenodo_file(record, file_name, target_path: str = '.'):\n",
" url = f'https://zenodo.org/records/{record}/files/{file_name}.xz?download=1'\n",
" try:\n",
" with open(os.path.join(target_path, file_name), 'xb') as f_out:\n",
" with urllib.request.urlopen(url) as response:\n",
" with lzma.open(response) as decompressor:\n",
" shutil.copyfileobj(decompressor, f_out)\n",
" except FileExistsError:\n",
" return"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "35578a39-41b4-4c34-94ed-44ce8a1abad7",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"record = '19798734'\n",
"DB_FILE = 'MILP_model_comparison.v4.sqlite'"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "24cc97f0-92b7-4651-a35d-b54471937ba3",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"fetch_zenodo_file(record, DB_FILE)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "dd07ebb1-44f2-4dfe-9b99-07c4369f96a8",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"handle_from_name = {\n",
" 'BIG Ronne Bank North': 'rbn',\n",
" 'Ormonde': 'ormonde',\n",
" 'BIG Ronne Bank South': 'rbs',\n",
" 'DanTysk': 'dantysk',\n",
" 'Horns Rev 1': 'horns',\n",
" 'Thanet': 'thanet',\n",
" 'West of Duddon Sands': 'sands',\n",
" 'Anholt': 'anholt',\n",
" 'SynthTess': 'tess',\n",
" 'London Array': 'london',\n",
" 'SynthTess (3 OSS)': 'tess3',\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "26960164-9690-4ce0-8f79-e952c20f6845",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Axes definition"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6aecfb07-91c6-4509-9bf1-3572af86718b",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"Ns_q = NodeSet.select()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "71b39664-ecf0-4e11-82cc-11a549259bda",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'BIG Ronne Bank North': 'rbn',\n",
" 'Ormonde': 'ormonde',\n",
" 'BIG Ronne Bank South': 'rbs',\n",
" 'DanTysk': 'dantysk',\n",
" 'Horns Rev 1 legacy': 'horns',\n",
" 'Thanet': 'thanet',\n",
" 'West of Duddon Sands': 'sands',\n",
" 'Anholt legacy': 'anholt',\n",
" 'SynthTess': 'tess',\n",
" 'London Array legacy': 'london',\n",
" 'SynthTess (3 OSS)': 'tess3'}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with database_connection(DB_FILE):\n",
" name2handle = dict((ns.name, next(iter(ns.routesets)).handle) for ns in Ns_q)\n",
"name2handle"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5a218172-161f-4d6c-93a8-99eac412670c",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"['rbn',\n",
" 'ormonde',\n",
" 'rbs',\n",
" 'dantysk',\n",
" 'horns',\n",
" 'thanet',\n",
" 'sands',\n",
" 'anholt',\n",
" 'tess',\n",
" 'london',\n",
" 'tess3']"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"node_count = {handle: NodeSet.get(NodeSet.name == name).T\n",
" for name, handle in name2handle.items()}\n",
"handleAx = list(node_count.keys())\n",
"handleAx.sort(key=lambda k: node_count[k])\n",
"handleAx"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "9a406bdc-9463-4913-9e55-d2fb6c7b075b",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"capacityLim = (3, 16)\n",
"capacityAx = list(range(*capacityLim))\n",
"capacityAx"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "1c173274-5939-4bd0-9f39-7e0b90ae8e91",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"solverAx = ['global_optimizer', 'MILP']"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6cd6dd51-f573-43ca-80d2-69c5e638f381",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"data = 'length', 'graph', 'runtime'\n",
"dims= 'handle', 'capacity', 'solver'\n",
"shape = len(handleAx), len(capacityAx), len(solverAx)\n",
"optima = xr.Dataset(data_vars=dict(length=(dims, np.full(shape, np.nan)),\n",
" graph=(dims, np.empty(shape, dtype=object)),\n",
" runtime=(dims, np.full(shape, np.nan))),\n",
" coords=dict(zip(dims, (handleAx, capacityAx, solverAx))))"
]
},
{
"cell_type": "markdown",
"id": "18d70401-d616-4604-82e3-61ec6ebe2709",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Fetch data from database"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c3e1caf0-1379-4426-8033-9d64d71256ae",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('rbn', 3, 'global_optimizer') 33298.17836033638\n",
"('rbn', 4, 'global_optimizer') 29860.204861551734\n",
"('rbn', 5, 'global_optimizer') 28423.402888795787\n",
"('rbn', 6, 'global_optimizer') 27716.325905266214\n",
"('rbn', 7, 'global_optimizer') 27168.285951533515\n",
"('rbn', 8, 'global_optimizer') 26552.257544399687\n",
"('rbn', 9, 'global_optimizer') 26552.244636810836\n",
"('rbn', 10, 'global_optimizer') 26201.089671194622\n",
"('rbn', 11, 'global_optimizer') 26201.086106804836\n",
"('rbn', 12, 'global_optimizer') 26156.787801059225\n",
"('rbn', 13, 'global_optimizer') 25805.619229896412\n",
"('ormonde', 3, 'global_optimizer') 29324.48987050354\n",
"('ormonde', 4, 'global_optimizer') 24688.407433332213\n",
"('ormonde', 5, 'global_optimizer') 21429.106016125974\n",
"('ormonde', 6, 'global_optimizer') 19474.12162862974\n",
"('ormonde', 7, 'global_optimizer') 18039.395753991095\n",
"('ormonde', 8, 'global_optimizer') 16921.93611519869\n",
"('ormonde', 9, 'global_optimizer') 16921.93611519869\n",
"('ormonde', 10, 'global_optimizer') 16921.93611519869\n",
"('ormonde', 11, 'global_optimizer') 16739.07924499595\n",
"('ormonde', 12, 'global_optimizer') 16760.418413486368\n",
"('ormonde', 13, 'global_optimizer') 16703.761325471824\n",
"('ormonde', 14, 'global_optimizer') 16733.895536985965\n",
"('ormonde', 15, 'global_optimizer') 16408.416545612094\n",
"('rbs', 3, 'global_optimizer') 112191.83135823737\n",
"('rbs', 4, 'global_optimizer') 96763.06977124394\n",
"('rbs', 5, 'global_optimizer') 88555.6831332727\n",
"('rbs', 6, 'global_optimizer') 83608.47225858844\n",
"('rbs', 7, 'global_optimizer') 81373.62178541177\n",
"('rbs', 8, 'global_optimizer') 79779.67989422882\n",
"('rbs', 9, 'global_optimizer') 78342.94151532424\n",
"('rbs', 10, 'global_optimizer') 77816.19093515755\n",
"('rbs', 11, 'global_optimizer') 76847.45689962857\n",
"('rbs', 12, 'global_optimizer') 76461.16977503322\n",
"('rbs', 13, 'global_optimizer') 75934.43060698418\n",
"('rbs', 14, 'global_optimizer') 75684.76644574714\n",
"('rbs', 15, 'global_optimizer') 75684.78493691\n",
"('dantysk', 3, 'global_optimizer') 186965.4607179916\n",
"('dantysk', 4, 'global_optimizer') 150107.1555436056\n",
"('dantysk', 5, 'global_optimizer') 128883.88192879168\n",
"('dantysk', 6, 'global_optimizer') 114424.59372828214\n",
"('dantysk', 7, 'global_optimizer') 105055.65476872603\n",
"('dantysk', 8, 'global_optimizer') 97072.5662850161\n",
"('dantysk', 9, 'global_optimizer') 92475.3988276232\n",
"('dantysk', 10, 'global_optimizer') 88952.72298602328\n",
"('dantysk', 11, 'global_optimizer') 84861.28342989853\n",
"('dantysk', 12, 'global_optimizer') 81738.84210431519\n",
"('dantysk', 13, 'global_optimizer') 79813.65633309666\n",
"('dantysk', 14, 'global_optimizer') 76909.60581391084\n",
"('dantysk', 15, 'global_optimizer') 76516.82497873653\n",
"('horns', 3, 'global_optimizer') 114842.47426147909\n",
"('horns', 4, 'global_optimizer') 92186.60718333787\n",
"('horns', 5, 'global_optimizer') 79828.4366963156\n",
"('horns', 6, 'global_optimizer') 70608.30322850394\n",
"('horns', 7, 'global_optimizer') 64103.554765415436\n",
"('horns', 8, 'global_optimizer') 59003.343585534516\n",
"('horns', 9, 'global_optimizer') 55976.13421886173\n",
"('horns', 10, 'global_optimizer') 53410.53765921339\n",
"('horns', 11, 'global_optimizer') 53048.65219744707\n",
"('horns', 12, 'global_optimizer') 50830.62670976542\n",
"('horns', 13, 'global_optimizer') 50281.22439480547\n",
"('horns', 14, 'global_optimizer') 49151.833684431\n",
"('horns', 15, 'global_optimizer') 49028.77324477393\n",
"('thanet', 3, 'global_optimizer') 102067.59439020033\n",
"('thanet', 4, 'global_optimizer') 83379.53051809293\n",
"('thanet', 5, 'global_optimizer') 72952.83343753527\n",
"('thanet', 6, 'global_optimizer') 66434.23934955901\n",
"('thanet', 7, 'global_optimizer') 61454.790693540715\n",
"('thanet', 8, 'global_optimizer') 58072.80219849351\n",
"('thanet', 9, 'global_optimizer') 55632.41817377201\n",
"('thanet', 10, 'global_optimizer') 53604.9204210903\n",
"('thanet', 11, 'global_optimizer') 52935.0469647424\n",
"('thanet', 12, 'global_optimizer') 52519.5723244418\n",
"('thanet', 13, 'global_optimizer') 52282.26732291174\n",
"('thanet', 14, 'global_optimizer') 51626.11768783746\n",
"('thanet', 15, 'global_optimizer') 51172.45741670388\n",
"('sands', 3, 'global_optimizer') 172952.6188869118\n",
"('sands', 4, 'global_optimizer') 141460.61072459244\n",
"('sands', 5, 'global_optimizer') 122476.62244061175\n",
"('sands', 6, 'global_optimizer') 110983.14147307574\n",
"('sands', 7, 'global_optimizer') 103171.00610692591\n",
"('sands', 8, 'global_optimizer') 98437.45024262191\n",
"('sands', 9, 'global_optimizer') 94451.19707146697\n",
"('sands', 10, 'global_optimizer') 91457.25135532257\n",
"('sands', 11, 'global_optimizer') 88469.51895972031\n",
"('sands', 12, 'global_optimizer') 86681.12424763002\n",
"('sands', 13, 'global_optimizer') 85176.76772892375\n",
"('sands', 14, 'global_optimizer') 83223.59901516212\n",
"('sands', 15, 'global_optimizer') 82324.85351264001\n",
"('anholt', 3, 'global_optimizer') 307601.80897840013\n",
"('anholt', 4, 'global_optimizer') 243877.9157801405\n",
"('anholt', 5, 'global_optimizer') 206265.11081878003\n",
"('anholt', 6, 'global_optimizer') 179735.23789478844\n",
"('anholt', 7, 'global_optimizer') 162568.48904861844\n",
"('anholt', 8, 'global_optimizer') 147645.0805647098\n",
"('anholt', 9, 'global_optimizer') 138261.72441922815\n",
"('anholt', 10, 'global_optimizer') 130097.51022406039\n",
"('anholt', 11, 'global_optimizer') 122180.8378072613\n",
"('anholt', 12, 'global_optimizer') 118563.72956328407\n",
"('anholt', 13, 'global_optimizer') 113833.91835451077\n",
"('anholt', 14, 'global_optimizer') 109626.84326015905\n",
"('anholt', 15, 'global_optimizer') 108125.04204062361\n",
"('tess', 3, 'global_optimizer') 186886.02338171666\n",
"('tess', 4, 'global_optimizer') 156969.81104506835\n",
"('tess', 5, 'global_optimizer') 139734.5976706505\n",
"('tess', 6, 'global_optimizer') 129458.15141623422\n",
"('tess', 7, 'global_optimizer') 125185.3078497028\n",
"('tess', 8, 'global_optimizer') 121802.42817771433\n",
"('tess', 9, 'global_optimizer') 119283.33979264004\n",
"('tess', 10, 'global_optimizer') 118023.72038947423\n",
"('tess', 11, 'global_optimizer') 116942.07457303673\n",
"('tess', 12, 'global_optimizer') 115860.40631070288\n",
"('tess', 13, 'global_optimizer') 115778.73745447413\n",
"('tess', 14, 'global_optimizer') 114778.75672959436\n",
"('tess', 15, 'global_optimizer') 114251.24384624511\n",
"('london', 3, 'global_optimizer') 273692.07420971623\n",
"('london', 4, 'global_optimizer') 225450.88061668695\n",
"('london', 5, 'global_optimizer') 195552.13374809423\n",
"('london', 6, 'global_optimizer') 178137.77587870634\n",
"('london', 7, 'global_optimizer') 166836.08976842053\n",
"('london', 8, 'global_optimizer') 156600.64395518746\n",
"('london', 9, 'global_optimizer') 150561.5961252862\n",
"('london', 10, 'global_optimizer') 143869.12719558683\n",
"('london', 11, 'global_optimizer') 140641.09868662452\n",
"('london', 12, 'global_optimizer') 137570.67701081812\n",
"('london', 13, 'global_optimizer') 137730.35823912258\n",
"('london', 14, 'global_optimizer') 133542.84353291648\n",
"('london', 15, 'global_optimizer') 135257.49448724478\n",
"('tess3', 3, 'global_optimizer') 362392.4229015522\n",
"('tess3', 4, 'global_optimizer') 306837.1517530203\n",
"('tess3', 5, 'global_optimizer') 275707.70952610986\n",
"('tess3', 6, 'global_optimizer') 260145.915885964\n",
"('tess3', 7, 'global_optimizer') 254498.86815371612\n",
"('tess3', 8, 'global_optimizer') 247119.33918442467\n",
"('tess3', 9, 'global_optimizer') 244211.01081018447\n",
"('tess3', 10, 'global_optimizer') 242302.63827966966\n",
"('tess3', 11, 'global_optimizer') 241070.63252210253\n",
"('tess3', 12, 'global_optimizer') 240102.00313237103\n",
"('tess3', 13, 'global_optimizer') 241101.99428584546\n",
"('tess3', 14, 'global_optimizer') 239865.4727318498\n",
"('tess3', 15, 'global_optimizer') 239865.3461584033\n",
"('rbn', 3, 'MILP') 33266.36371548993\n",
"('rbn', 4, 'MILP') 29860.204861551734\n",
"('rbn', 5, 'MILP') 28391.588592928623\n",
"('rbn', 6, 'MILP') 27551.248664223054\n",
"('rbn', 7, 'MILP') 27168.2535875646\n",
"('rbn', 8, 'MILP') 26552.257544399687\n",
"('rbn', 9, 'MILP') 26552.23142749388\n",
"('rbn', 10, 'MILP') 26201.089322215314\n",
"('rbn', 11, 'MILP') 26156.76489956474\n",
"('rbn', 12, 'MILP') 26156.76420160615\n",
"('rbn', 13, 'MILP') 25805.619927854998\n",
"('ormonde', 3, 'MILP') 28468.75482702624\n",
"('ormonde', 4, 'MILP') 23857.474053100257\n",
"('ormonde', 5, 'MILP') 21276.36757136436\n",
"('ormonde', 6, 'MILP') 19474.12162862974\n",
"('ormonde', 7, 'MILP') 18039.395753991095\n",
"('ormonde', 8, 'MILP') 16921.93611519869\n",
"('ormonde', 9, 'MILP') 16921.93611519869\n",
"('ormonde', 10, 'MILP') 16921.93611519869\n",
"('ormonde', 11, 'MILP') 16730.024237975187\n",
"('ormonde', 12, 'MILP') 16694.362130485166\n",
"('ormonde', 13, 'MILP') 16694.362130485166\n",
"('ormonde', 14, 'MILP') 16694.362130485166\n",
"('ormonde', 15, 'MILP') 16408.416545612094\n",
"('rbs', 3, 'MILP') 110902.33921821232\n",
"('rbs', 4, 'MILP') 96489.50490846757\n",
"('rbs', 5, 'MILP') 88462.09862949734\n",
"('rbs', 6, 'MILP') 83608.44233166556\n",
"('rbs', 7, 'MILP') 81132.15038929948\n",
"('rbs', 8, 'MILP') 79779.66991858807\n",
"('rbs', 9, 'MILP') 78342.92156404235\n",
"('rbs', 10, 'MILP') 77576.12125079533\n",
"('rbs', 11, 'MILP') 76752.00687240942\n",
"('rbs', 12, 'MILP') 76235.9774658932\n",
"('rbs', 13, 'MILP') 75934.45757235313\n",
"('rbs', 14, 'MILP') 75684.76718464145\n",
"('rbs', 15, 'MILP') 75684.76574816529\n",
"('dantysk', 3, 'MILP') 183828.57515589587\n",
"('dantysk', 4, 'MILP') 148767.30533416467\n",
"('dantysk', 5, 'MILP') 127925.05054530728\n",
"('dantysk', 6, 'MILP') 113450.59849386492\n",
"('dantysk', 7, 'MILP') 104050.23450286816\n",
"('dantysk', 8, 'MILP') 96997.71300844806\n",
"('dantysk', 9, 'MILP') 92433.19918314437\n",
"('dantysk', 10, 'MILP') 88245.91837868161\n",
"('dantysk', 11, 'MILP') 84804.05437119018\n",
"('dantysk', 12, 'MILP') 81545.88644903792\n",
"('dantysk', 13, 'MILP') 79248.97831538455\n",
"('dantysk', 14, 'MILP') 76875.24994486028\n",
"('dantysk', 15, 'MILP') 76425.01648507122\n",
"('horns', 3, 'MILP') 114135.23903799473\n",
"('horns', 4, 'MILP') 91430.7470537994\n",
"('horns', 5, 'MILP') 79298.7577318621\n",
"('horns', 6, 'MILP') 70483.52870416982\n",
"('horns', 7, 'MILP') 64067.0520781751\n",
"('horns', 8, 'MILP') 58884.66672358922\n",
"('horns', 9, 'MILP') 55928.08103681947\n",
"('horns', 10, 'MILP') 53322.23018440208\n",
"('horns', 11, 'MILP') 52862.54053053543\n",
"('horns', 12, 'MILP') 50866.643435902406\n",
"('horns', 13, 'MILP') 50283.19009713246\n",
"('horns', 14, 'MILP') 49027.6426352129\n",
"('horns', 15, 'MILP') 49028.06565600351\n",
"('thanet', 3, 'MILP') 99743.37885680527\n",
"('thanet', 4, 'MILP') 82626.23761831594\n",
"('thanet', 5, 'MILP') 72359.70992142372\n",
"('thanet', 6, 'MILP') 65930.14790575013\n",
"('thanet', 7, 'MILP') 61504.0323170166\n",
"('thanet', 8, 'MILP') 58024.89002746611\n",
"('thanet', 9, 'MILP') 55454.90538854051\n",
"('thanet', 10, 'MILP') 53493.64385257402\n",
"('thanet', 11, 'MILP') 52854.72835292261\n",
"('thanet', 12, 'MILP') 52515.405574957396\n",
"('thanet', 13, 'MILP') 51862.64712074536\n",
"('thanet', 14, 'MILP') 51624.265800852416\n",
"('thanet', 15, 'MILP') 51159.83126677292\n",
"('sands', 3, 'MILP') 171522.54983954018\n",
"('sands', 4, 'MILP') 140796.20242514837\n",
"('sands', 5, 'MILP') 121889.14290338813\n",
"('sands', 6, 'MILP') 110405.63024608347\n",
"('sands', 7, 'MILP') 103085.02144206477\n",
"('sands', 8, 'MILP') 97875.32129300473\n",
"('sands', 9, 'MILP') 93822.85401656787\n",
"('sands', 10, 'MILP') 90722.38586933207\n",
"('sands', 11, 'MILP') 88657.34055081209\n",
"('sands', 12, 'MILP') 86277.54368427079\n",
"('sands', 13, 'MILP') 85003.89230321214\n",
"('sands', 14, 'MILP') 83211.52829881277\n",
"('sands', 15, 'MILP') 82149.87665908411\n",
"('anholt', 3, 'MILP') 300639.1427423917\n",
"('anholt', 4, 'MILP') 240130.73344383217\n",
"('anholt', 5, 'MILP') 202978.28824163205\n",
"('anholt', 6, 'MILP') 178293.27077721423\n",
"('anholt', 7, 'MILP') 160444.70000917363\n",
"('anholt', 8, 'MILP') 146734.81319304628\n",
"('anholt', 9, 'MILP') 139011.23328317754\n",
"('anholt', 10, 'MILP') 130019.40149400773\n",
"('anholt', 11, 'MILP') 122371.00453172733\n",
"('anholt', 12, 'MILP') 117808.84297279986\n",
"('anholt', 13, 'MILP') 113332.92557026623\n",
"('anholt', 14, 'MILP') 109665.57303570553\n",
"('anholt', 15, 'MILP') 108111.31851484787\n",
"('tess', 3, 'MILP') 186198.53958616164\n",
"('tess', 4, 'MILP') 155809.8463116733\n",
"('tess', 5, 'MILP') 139394.3765547251\n",
"('tess', 6, 'MILP') 129458.16599251606\n",
"('tess', 7, 'MILP') 124770.88397191273\n",
"('tess', 8, 'MILP') 121802.47776368656\n",
"('tess', 9, 'MILP') 119283.31769569566\n",
"('tess', 10, 'MILP') 118023.72807192127\n",
"('tess', 11, 'MILP') 116942.0583395688\n",
"('tess', 12, 'MILP') 115860.41130221337\n",
"('tess', 13, 'MILP') 114778.73263117071\n",
"('tess', 14, 'MILP') 114778.7359845226\n",
"('tess', 15, 'MILP') 114251.2244999111\n",
"('london', 3, 'MILP') 269312.4251166492\n",
"('london', 4, 'MILP') 222515.34310332066\n",
"('london', 5, 'MILP') 194018.68429151856\n",
"('london', 6, 'MILP') 177414.05766684632\n",
"('london', 7, 'MILP') 165754.2212189447\n",
"('london', 8, 'MILP') 156194.69277115766\n",
"('london', 9, 'MILP') 149734.5493588601\n",
"('london', 10, 'MILP') 143835.04216111975\n",
"('london', 11, 'MILP') 140271.64771892317\n",
"('london', 12, 'MILP') 137387.45485098675\n",
"('london', 13, 'MILP') 136027.17574108153\n",
"('london', 14, 'MILP') 132234.81972404307\n",
"('london', 15, 'MILP') 130009.69988158008\n",
"('tess3', 3, 'MILP') 358098.38768541877\n",
"('tess3', 4, 'MILP') 304387.5213575615\n",
"('tess3', 5, 'MILP') 273742.07777123415\n",
"('tess3', 6, 'MILP') 258234.37143086415\n",
"('tess3', 7, 'MILP') 251784.56995000975\n",
"('tess3', 8, 'MILP') 246387.25213710437\n",
"('tess3', 9, 'MILP') 243478.94111512793\n",
"('tess3', 10, 'MILP') 241570.61751547427\n",
"('tess3', 11, 'MILP') 240424.89920448486\n",
"('tess3', 12, 'MILP') 240102.00215962718\n",
"('tess3', 13, 'MILP') 239456.19478320668\n",
"('tess3', 14, 'MILP') 239456.2253206955\n",
"('tess3', 15, 'MILP') 239133.26242696456\n"
]
}
],
"source": [
"with database_connection(DB_FILE):\n",
" for method_idx in solverAx:\n",
" for rs in RouteSet.select().where(\n",
" RouteSet.creator.startswith(method_idx)\n",
" ):\n",
" idx = (rs.handle, rs.capacity, method_idx)\n",
" print(idx, rs.length)\n",
" optima.length.loc[idx] = rs.length\n",
" G = G_from_routeset(rs)\n",
" optima.graph.loc[idx].values.__setitem__((), G)\n",
" optima.runtime.loc[idx] = rs.runtime"
]
},
{
"cell_type": "markdown",
"id": "a1759132-8f30-4047-ab7b-253399738606",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"### runtime"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ba61e429-cd7c-44f7-88b1-fa698fc73df4",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, axs = plt.subplots(1, len(solverAx))\n",
"fig.suptitle('Time (h) to reach gap (clipped at 3 h)')\n",
"for solver, ax in zip(solverAx, axs):\n",
" img = ax.pcolormesh(\n",
" np.clip(optima.runtime.sel(solver=solver).values.T, 0, 10800)/3600,\n",
" )\n",
" ax.tick_params(top=False, labeltop=False, bottom=True, labelbottom=True)\n",
" ax.set_aspect('equal')\n",
" ax.set_xlabel('site')\n",
" ax.set_xticks(range(len(optima.handle)), optima.handle.data, rotation='vertical')\n",
" ax.set_ylabel(r'$\\kappa$')\n",
" ax.set_yticks(np.arange(len(optima.capacity)) + 0.5, range(*capacityLim))\n",
" divider = make_axes_locatable(ax)\n",
" # cax = divider.append_axes(\"top\", size=\"5%\", pad=0.05)\n",
" # plt.colorbar(img, cax=cax, orientation='horizontal', location='top')\n",
" # cax.set_title(Title[i])\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(img, cax=cax, orientation='vertical')\n",
" ax.set_title(solver)\n",
" ax.grid(False)"
]
},
{
"cell_type": "markdown",
"id": "b26a34b0-795d-4b95-8403-e6fdeff5d403",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"### total length"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "862b9b21-fcc8-4ed3-a9a5-85524685b9d8",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"reference = optima.length.sel(solver='MILP').values.T\n",
"fig, axs = plt.subplots(1, len(solverAx) - 1)\n",
"if len(solverAx) == 2:\n",
" axs = [axs]\n",
"divnorm=plt.cm.colors.TwoSlopeNorm(vmin=0.94, vcenter=1., vmax=1.06)\n",
"for solver, ax in zip(['global_optimizer'], axs):\n",
" img = ax.pcolormesh(\n",
" optima.length.sel(solver=solver).values.T/reference,\n",
" cmap=plt.cm.seismic,\n",
" norm=divnorm,\n",
" )\n",
" ax.tick_params(top=False, labeltop=False, bottom=True, labelbottom=True)\n",
" ax.set_aspect('equal')\n",
" ax.set_xlabel('site')\n",
" ax.set_xticks(np.arange(len(optima.handle)) + 0.5, optima.handle.data, rotation='vertical')\n",
" ax.set_ylabel(r'$\\kappa$')\n",
" ax.set_yticks(np.arange(len(optima.capacity)) + 0.5, range(*capacityLim))\n",
" divider = make_axes_locatable(ax)\n",
" # cax = divider.append_axes(\"top\", size=\"5%\", pad=0.05)\n",
" # plt.colorbar(img, cax=cax, orientation='horizontal', location='top')\n",
" # cax.set_title(Title[i])\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(img, cax=cax, orientation='vertical',\n",
" boundaries=np.linspace(0.97, 1.03, 13),\n",
" )\n",
" ax.set_title(solver)\n",
" ax.grid(False)"
]
},
{
"cell_type": "markdown",
"id": "eaed4df5-3f54-4198-be0f-4cf8243cb5df",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Instances where Perez-Rua 2020 is shorter than our B&C result"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "21c6de9d-9a3f-460c-9c37-21193574b34b",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"['global_optimizer', 'MILP']"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"solverAx"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "bf359958-1c1b-4f48-a261-6b0e81c101f9",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | capacity | \n",
" 3 | \n",
" 4 | \n",
" 5 | \n",
" 6 | \n",
" 7 | \n",
" 8 | \n",
" 9 | \n",
" 10 | \n",
" 11 | \n",
" 12 | \n",
" 13 | \n",
" 14 | \n",
" 15 | \n",
"
\n",
" \n",
" | handle | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | rbn | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | ormonde | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | rbs | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | dantysk | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | horns | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" True | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | thanet | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" True | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | sands | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" True | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | anholt | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" True | \n",
" False | \n",
" True | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | tess | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | london | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
" | tess3 | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
" False | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
"capacity 3 4 5 6 7 8 9 10 11 \\\n",
"handle \n",
"rbn False False False False False False False False False \n",
"ormonde False False False False False False False False False \n",
"rbs False False False False False False False False False \n",
"dantysk False False False False False False False False False \n",
"horns False False False False False False False False False \n",
"thanet False False False False True False False False False \n",
"sands False False False False False False False False True \n",
"anholt False False False False False False True False True \n",
"tess False False False False False False False False False \n",
"london False False False False False False False False False \n",
"tess3 False False False False False False False False False \n",
"\n",
"capacity 12 13 14 15 \n",
"handle \n",
"rbn False False False False \n",
"ormonde False False False False \n",
"rbs False False False False \n",
"dantysk False False False False \n",
"horns True False False False \n",
"thanet False False False False \n",
"sands False False False False \n",
"anholt False False False False \n",
"tess False False False False \n",
"london False False False False \n",
"tess3 False False False False "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"juru_is_better = ((optima.length[:,:, 0]/optima.length[:,:, 1] - 1) < -5e-4)\n",
"juru_is_better.to_pandas()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "2d7a74fd-55b3-4804-ae27-0921f36c6c04",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"juru_is_better.sum().item()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "059981d7-9762-44f0-98c7-583a545453a9",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"(-0.038798549578038966, 0.0054209425428310976)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merit = optima.length[:,:, 1]/optima.length[:,:, 0] - 1\n",
"merit.min().item(), merit.max().item()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "8c97e1e7-e0db-4e3b-8386-560ec20a2efe",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[4, 9],\n",
" [5, 4],\n",
" [6, 8],\n",
" [7, 6],\n",
" [7, 8]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"juru_idx = np.argwhere(juru_is_better.data)\n",
"juru_idx"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "66659402-3baa-4f3c-a609-d8d1e1782896",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"50831 -> 50867 (MILP) +0.07% horns, κ = 12, num_rogues = 0\n",
"61455 -> 61504 (MILP) +0.08% thanet, κ = 7, num_rogues = 0\n",
"88470 -> 88657 (MILP) +0.21% sands, κ = 11, num_rogues = 0\n",
"138262 -> 139011 (MILP) +0.54% anholt, κ = 9, num_rogues = 2\n",
"122181 -> 122371 (MILP) +0.16% anholt, κ = 11, num_rogues = 2\n"
]
}
],
"source": [
"for handle_idx, κ_idx in juru_idx:\n",
" length_juru = optima.length[handle_idx, κ_idx, 0].item()\n",
" solver_idx = 1\n",
" length_contestant = optima.length[handle_idx, κ_idx, solver_idx].item()\n",
" G = optima.graph[handle_idx, κ_idx, 0].item()\n",
" for _, _, r in G.edges(data=\"rogue\"):\n",
" if r is not None:\n",
" print(handle_idx, κ_idx)\n",
" num_rogues = sum(1 for _, _, kind in G.edges(data='kind') if kind == 'rogue')\n",
" print(f'{length_juru:.0f} -> {length_contestant:.0f} '\n",
" f'({solverAx[solver_idx]}) '\n",
" f'{100*(length_contestant/length_juru - 1):+.2f}% '\n",
" f'{handleAx[handle_idx]}, κ = {κ_idx + 3}, '\n",
" f'num_rogues = {num_rogues}')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "70e20eee-1f52-411a-bad5-1a550818b839",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"141"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"num_instances = (optima.length[:,:, 0].size - optima.length[:,:, 0].isnull().sum()).item()\n",
"num_instances"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "7f7cb4a5-df84-498b-b4e8-8f67668f76bf",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"text/plain": [
"-0.0024347664901663846"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merit.median().item()"
]
},
{
"cell_type": "markdown",
"id": "a510d8ee-6970-496d-a7e8-e2b251cb6b34",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Create quality comparison plots"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "4aaa19b8-068f-4d3e-a293-f4832131e42b",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with plt.style.context('pdf_1col'):\n",
" fig, ax = plt.subplots(facecolor='w')\n",
" divnorm=plt.cm.colors.TwoSlopeNorm(vmin=-4, vcenter=0., vmax=4)\n",
" img = ax.pcolormesh(100*merit, cmap=plt.cm.seismic, norm=divnorm)\n",
" ax.tick_params(top=False, labeltop=False, bottom=True, labelbottom=True)\n",
" ax.set_ylabel('Site')\n",
" ax.set_yticks(np.arange(len(optima.handle)) + 0.5, optima.handle.data)\n",
" ax.set_xlabel('Capacity')\n",
" ax.set_xticks(np.arange(len(optima.capacity)) + 0.5, range(*capacityLim))\n",
" divider = make_axes_locatable(ax)\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(img, cax=cax, orientation='vertical',\n",
" boundaries=np.linspace(-4, 1, 11),\n",
" )\n",
" cax.set_ylabel('Length change (%)')\n",
" ax.scatter(*(juru_idx.T[::-1] + 0.5), marker='s',\n",
" facecolor='none', color='darkorange', s=140)\n",
" ax.set_aspect('equal')\n",
" ax.grid(False)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "41155f95-7a91-4fca-86a3-32131db08565",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with plt.style.context('pdf_1col'):\n",
" fig, ax = plt.subplots(facecolor='w')\n",
" hist = ax.hist((100*merit.data).flat, orientation='horizontal', bins=np.linspace(-4, 1, 69),\n",
" edgecolor='none');\n",
" median = 100*merit.median().item()\n",
" ax.axhline(median, *ax.get_xlim(), color='k', ls=':', lw=0.5,\n",
" label=f'median: {median:.2f}%')\n",
" ax.legend(loc='lower right')\n",
" ax.set_ylabel('Length change (%)')\n",
" ax.set_xlabel('Number of instances')"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "d82a1039-fb66-4fe0-8dcc-5aa919607a97",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with plt.style.context('pdf_2col'):\n",
" fig, (ax, ax2) = plt.subplots(1, 2, facecolor='w', gridspec_kw={'wspace': 0.1})\n",
" divnorm = plt.cm.colors.TwoSlopeNorm(vmin=-4, vcenter=0., vmax=4)\n",
" img = ax.pcolormesh(100*merit, cmap=plt.cm.seismic, norm=divnorm)\n",
" ax.tick_params(top=False, labeltop=False, bottom=True, labelbottom=True)\n",
" ax.set_ylabel('Site')\n",
" ax.set_yticks(np.arange(len(optima.handle)) + 0.5, optima.handle.data)\n",
" ax.set_xlabel('Capacity')\n",
" ax.set_xticks(np.arange(len(optima.capacity)) + 0.5, range(*capacityLim))\n",
" divider = make_axes_locatable(ax)\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(img, cax=cax, orientation='vertical',\n",
" boundaries=np.linspace(-4, 1, 11))\n",
" ax.scatter(*(juru_idx.T[::-1] + 0.5), marker='s',\n",
" facecolor='none', color='darkorange', s=140)\n",
" ax.set_aspect('equal')\n",
" ax.grid(False)\n",
"\n",
" hist = ax2.hist((100*merit.data).flat, orientation='horizontal', bins=np.linspace(-4, 1, 69),\n",
" edgecolor='none');\n",
" median = 100*merit.median().item()\n",
" ax2.axhline(median, *ax.get_xlim(), color='k', ls=':', lw=0.5,\n",
" label=f'median: {median:.2f}%')\n",
" ax2.legend(loc='lower right', fontsize='small')\n",
" ax2.set_ylabel('Length difference (%)')\n",
" ax2.set_xlabel('Number of instances')\n",
" ax2.set_ylim(-4, 1)\n",
" fig.savefig('quality_comparison.pdf')"
]
},
{
"cell_type": "markdown",
"id": "4165f558-3cb9-440c-a156-47d1b6826ae8",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"source": [
"## Plot the instance with the highest positive difference"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "0c482f5b-7e8e-457a-902b-bdb0544c6100",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.18, 1.95\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with plt.style.context('pdf_1col'):\n",
" G = optima.graph.loc['anholt', 9, 'global_optimizer'].item()\n",
" ax = gplot(G, infobox=False, legend=False, dark=False, figsize=(4.2, 50))\n",
" ax.figure.canvas.draw()\n",
" bbox = ax.get_window_extent().transformed(ax.figure.dpi_scale_trans.inverted())\n",
" print(f'{bbox.width:.2f}, {bbox.height:.2f}')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "92cf3882-f920-41ce-a91b-c6a3ec643fb6",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"ax.figure.savefig('anholt_9_ref.pdf', pad_inches=0., transparent=True)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "8a15fd86-3620-4032-8c86-941965ea2d26",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.18, 1.95\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with plt.style.context('pdf_1col'):\n",
" G = optima.graph.loc['anholt', 9, 'MILP'].item()\n",
" ax = gplot(G, infobox=False, legend=False, dark=False, figsize=(4.2, 2.2))\n",
" ax.figure.canvas.draw()\n",
" bbox = ax.get_window_extent().transformed(ax.figure.dpi_scale_trans.inverted())\n",
" print(f'{bbox.width:.2f}, {bbox.height:.2f}')"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "b90c0012-eff2-4376-9214-901a0b2dcd37",
"metadata": {
"deletable": true,
"editable": true,
"frozen": false
},
"outputs": [],
"source": [
"ax.figure.savefig('anholt_9_our.pdf', pad_inches=0., transparent=True)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}