{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import FINE as fn\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Water supply of a small mountain village\n",
    "\n",
    "Two new houses (house 5 and 6) were built in a small mountain village in Utopia which requires an update of the existing clean water supply system of the village which now consists of 6 houses:\n",
    "\n",
    "<img src=\"MountainVillage.png\" style=\"width: 500px;\"/>\n",
    "\n",
    "\n",
    "### Water demand\n",
    "The demand for clean water occurs in spring between 5 am and 11 pm, in summer between 4 am and 12 pm, in autumn between 5 am and 11 pm and in winter between 6 am and 11 pm. The demand for one house assumes random values between 0 to 1 Uh (Unit*hour) during the demand hours. These values are uniformly distributed and are 0 outside the demand hours.\n",
    "\n",
    "### Water supply \n",
    "The water supply comes from a small tributary of a glacier river, which provides more water in summer and less in winter: the profile is given for each hour of the year as\n",
    "\n",
    "f(t) = 8 \\* sin(π*t/8760) + g(t)    \n",
    "    \n",
    "where g(t) is a uniformly distributed random value between 0 and 4.\n",
    "\n",
    "### Water storage\n",
    "Clean water can be stored in a water tank (newly purchased). The invest per capacity is 100€/Uh, the economic lifetime is 20 years.\n",
    "\n",
    "### Water treatment\n",
    "The river water is converted to clean water in a water treatment plant (newly purchased). The invest per capacity is 7000€/U, the economic lifetime is 20 years. Further, it needs some electricity wherefore it has operational cost of 0.05 €/U.\n",
    "\n",
    "### Water transmission\n",
    "The clean water can be transported via water pipes, where some already exist between the houses 1-4, the water treatment plant and the\u000b",
    "water tank, however new ones might need to\u000b",
    "be built to connect the newly built houses or reinforce the transmission along the old pipes. The invest for new pipes per capacity is 100 €/(m\\*U), the invest if a new pipe route is built is 500 €/(m\\*U), the economic lifetime is 20 years.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "locations = ['House 1', 'House 2', 'House 3', 'House 4', 'House 5', 'House 6',\n",
    "             'Node 1', 'Node 2', 'Node 3', 'Node 4', 'Water treatment', 'Water tank']\n",
    "commodityUnitDict = {'clean water': 'U', 'river water': 'U'}\n",
    "commodities = {'clean water', 'river water'}\n",
    "numberOfTimeSteps=8760\n",
    "hoursPerTimeStep=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM = fn.EnergySystemModel(locations=set(locations), commodities=commodities, numberOfTimeSteps=8760,\n",
    "                           commodityUnitsDict=commodityUnitDict,\n",
    "                           hoursPerTimeStep=1, costUnit='1e3 Euro', lengthUnit='m')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "riverFlow = pd.DataFrame(np.zeros((8760,12)), columns=locations)\n",
    "np.random.seed(42)\n",
    "riverFlow.loc[:,'Water treatment'] = np.random.uniform(0,4,(8760))+8*np.sin(np.pi*np.arange(8760)/8760)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='River', commodity='river water', hasCapacityVariable=False,\n",
    "                  operationRateMax=riverFlow, opexPerOperation = 0.05))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Conversion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "eligibility = pd.Series([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], index=locations)\n",
    "esM.add(fn.Conversion(esM=esM, name='Water treatment plant', physicalUnit='U',\n",
    "                      commodityConversionFactors={'river water':-1, 'clean water':1}, \n",
    "                      hasCapacityVariable=True, locationalEligibility=eligibility,\n",
    "                      investPerCapacity=7, opexPerCapacity=0.02*7, interestRate=0.08, economicLifetime=20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Storage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "eligibility = pd.Series([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], index=locations)\n",
    "esM.add(fn.Storage(esM=esM, name='Water tank', commodity='clean water', hasCapacityVariable=True, \n",
    "                   chargeRate=1/24, dischargeRate=1/24, locationalEligibility=eligibility,\n",
    "                   investPerCapacity=0.10, opexPerCapacity=0.02*0.1, interestRate=0.08, economicLifetime=20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Distances between eligible regions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water treatment</th>\n",
       "      <th>Water tank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>House 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 5</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 6</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>105</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>105</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 3</th>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water treatment</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water tank</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 House 1  House 2  House 3  House 4  House 5  House 6  Node 1  \\\n",
       "House 1                0        0        0        0        0        0       0   \n",
       "House 2                0        0        0        0        0        0       0   \n",
       "House 3                0        0        0        0        0        0       0   \n",
       "House 4                0        0        0        0        0        0       0   \n",
       "House 5                0        0        0        0        0        0      38   \n",
       "House 6                0        0        0        0        0        0      40   \n",
       "Node 1                 0        0        0        0       38       40       0   \n",
       "Node 2                 0        0       38       40        0        0     105   \n",
       "Node 3                38       40        0        0        0        0       0   \n",
       "Node 4                 0        0        0        0        0        0       0   \n",
       "Water treatment        0        0        0        0        0        0       0   \n",
       "Water tank             0        0        0        0        0        0       0   \n",
       "\n",
       "                 Node 2  Node 3  Node 4  Water treatment  Water tank  \n",
       "House 1               0      38       0                0           0  \n",
       "House 2               0      40       0                0           0  \n",
       "House 3              38       0       0                0           0  \n",
       "House 4              40       0       0                0           0  \n",
       "House 5               0       0       0                0           0  \n",
       "House 6               0       0       0                0           0  \n",
       "Node 1              105       0       0                0           0  \n",
       "Node 2                0     100       0                0           0  \n",
       "Node 3              100       0      30                0           0  \n",
       "Node 4                0      30       0               20          50  \n",
       "Water treatment       0       0      20                0           0  \n",
       "Water tank            0       0      50                0           0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 38, 40, 0, 105, 0, 0, 0, 0],\n",
    "                      [0, 0, 38, 40, 0, 0, 105, 0, 100, 0, 0, 0],\n",
    "                      [38, 40, 0, 0, 0, 0, 0, 100, 0, 30, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 20, 50],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0]])\n",
    "\n",
    "distances = pd.DataFrame(distances, index=locations, columns=locations)\n",
    "distances"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Old water pipes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water treatment</th>\n",
       "      <th>Water tank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>House 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 5</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 6</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water treatment</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water tank</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 House 1  House 2  House 3  House 4  House 5  House 6  Node 1  \\\n",
       "House 1                0        0        0        0        0        0       0   \n",
       "House 2                0        0        0        0        0        0       0   \n",
       "House 3                0        0        0        0        0        0       0   \n",
       "House 4                0        0        0        0        0        0       0   \n",
       "House 5                0        0        0        0        0        0       0   \n",
       "House 6                0        0        0        0        0        0       0   \n",
       "Node 1                 0        0        0        0        0        0       0   \n",
       "Node 2                 0        0        1        1        0        0       0   \n",
       "Node 3                 1        1        0        0        0        0       0   \n",
       "Node 4                 0        0        0        0        0        0       0   \n",
       "Water treatment        0        0        0        0        0        0       0   \n",
       "Water tank             0        0        0        0        0        0       0   \n",
       "\n",
       "                 Node 2  Node 3  Node 4  Water treatment  Water tank  \n",
       "House 1               0       1       0                0           0  \n",
       "House 2               0       1       0                0           0  \n",
       "House 3               1       0       0                0           0  \n",
       "House 4               1       0       0                0           0  \n",
       "House 5               0       0       0                0           0  \n",
       "House 6               0       0       0                0           0  \n",
       "Node 1                0       0       0                0           0  \n",
       "Node 2                0       2       0                0           0  \n",
       "Node 3                2       0       4                0           0  \n",
       "Node 4                0       4       0                4           4  \n",
       "Water treatment       0       0       4                0           0  \n",
       "Water tank            0       0       4                0           0  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "capacityFix = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
    "                        [0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0],\n",
    "                        [1, 1, 0, 0, 0, 0, 0, 2, 0, 4, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 4],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0],\n",
    "                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0]])\n",
    "\n",
    "capacityFix = pd.DataFrame(capacityFix, index=locations, columns=locations)\n",
    "capacityFix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The old pipes have many leckages wherefore they lose 0.1%/m of the water they transport."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "isBuiltFix = capacityFix.copy()\n",
    "isBuiltFix[isBuiltFix>0]=1\n",
    "\n",
    "esM.add(fn.Transmission(esM=esM, name='Old water pipes', commodity='clean water',\n",
    "                        losses = 0.1e-2,\n",
    "                        distances=distances, hasCapacityVariable=True, hasIsBuiltBinaryVariable=True, bigM=100,\n",
    "                        capacityFix=capacityFix, isBuiltFix=isBuiltFix))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## New water pipes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water treatment</th>\n",
       "      <th>Water tank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>House 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 5</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 6</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water treatment</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water tank</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 House 1  House 2  House 3  House 4  House 5  House 6  Node 1  \\\n",
       "House 1                0        0        0        0        0        0       0   \n",
       "House 2                0        0        0        0        0        0       0   \n",
       "House 3                0        0        0        0        0        0       0   \n",
       "House 4                0        0        0        0        0        0       0   \n",
       "House 5                0        0        0        0        0        0       1   \n",
       "House 6                0        0        0        0        0        0       1   \n",
       "Node 1                 0        0        0        0        1        1       0   \n",
       "Node 2                 0        0        1        1        0        0       1   \n",
       "Node 3                 1        1        0        0        0        0       0   \n",
       "Node 4                 0        0        0        0        0        0       0   \n",
       "Water treatment        0        0        0        0        0        0       0   \n",
       "Water tank             0        0        0        0        0        0       0   \n",
       "\n",
       "                 Node 2  Node 3  Node 4  Water treatment  Water tank  \n",
       "House 1               0       1       0                0           0  \n",
       "House 2               0       1       0                0           0  \n",
       "House 3               1       0       0                0           0  \n",
       "House 4               1       0       0                0           0  \n",
       "House 5               0       0       0                0           0  \n",
       "House 6               0       0       0                0           0  \n",
       "Node 1                1       0       0                0           0  \n",
       "Node 2                0       1       0                0           0  \n",
       "Node 3                1       0       1                0           0  \n",
       "Node 4                0       1       0                1           1  \n",
       "Water treatment       0       0       1                0           0  \n",
       "Water tank            0       0       1                0           0  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "incidence = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],\n",
    "                      [0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0],\n",
    "                      [0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0],\n",
    "                      [1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n",
    "                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]])\n",
    "\n",
    "eligibility = pd.DataFrame(incidence, index=locations, columns=locations)\n",
    "eligibility"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The new are pipes are better but still lose 0.05%/m of the water they transport."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Transmission(esM=esM, name='New water pipes', commodity='clean water',\n",
    "                        losses = 0.05e-2,\n",
    "                        distances=distances, hasCapacityVariable=True, hasIsBuiltBinaryVariable=True, bigM=100,\n",
    "                        locationalEligibility=eligibility,\n",
    "                        investPerCapacity=0.1, investIfBuilt=0.5, interestRate=0.08, economicLifetime=50))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sink"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "winterHours=np.append(range(8520,8760),range(1920))\n",
    "springHours, summerHours, autumnHours = np.arange(1920,4128), np.arange(4128,6384), np.arange(6384,8520)\n",
    "\n",
    "demand = pd.DataFrame(np.zeros((8760,12)), columns=list(locations))\n",
    "np.random.seed(42)\n",
    "demand[locations[0:6]] = np.random.uniform(0,1,(8760,6))\n",
    "\n",
    "demand.loc[winterHours[(winterHours%24 < 5) | (winterHours%24 >= 23)]] = 0\n",
    "demand.loc[springHours[(springHours%24 < 4)]] = 0\n",
    "demand.loc[summerHours[(summerHours%24 < 5) | (summerHours%24 >= 23)]] = 0\n",
    "demand.loc[autumnHours[(autumnHours%24 < 6) | (autumnHours%24 >= 23)]] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19955.41528977587"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "demand.sum().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Sink(esM=esM, name='Water demand', commodity='clean water', hasCapacityVariable=False,\n",
    "                  operationRateFix=demand))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Optimize the system"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Clustering time series data with 7 typical periods and 24 time steps per period...\n",
      "\t\t(1.3906 sec)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "esM.cluster(numberOfTypicalPeriods=7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time series aggregation specifications:\n",
      "Number of typical periods:7, number of time steps per periods:24\n",
      "\n",
      "Declaring sets, variables and constraints for SourceSinkModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.6250 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for ConversionModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.0156 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for StorageModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.0625 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for TransmissionModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.1875 sec)\n",
      "\n",
      "Declaring shared potential constraint...\n",
      "\t\t(0.0000 sec)\n",
      "\n",
      "Declaring commodity balances...\n",
      "\t\t(0.2969 sec)\n",
      "\n",
      "Declaring objective function...\n",
      "\t\t(0.0625 sec)\n",
      "\n",
      "Using license file C:\\Users\\t.gross\\gurobi.lic\n",
      "Academic license - for non-commercial use only\n",
      "Read LP format model from file C:\\Users\\T58C8~1.GRO\\AppData\\Local\\Temp\\tmpvq0lxvna.pyomo.lp\n",
      "Reading time = 0.05 seconds\n",
      "x8738: 12004 rows, 8738 columns, 40490 nonzeros\n",
      "Changed value of parameter QCPDual to 1\n",
      "   Prev: 0  Min: 0  Max: 1  Default: 0\n",
      "Changed value of parameter Threads to 3\n",
      "   Prev: 0  Min: 0  Max: 1024  Default: 0\n",
      "Parameter logfile unchanged\n",
      "   Value:   Default: \n",
      "Parameter LogToConsole unchanged\n",
      "   Value: 1  Min: 0  Max: 1  Default: 1\n",
      "Parameter OptimalityTol unchanged\n",
      "   Value: 1e-06  Min: 1e-09  Max: 0.01  Default: 1e-06\n",
      "Changed value of parameter crossover to 1\n",
      "   Prev: -1  Min: -1  Max: 5  Default: -1\n",
      "Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (win64)\n",
      "Optimize a model with 12004 rows, 8738 columns and 40490 nonzeros\n",
      "Model fingerprint: 0x3b382bf1\n",
      "Variable types: 8700 continuous, 38 integer (38 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [4e-02, 1e+02]\n",
      "  Objective range  [1e-02, 5e+00]\n",
      "  Bounds range     [1e+00, 1e+00]\n",
      "  RHS range        [1e-03, 1e+01]\n",
      "Presolve removed 5473 rows and 2056 columns\n",
      "Presolve time: 0.03s\n",
      "Presolved: 6531 rows, 6682 columns, 24177 nonzeros\n",
      "Variable types: 6679 continuous, 3 integer (3 binary)\n",
      "\n",
      "Root relaxation: objective 1.134009e+03, 3728 iterations, 0.23 seconds\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0 1134.00912    0    3          - 1134.00912      -     -    0s\n",
      "     0     0 1134.00912    0    3          - 1134.00912      -     -    0s\n",
      "     0     1 1134.00912    0    3          - 1134.00912      -     -    0s\n",
      "*    4     1               3    1148.3534875 1135.98827  1.08%   282    0s\n",
      "*    5     1               3    1137.5379578 1137.06770  0.04%   307    0s\n",
      "\n",
      "Explored 8 nodes (5377 simplex iterations) in 0.36 seconds\n",
      "Thread count was 3 (of 8 available processors)\n",
      "\n",
      "Solution count 2: 1137.54 1148.35 \n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 1.137537957813e+03, best bound 1.137537957813e+03, gap 0.0000%\n",
      "\n",
      "Status: ok\n",
      "Return code: 0\n",
      "Message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.\n",
      "Termination condition: optimal\n",
      "Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.\n",
      "Wall time: 0.3593482971191406\n",
      "Error rc: 0\n",
      "Time: 0.7343604564666748\n",
      "\n",
      "\n",
      "Name: x8738\n",
      "Lower bound: 1137.5379578127965\n",
      "Upper bound: 1137.5379578127965\n",
      "Number of objectives: 1\n",
      "Number of constraints: 12004\n",
      "Number of variables: 8738\n",
      "Number of binary variables: 38\n",
      "Number of integer variables: 38\n",
      "Number of continuous variables: 8700\n",
      "Number of nonzeros: 40490\n",
      "Sense: minimize\n",
      "\n",
      "Solve time: 1.1875040531158447 sec.\n",
      "\n",
      "Processing optimization output...\n",
      "for SourceSinkModel ...    (0.4218sec)\n",
      "for ConversionModel ...    (0.3438sec)\n",
      "for StorageModel ...       (1.4999sec)\n",
      "for TransmissionModel ...  (2.2271sec)\n",
      "\t\t(4.4927 sec)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "esM.optimize(timeSeriesAggregation=True, optimizationSpecs='LogToConsole=1 OptimalityTol=1e-6 crossover=1')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selected results output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sources and Sinks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water tank</th>\n",
       "      <th>Water treatment</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">River</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1104.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[U*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22097.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexOp</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1104.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water demand</th>\n",
       "      <th>operation</th>\n",
       "      <th>[U*h/a]</th>\n",
       "      <td>3329.49</td>\n",
       "      <td>3301.98</td>\n",
       "      <td>3316.75</td>\n",
       "      <td>3353.06</td>\n",
       "      <td>3321.53</td>\n",
       "      <td>3332.61</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     House 1  House 2  House 3  House 4  \\\n",
       "Component    Property  Unit                                               \n",
       "River        TAC       [1e3 Euro/a]        0        0        0        0   \n",
       "             operation [U*h/a]           NaN      NaN      NaN      NaN   \n",
       "             opexOp    [1e3 Euro/a]      NaN      NaN      NaN      NaN   \n",
       "Water demand operation [U*h/a]       3329.49  3301.98  3316.75  3353.06   \n",
       "\n",
       "                                     House 5  House 6 Node 1 Node 2 Node 3  \\\n",
       "Component    Property  Unit                                                  \n",
       "River        TAC       [1e3 Euro/a]        0        0      0      0      0   \n",
       "             operation [U*h/a]           NaN      NaN    NaN    NaN    NaN   \n",
       "             opexOp    [1e3 Euro/a]      NaN      NaN    NaN    NaN    NaN   \n",
       "Water demand operation [U*h/a]       3321.53  3332.61    NaN    NaN    NaN   \n",
       "\n",
       "                                    Node 4 Water tank Water treatment  \n",
       "Component    Property  Unit                                            \n",
       "River        TAC       [1e3 Euro/a]      0          0         1104.88  \n",
       "             operation [U*h/a]         NaN        NaN         22097.7  \n",
       "             opexOp    [1e3 Euro/a]    NaN        NaN         1104.88  \n",
       "Water demand operation [U*h/a]         NaN        NaN             NaN  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"SourceSinkModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Storage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water tank</th>\n",
       "      <th>Water treatment</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">Water tank</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.700925</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[U*h]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>57.5226</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.58588</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e3 Euro]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.75226</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationCharge</th>\n",
       "      <th>[U*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1071.92</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationDischarge</th>\n",
       "      <th>[U*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1071.92</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.115045</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           House 1 House 2 House 3 House 4  \\\n",
       "Component  Property           Unit                                           \n",
       "Water tank TAC                [1e3 Euro/a]       0       0       0       0   \n",
       "           capacity           [U*h]            NaN     NaN     NaN     NaN   \n",
       "           capexCap           [1e3 Euro/a]     NaN     NaN     NaN     NaN   \n",
       "           invest             [1e3 Euro]       NaN     NaN     NaN     NaN   \n",
       "           operationCharge    [U*h/a]          NaN     NaN     NaN     NaN   \n",
       "           operationDischarge [U*h/a]          NaN     NaN     NaN     NaN   \n",
       "           opexCap            [1e3 Euro/a]     NaN     NaN     NaN     NaN   \n",
       "\n",
       "                                           House 5 House 6 Node 1 Node 2  \\\n",
       "Component  Property           Unit                                         \n",
       "Water tank TAC                [1e3 Euro/a]       0       0      0      0   \n",
       "           capacity           [U*h]            NaN     NaN    NaN    NaN   \n",
       "           capexCap           [1e3 Euro/a]     NaN     NaN    NaN    NaN   \n",
       "           invest             [1e3 Euro]       NaN     NaN    NaN    NaN   \n",
       "           operationCharge    [U*h/a]          NaN     NaN    NaN    NaN   \n",
       "           operationDischarge [U*h/a]          NaN     NaN    NaN    NaN   \n",
       "           opexCap            [1e3 Euro/a]     NaN     NaN    NaN    NaN   \n",
       "\n",
       "                                           Node 3 Node 4 Water tank  \\\n",
       "Component  Property           Unit                                    \n",
       "Water tank TAC                [1e3 Euro/a]      0      0   0.700925   \n",
       "           capacity           [U*h]           NaN    NaN    57.5226   \n",
       "           capexCap           [1e3 Euro/a]    NaN    NaN    0.58588   \n",
       "           invest             [1e3 Euro]      NaN    NaN    5.75226   \n",
       "           operationCharge    [U*h/a]         NaN    NaN    1071.92   \n",
       "           operationDischarge [U*h/a]         NaN    NaN    1071.92   \n",
       "           opexCap            [1e3 Euro/a]    NaN    NaN   0.115045   \n",
       "\n",
       "                                           Water treatment  \n",
       "Component  Property           Unit                          \n",
       "Water tank TAC                [1e3 Euro/a]               0  \n",
       "           capacity           [U*h]                    NaN  \n",
       "           capexCap           [1e3 Euro/a]             NaN  \n",
       "           invest             [1e3 Euro]               NaN  \n",
       "           operationCharge    [U*h/a]                  NaN  \n",
       "           operationDischarge [U*h/a]                  NaN  \n",
       "           opexCap            [1e3 Euro/a]             NaN  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"StorageModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conversion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water tank</th>\n",
       "      <th>Water treatment</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">Water treatment plant</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4.1662</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[U]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.88437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.48238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e3 Euro]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>34.1906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[U*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22097.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e3 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.683811</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             House 1 House 2 House 3 House 4  \\\n",
       "Component             Property  Unit                                           \n",
       "Water treatment plant TAC       [1e3 Euro/a]       0       0       0       0   \n",
       "                      capacity  [U]              NaN     NaN     NaN     NaN   \n",
       "                      capexCap  [1e3 Euro/a]     NaN     NaN     NaN     NaN   \n",
       "                      invest    [1e3 Euro]       NaN     NaN     NaN     NaN   \n",
       "                      operation [U*h/a]          NaN     NaN     NaN     NaN   \n",
       "                      opexCap   [1e3 Euro/a]     NaN     NaN     NaN     NaN   \n",
       "\n",
       "                                             House 5 House 6 Node 1 Node 2  \\\n",
       "Component             Property  Unit                                         \n",
       "Water treatment plant TAC       [1e3 Euro/a]       0       0      0      0   \n",
       "                      capacity  [U]              NaN     NaN    NaN    NaN   \n",
       "                      capexCap  [1e3 Euro/a]     NaN     NaN    NaN    NaN   \n",
       "                      invest    [1e3 Euro]       NaN     NaN    NaN    NaN   \n",
       "                      operation [U*h/a]          NaN     NaN    NaN    NaN   \n",
       "                      opexCap   [1e3 Euro/a]     NaN     NaN    NaN    NaN   \n",
       "\n",
       "                                             Node 3 Node 4 Water tank  \\\n",
       "Component             Property  Unit                                    \n",
       "Water treatment plant TAC       [1e3 Euro/a]      0      0          0   \n",
       "                      capacity  [U]             NaN    NaN        NaN   \n",
       "                      capexCap  [1e3 Euro/a]    NaN    NaN        NaN   \n",
       "                      invest    [1e3 Euro]      NaN    NaN        NaN   \n",
       "                      operation [U*h/a]         NaN    NaN        NaN   \n",
       "                      opexCap   [1e3 Euro/a]    NaN    NaN        NaN   \n",
       "\n",
       "                                             Water treatment  \n",
       "Component             Property  Unit                          \n",
       "Water treatment plant TAC       [1e3 Euro/a]          4.1662  \n",
       "                      capacity  [U]                  4.88437  \n",
       "                      capexCap  [1e3 Euro/a]         3.48238  \n",
       "                      invest    [1e3 Euro]           34.1906  \n",
       "                      operation [U*h/a]              22097.7  \n",
       "                      opexCap   [1e3 Euro/a]        0.683811  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"ConversionModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Transmission"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>House 1</th>\n",
       "      <th>House 2</th>\n",
       "      <th>House 3</th>\n",
       "      <th>House 4</th>\n",
       "      <th>House 5</th>\n",
       "      <th>House 6</th>\n",
       "      <th>Node 1</th>\n",
       "      <th>Node 2</th>\n",
       "      <th>Node 3</th>\n",
       "      <th>Node 4</th>\n",
       "      <th>Water tank</th>\n",
       "      <th>Water treatment</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th>LocationIn</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">New water pipes</th>\n",
       "      <th rowspan=\"5\" valign=\"top\">TAC</th>\n",
       "      <th rowspan=\"5\" valign=\"top\">[1e3 Euro/a]</th>\n",
       "      <th>House 1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.776557</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.817429</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.776557</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.817429</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>House 5</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.776557</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Old water pipes</th>\n",
       "      <th rowspan=\"5\" valign=\"top\">operation</th>\n",
       "      <th rowspan=\"5\" valign=\"top\">[U*h/a]</th>\n",
       "      <th>Node 2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.2389</td>\n",
       "      <td>8.99169</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 3</th>\n",
       "      <td>7.50041</td>\n",
       "      <td>4.55491</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>93.6361</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Node 4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>148.693</td>\n",
       "      <td>NaN</td>\n",
       "      <td>792.787</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water tank</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>753.147</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Water treatment</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.785</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>72 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                        House 1  House 2  \\\n",
       "Component       Property  Unit         LocationIn                          \n",
       "New water pipes TAC       [1e3 Euro/a] House 1                0        0   \n",
       "                                       House 2                0        0   \n",
       "                                       House 3                0        0   \n",
       "                                       House 4                0        0   \n",
       "                                       House 5                0        0   \n",
       "...                                                         ...      ...   \n",
       "Old water pipes operation [U*h/a]      Node 2               NaN      NaN   \n",
       "                                       Node 3           7.50041  4.55491   \n",
       "                                       Node 4               NaN      NaN   \n",
       "                                       Water tank           NaN      NaN   \n",
       "                                       Water treatment      NaN      NaN   \n",
       "\n",
       "                                                       House 3  House 4  \\\n",
       "Component       Property  Unit         LocationIn                         \n",
       "New water pipes TAC       [1e3 Euro/a] House 1               0        0   \n",
       "                                       House 2               0        0   \n",
       "                                       House 3               0        0   \n",
       "                                       House 4               0        0   \n",
       "                                       House 5               0        0   \n",
       "...                                                        ...      ...   \n",
       "Old water pipes operation [U*h/a]      Node 2           7.2389  8.99169   \n",
       "                                       Node 3              NaN      NaN   \n",
       "                                       Node 4              NaN      NaN   \n",
       "                                       Water tank          NaN      NaN   \n",
       "                                       Water treatment     NaN      NaN   \n",
       "\n",
       "                                                       House 5 House 6  \\\n",
       "Component       Property  Unit         LocationIn                        \n",
       "New water pipes TAC       [1e3 Euro/a] House 1               0       0   \n",
       "                                       House 2               0       0   \n",
       "                                       House 3               0       0   \n",
       "                                       House 4               0       0   \n",
       "                                       House 5               0       0   \n",
       "...                                                        ...     ...   \n",
       "Old water pipes operation [U*h/a]      Node 2              NaN     NaN   \n",
       "                                       Node 3              NaN     NaN   \n",
       "                                       Node 4              NaN     NaN   \n",
       "                                       Water tank          NaN     NaN   \n",
       "                                       Water treatment     NaN     NaN   \n",
       "\n",
       "                                                          Node 1    Node 2  \\\n",
       "Component       Property  Unit         LocationIn                            \n",
       "New water pipes TAC       [1e3 Euro/a] House 1                 0         0   \n",
       "                                       House 2                 0         0   \n",
       "                                       House 3                 0  0.776557   \n",
       "                                       House 4                 0  0.817429   \n",
       "                                       House 5          0.776557         0   \n",
       "...                                                          ...       ...   \n",
       "Old water pipes operation [U*h/a]      Node 2                NaN       NaN   \n",
       "                                       Node 3                NaN   93.6361   \n",
       "                                       Node 4                NaN       NaN   \n",
       "                                       Water tank            NaN       NaN   \n",
       "                                       Water treatment       NaN       NaN   \n",
       "\n",
       "                                                          Node 3   Node 4  \\\n",
       "Component       Property  Unit         LocationIn                           \n",
       "New water pipes TAC       [1e3 Euro/a] House 1          0.776557        0   \n",
       "                                       House 2          0.817429        0   \n",
       "                                       House 3                 0        0   \n",
       "                                       House 4                 0        0   \n",
       "                                       House 5                 0        0   \n",
       "...                                                          ...      ...   \n",
       "Old water pipes operation [U*h/a]      Node 2                  0      NaN   \n",
       "                                       Node 3                NaN        0   \n",
       "                                       Node 4            148.693      NaN   \n",
       "                                       Water tank            NaN  753.147   \n",
       "                                       Water treatment       NaN  135.785   \n",
       "\n",
       "                                                       Water tank  \\\n",
       "Component       Property  Unit         LocationIn                   \n",
       "New water pipes TAC       [1e3 Euro/a] House 1                  0   \n",
       "                                       House 2                  0   \n",
       "                                       House 3                  0   \n",
       "                                       House 4                  0   \n",
       "                                       House 5                  0   \n",
       "...                                                           ...   \n",
       "Old water pipes operation [U*h/a]      Node 2                 NaN   \n",
       "                                       Node 3                 NaN   \n",
       "                                       Node 4             792.787   \n",
       "                                       Water tank             NaN   \n",
       "                                       Water treatment        NaN   \n",
       "\n",
       "                                                       Water treatment  \n",
       "Component       Property  Unit         LocationIn                       \n",
       "New water pipes TAC       [1e3 Euro/a] House 1                       0  \n",
       "                                       House 2                       0  \n",
       "                                       House 3                       0  \n",
       "                                       House 4                       0  \n",
       "                                       House 5                       0  \n",
       "...                                                                ...  \n",
       "Old water pipes operation [U*h/a]      Node 2                      NaN  \n",
       "                                       Node 3                      NaN  \n",
       "                                       Node 4                        0  \n",
       "                                       Water tank                  NaN  \n",
       "                                       Water treatment             NaN  \n",
       "\n",
       "[72 rows x 12 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"TransmissionModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "New water pipes  House 1          Node 3                 0.000000\n",
       "                 House 2          Node 3                 0.000000\n",
       "                 House 3          Node 2                 0.000000\n",
       "                 House 4          Node 2                 0.000000\n",
       "                 House 5          Node 1                 0.000000\n",
       "                 House 6          Node 1                 0.000000\n",
       "                 Node 1           House 5             3385.864780\n",
       "                                  House 6             3400.619777\n",
       "                                  Node 2                 0.000000\n",
       "                 Node 2           House 3             3373.887533\n",
       "                                  House 4             3412.683133\n",
       "                                  Node 1              7162.516682\n",
       "                                  Node 3                 0.000000\n",
       "                 Node 3           House 1             3386.620539\n",
       "                                  House 2             3364.900732\n",
       "                                  Node 2             14611.626819\n",
       "                                  Node 4                 0.000000\n",
       "                 Node 4           Node 3             21649.347831\n",
       "                                  Water tank             0.000000\n",
       "                                  Water treatment        0.000000\n",
       "                 Water tank       Node 4                 0.000000\n",
       "                 Water treatment  Node 4             21961.886367\n",
       "Old water pipes  House 1          Node 3                 0.000000\n",
       "                 House 2          Node 3                 0.000000\n",
       "                 House 3          Node 2                 0.000000\n",
       "                 House 4          Node 2                 0.000000\n",
       "                 Node 2           House 3                7.238899\n",
       "                                  House 4                8.991694\n",
       "                                  Node 3                 0.000000\n",
       "                 Node 3           House 1                7.500411\n",
       "                                  House 2                4.554908\n",
       "                                  Node 2                93.636071\n",
       "                                  Node 4                 0.000000\n",
       "                 Node 4           Node 3               148.692644\n",
       "                                  Water tank           792.786557\n",
       "                                  Water treatment        0.000000\n",
       "                 Water tank       Node 4               753.147229\n",
       "                 Water treatment  Node 4               135.785369\n",
       "dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.componentModelingDict[\"TransmissionModel\"].operationVariablesOptimum.sum(axis=1)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
