{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "import sumolib\n",
    "import copy\n",
    "from tqdm import tqdm\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-05 08:25:00\n",
      "2024-01-05 08:30:00\n",
      "2024-01-05 08:35:00\n",
      "2024-01-05 08:45:00\n"
     ]
    }
   ],
   "source": [
    "midnight = int(datetime(2024, 1, 5, 0, 0, 0).timestamp())\n",
    "next_day = int(datetime(2024, 1, 6, 0, 0, 0).timestamp())\n",
    "fmins = range(midnight, next_day, 300)\n",
    "m = 105 # m ranges from 26 to 287\n",
    "# sigtable 시작시각  : 현재시각 - 1200 = 08:25\n",
    "# 시뮬레이션 시작시각 : 현재시각 - 900 = 08:30\n",
    "# 시뮬레이션 종료시각 : 현재시각 - 600 = 08:35\n",
    "# 현재시각           : 08:45\n",
    "present_time = fmins[m]\n",
    "sigtable_start = fmins[m] - 1200\n",
    "sim_start = fmins[m] - 900\n",
    "sim_end = fmins[m] - 600\n",
    "print(datetime.fromtimestamp(sigtable_start))\n",
    "print(datetime.fromtimestamp(sim_start))\n",
    "print(datetime.fromtimestamp(sim_end))\n",
    "print(datetime.fromtimestamp(present_time))\n",
    "net = sumolib.net.readNet('../../Data/networks/sn.net.xml')\n",
    "inter_node = pd.read_csv('../../data/tables/inter_node.csv', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9']\n"
     ]
    }
   ],
   "source": [
    "histid = pd.read_csv(f'../../Data/tables/histids/histids_{fmins[50]}.csv', index_col=0)\n",
    "print(sorted(histid.node_id.unique()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{175: 'u00', 176: 'i1', 177: 'u20', 178: 'c30', 210: 'u60', 206: 'i7', 201: 'i8', 202: 'i9'}\n",
      "{'i0': 175, 'u00': 175, 'i1': 176, 'i2': 177, 'u20': 177, 'i3': 178, 'u30': 178, 'u31': 178, 'u32': 178, 'c30': 178, 'i6': 210, 'u60': 210, 'i7': 206, 'i8': 201, 'i9': 202}\n",
      "{'u00': 'i0', 'u20': 'i2', 'u30': 'i3', 'u31': 'i3', 'u32': 'i3', 'c30': 'i3'}\n",
      "{'i0': ['u00'], 'i1': [], 'i2': ['u20'], 'i3': ['c30', 'u30', 'u31', 'u32'], 'i6': [], 'i7': [], 'i8': [], 'i9': []}\n",
      "['c30', 'i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9', 'u00', 'u20', 'u30', 'u31', 'u32', 'u60']\n",
      "['i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9']\n",
      "['c30', 'u00', 'u20', 'u30', 'u31', 'u32', 'u60']\n"
     ]
    }
   ],
   "source": [
    "inter2node = dict(zip(inter_node['inter_no'], inter_node['node_id']))\n",
    "node2inter = dict(zip(inter_node['node_id'], inter_node['inter_no']))\n",
    "ch2pa = {'u00': 'i0', 'u20': 'i2', 'u30': 'i3', 'u31': 'i3', 'u32': 'i3', 'c30': 'i3'}\n",
    "pa2ch = {'i0':['u00'], 'i1':[], 'i2':['u20'], 'i3':['c30', 'u30', 'u31', 'u32'], 'i6':[], 'i7':[], 'i8':[], 'i9':[]}\n",
    "node_ids = sorted(inter_node.node_id.unique())\n",
    "parent_ids = sorted(inter_node[inter_node.inter_type=='parent'].node_id.unique())\n",
    "child_ids = sorted(inter_node[inter_node.inter_type=='child'].node_id.unique())\n",
    "\n",
    "print(inter2node)\n",
    "print(node2inter)\n",
    "print(ch2pa)\n",
    "print(pa2ch)\n",
    "print(node_ids)\n",
    "print(parent_ids)\n",
    "print(child_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1704411900 2024-01-05 08:45:00\n"
     ]
    },
    {
     "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>node_id</th>\n",
       "      <th>start_unix</th>\n",
       "      <th>phas_A</th>\n",
       "      <th>phas_B</th>\n",
       "      <th>duration</th>\n",
       "      <th>inc_edge_A</th>\n",
       "      <th>out_edge_A</th>\n",
       "      <th>inc_edge_B</th>\n",
       "      <th>out_edge_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542811_01</td>\n",
       "      <td>571542811_02</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>25</td>\n",
       "      <td>571542811_02</td>\n",
       "      <td>571542107_01</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>71</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>34</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542811_01</td>\n",
       "      <td>571542107_02</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>i6</td>\n",
       "      <td>1704410760</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>-571542115_01</td>\n",
       "      <td>571500535_01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>i0</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>571545870_02</td>\n",
       "      <td>571510153_01</td>\n",
       "      <td>571510153_02</td>\n",
       "      <td>571545870_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>i0</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>571510153_02</td>\n",
       "      <td>571500487_01</td>\n",
       "      <td>571510153_02</td>\n",
       "      <td>571545870_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>37</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>571542797_02.99</td>\n",
       "      <td>571542810_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>93</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>571543469_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>40</td>\n",
       "      <td>571543469_02</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>168 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    node_id  start_unix  phas_A  phas_B  duration     inc_edge_A  \\\n",
       "0        i2  1704410739       1       1        40  -571542809_01   \n",
       "1        i2  1704410739       2       2        25   571542811_02   \n",
       "2        i2  1704410739       3       3        71            NaN   \n",
       "3        i2  1704410739       4       4        34  -571542809_01   \n",
       "4        i6  1704410760       1       1        24  -571542115_01   \n",
       "..      ...         ...     ...     ...       ...            ...   \n",
       "163      i0  1704411630       3       4        26   571545870_02   \n",
       "164      i0  1704411630       4       4        33   571510153_02   \n",
       "165      i1  1704411670       1       1        37  -571542810_01   \n",
       "166      i1  1704411670       2       2        93  -571542810_01   \n",
       "167      i1  1704411670       3       3        40   571543469_02   \n",
       "\n",
       "           out_edge_A       inc_edge_B    out_edge_B  \n",
       "0        571542811_01     571542811_02  571542809_01  \n",
       "1        571542107_01    -571542809_01  571542809_01  \n",
       "2                 NaN              NaN           NaN  \n",
       "3        571542811_01     571542107_02  571542809_01  \n",
       "4        571500535_01              NaN           NaN  \n",
       "..                ...              ...           ...  \n",
       "163      571510153_01     571510153_02  571545870_01  \n",
       "164      571500487_01     571510153_02  571545870_01  \n",
       "165  -571542797_02.99  571542797_02.99  571542810_01  \n",
       "166  -571542797_02.99    -571542810_01  571543469_01  \n",
       "167  -571542797_02.99              NaN           NaN  \n",
       "\n",
       "[168 rows x 9 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "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>node_id</th>\n",
       "      <th>phase_no</th>\n",
       "      <th>ring_type</th>\n",
       "      <th>inc_edge</th>\n",
       "      <th>out_edge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>i0</td>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>-571542797_02</td>\n",
       "      <td>571500487_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>i0</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "      <td>-571500487_01</td>\n",
       "      <td>571542797_02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>i0</td>\n",
       "      <td>2</td>\n",
       "      <td>A</td>\n",
       "      <td>-571500487_01</td>\n",
       "      <td>571545870_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>i0</td>\n",
       "      <td>2</td>\n",
       "      <td>B</td>\n",
       "      <td>-571542797_02</td>\n",
       "      <td>571510153_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>i0</td>\n",
       "      <td>3</td>\n",
       "      <td>A</td>\n",
       "      <td>571545870_02</td>\n",
       "      <td>571510153_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>u60</td>\n",
       "      <td>2</td>\n",
       "      <td>B</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>u60</td>\n",
       "      <td>3</td>\n",
       "      <td>A</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>u60</td>\n",
       "      <td>3</td>\n",
       "      <td>B</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>u60</td>\n",
       "      <td>4</td>\n",
       "      <td>A</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>u60</td>\n",
       "      <td>4</td>\n",
       "      <td>B</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>116 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    node_id  phase_no ring_type       inc_edge      out_edge\n",
       "0        i0         1         A  -571542797_02  571500487_01\n",
       "1        i0         1         B  -571500487_01  571542797_02\n",
       "2        i0         2         A  -571500487_01  571545870_01\n",
       "3        i0         2         B  -571542797_02  571510153_01\n",
       "4        i0         3         A   571545870_02  571510153_01\n",
       "..      ...       ...       ...            ...           ...\n",
       "111     u60         2         B            NaN           NaN\n",
       "112     u60         3         A            NaN           NaN\n",
       "113     u60         3         B            NaN           NaN\n",
       "114     u60         4         A            NaN           NaN\n",
       "115     u60         4         B            NaN           NaN\n",
       "\n",
       "[116 rows x 5 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(fmins[m], datetime.fromtimestamp(fmins[m]))\n",
    "histid = pd.read_csv(f'../../Data/tables/histids/histids_{fmins[m]}.csv', index_col=0)\n",
    "match6 = pd.read_csv('../../Data/tables/matching/match6.csv', index_col=0)\n",
    "histid = histid.reset_index(drop=True)\n",
    "histid = histid.drop(columns=['inter_no'])\n",
    "match6 = match6[['node_id', 'phase_no', 'ring_type', 'inc_edge', 'out_edge']].reset_index(drop=True)\n",
    "display(histid)\n",
    "display(match6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['i0', 'i1', 'i2', 'i3', 'i6', 'i8', 'i9']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(histid.node_id.unique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "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>node_id</th>\n",
       "      <th>start_unix</th>\n",
       "      <th>phas_A</th>\n",
       "      <th>phas_B</th>\n",
       "      <th>duration</th>\n",
       "      <th>inc_edge_A</th>\n",
       "      <th>out_edge_A</th>\n",
       "      <th>inc_edge_B</th>\n",
       "      <th>out_edge_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542811_01</td>\n",
       "      <td>571542811_02</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>25</td>\n",
       "      <td>571542811_02</td>\n",
       "      <td>571542107_01</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>71</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>34</td>\n",
       "      <td>-571542809_01</td>\n",
       "      <td>571542811_01</td>\n",
       "      <td>571542107_02</td>\n",
       "      <td>571542809_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>u20</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>313</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>314</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>315</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>37</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>571542797_02.99</td>\n",
       "      <td>571542810_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>316</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>93</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>-571542810_01</td>\n",
       "      <td>571543469_01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>317</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>40</td>\n",
       "      <td>571543469_02</td>\n",
       "      <td>-571542797_02.99</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>318 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    node_id  start_unix  phas_A  phas_B  duration     inc_edge_A  \\\n",
       "0        i2  1704410739       1       1        40  -571542809_01   \n",
       "1        i2  1704410739       2       2        25   571542811_02   \n",
       "2        i2  1704410739       3       3        71            NaN   \n",
       "3        i2  1704410739       4       4        34  -571542809_01   \n",
       "4       u20  1704410739       1       1        40            NaN   \n",
       "..      ...         ...     ...     ...       ...            ...   \n",
       "313     u00  1704411630       3       4        26            NaN   \n",
       "314     u00  1704411630       4       4        33            NaN   \n",
       "315      i1  1704411670       1       1        37  -571542810_01   \n",
       "316      i1  1704411670       2       2        93  -571542810_01   \n",
       "317      i1  1704411670       3       3        40   571543469_02   \n",
       "\n",
       "           out_edge_A       inc_edge_B    out_edge_B  \n",
       "0        571542811_01     571542811_02  571542809_01  \n",
       "1        571542107_01    -571542809_01  571542809_01  \n",
       "2                 NaN              NaN           NaN  \n",
       "3        571542811_01     571542107_02  571542809_01  \n",
       "4                 NaN              NaN           NaN  \n",
       "..                ...              ...           ...  \n",
       "313               NaN              NaN           NaN  \n",
       "314               NaN              NaN           NaN  \n",
       "315  -571542797_02.99  571542797_02.99  571542810_01  \n",
       "316  -571542797_02.99    -571542810_01  571543469_01  \n",
       "317  -571542797_02.99              NaN           NaN  \n",
       "\n",
       "[318 rows x 9 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "new_histids = []\n",
    "for parent_id in parent_ids:\n",
    "    for child_id in pa2ch[parent_id]:\n",
    "        new_histid = histid.copy()[histid.node_id==parent_id]\n",
    "        new_histid[['inc_edge_A', 'out_edge_A', 'inc_edge_B', 'out_edge_B']] = np.nan\n",
    "        for i, row in new_histid.iterrows():\n",
    "            phas_A = row.phas_A\n",
    "            phas_B = row.phas_B\n",
    "            new_match = match6[match6.node_id==child_id]\n",
    "            Arow = new_match[(new_match.phase_no==phas_A) & (new_match.ring_type=='A')]\n",
    "            if ~ Arow[['inc_edge', 'out_edge']].isna().all().all():\n",
    "                inc_edge = Arow.iloc[0].inc_edge\n",
    "                out_edge = Arow.iloc[0].out_edge\n",
    "                new_histid.loc[i, ['inc_edge_A', 'out_edge_A']] = [inc_edge, out_edge]\n",
    "            Brow = new_match[(new_match.phase_no==phas_B) & (new_match.ring_type=='B')]\n",
    "            if ~ Brow[['inc_edge', 'out_edge']].isna().all().all():\n",
    "                inc_edge = Brow.iloc[0].inc_edge\n",
    "                out_edge = Brow.iloc[0].out_edge\n",
    "                new_histid.loc[i, ['inc_edge_B', 'out_edge_B']] = [inc_edge, out_edge]\n",
    "            new_histid.loc[i, 'node_id'] = child_id\n",
    "        new_histids.append(new_histid)\n",
    "histid_child = pd.concat(new_histids)\n",
    "histids = pd.concat([histid.copy(), histid_child])\n",
    "histids = histids.sort_values(by=['start_unix', 'node_id', 'phas_A', 'phas_B']).reset_index(drop=True)\n",
    "display(histids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "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>node_id</th>\n",
       "      <th>start_unix</th>\n",
       "      <th>phas_A</th>\n",
       "      <th>phas_B</th>\n",
       "      <th>duration</th>\n",
       "      <th>inc_edge_A</th>\n",
       "      <th>out_edge_A</th>\n",
       "      <th>inc_edge_B</th>\n",
       "      <th>out_edge_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410780</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410780</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410780</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410780</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410780</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411120</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411120</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411120</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411120</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411120</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411290</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411290</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411290</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411290</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>203</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411290</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411460</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411460</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411460</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>260</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411460</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411460</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>310</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>311</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>42</td>\n",
       "      <td>571500487_02</td>\n",
       "      <td>571500487_01.32</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>313</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>314</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>33</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": [
       "    node_id  start_unix  phas_A  phas_B  duration    inc_edge_A  \\\n",
       "18      u00  1704410780       1       1        40           NaN   \n",
       "19      u00  1704410780       2       2        42  571500487_02   \n",
       "20      u00  1704410780       3       3        29           NaN   \n",
       "21      u00  1704410780       3       4        26           NaN   \n",
       "22      u00  1704410780       4       4        33           NaN   \n",
       "79      u00  1704410950       1       1        40           NaN   \n",
       "80      u00  1704410950       2       2        42  571500487_02   \n",
       "81      u00  1704410950       3       3        29           NaN   \n",
       "82      u00  1704410950       3       4        26           NaN   \n",
       "83      u00  1704410950       4       4        33           NaN   \n",
       "146     u00  1704411120       1       1        40           NaN   \n",
       "147     u00  1704411120       2       2        42  571500487_02   \n",
       "148     u00  1704411120       3       3        29           NaN   \n",
       "149     u00  1704411120       3       4        26           NaN   \n",
       "150     u00  1704411120       4       4        33           NaN   \n",
       "199     u00  1704411290       1       1        40           NaN   \n",
       "200     u00  1704411290       2       2        42  571500487_02   \n",
       "201     u00  1704411290       3       3        29           NaN   \n",
       "202     u00  1704411290       3       4        26           NaN   \n",
       "203     u00  1704411290       4       4        33           NaN   \n",
       "257     u00  1704411460       1       1        40           NaN   \n",
       "258     u00  1704411460       2       2        42  571500487_02   \n",
       "259     u00  1704411460       3       3        29           NaN   \n",
       "260     u00  1704411460       3       4        26           NaN   \n",
       "261     u00  1704411460       4       4        33           NaN   \n",
       "310     u00  1704411630       1       1        40           NaN   \n",
       "311     u00  1704411630       2       2        42  571500487_02   \n",
       "312     u00  1704411630       3       3        29           NaN   \n",
       "313     u00  1704411630       3       4        26           NaN   \n",
       "314     u00  1704411630       4       4        33           NaN   \n",
       "\n",
       "          out_edge_A inc_edge_B out_edge_B  \n",
       "18               NaN        NaN        NaN  \n",
       "19   571500487_01.32        NaN        NaN  \n",
       "20               NaN        NaN        NaN  \n",
       "21               NaN        NaN        NaN  \n",
       "22               NaN        NaN        NaN  \n",
       "79               NaN        NaN        NaN  \n",
       "80   571500487_01.32        NaN        NaN  \n",
       "81               NaN        NaN        NaN  \n",
       "82               NaN        NaN        NaN  \n",
       "83               NaN        NaN        NaN  \n",
       "146              NaN        NaN        NaN  \n",
       "147  571500487_01.32        NaN        NaN  \n",
       "148              NaN        NaN        NaN  \n",
       "149              NaN        NaN        NaN  \n",
       "150              NaN        NaN        NaN  \n",
       "199              NaN        NaN        NaN  \n",
       "200  571500487_01.32        NaN        NaN  \n",
       "201              NaN        NaN        NaN  \n",
       "202              NaN        NaN        NaN  \n",
       "203              NaN        NaN        NaN  \n",
       "257              NaN        NaN        NaN  \n",
       "258  571500487_01.32        NaN        NaN  \n",
       "259              NaN        NaN        NaN  \n",
       "260              NaN        NaN        NaN  \n",
       "261              NaN        NaN        NaN  \n",
       "310              NaN        NaN        NaN  \n",
       "311  571500487_01.32        NaN        NaN  \n",
       "312              NaN        NaN        NaN  \n",
       "313              NaN        NaN        NaN  \n",
       "314              NaN        NaN        NaN  "
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "histids[histids.node_id=='u00']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['c30', 'i0', 'i1', 'i2', 'i3', 'i6', 'i8', 'i9', 'u00', 'u20', 'u30', 'u31', 'u32']\n",
      "[<junction id=\"c30\"/>, <junction id=\"i0\"/>, <junction id=\"i1\"/>, <junction id=\"i2\"/>, <junction id=\"i3\"/>, <junction id=\"i6\"/>, <junction id=\"i8\"/>, <junction id=\"i9\"/>, <junction id=\"u00\"/>, <junction id=\"u20\"/>, <junction id=\"u30\"/>, <junction id=\"u31\"/>, <junction id=\"u32\"/>]\n"
     ]
    }
   ],
   "source": [
    "node_ids = sorted(histids.node_id.unique())\n",
    "nodes = [net.getNode(node_id) for node_id in node_ids]\n",
    "print(node_ids)\n",
    "print(nodes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c30 rrrrrr\n",
      "i0 grrrgrrrgrrrrrgrr\n",
      "i1 grrrrrrgrr\n",
      "i2 rrggrrr\n",
      "i3 grrrrgrrrrgrrrrgrrrr\n",
      "i6 grrrgrrrrgrrgrrr\n",
      "i8 grrrrrrrgrrrgrrr\n",
      "i9 rrrr\n",
      "u00 ggggrgggg\n",
      "u20 ggrggg\n",
      "u30 ggggrggg\n",
      "u31 ggggrggg\n",
      "u32 gggggggr\n"
     ]
    }
   ],
   "source": [
    "node2init = {}\n",
    "for node in nodes:\n",
    "    node_id = node.getID()\n",
    "    conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n",
    "    conns = [c for c in conns if c[0] >= 0]\n",
    "    conns = sorted(conns, key=lambda x: x[0])\n",
    "    state = []\n",
    "    for i, ci in conns:\n",
    "        if ci.getTLLinkIndex() < 0:\n",
    "            continue\n",
    "        are_foes = False\n",
    "        for j, cj in conns:\n",
    "            if ci.getTo() == cj.getTo():\n",
    "                continue\n",
    "            if node.areFoes(i, j):\n",
    "                are_foes = True\n",
    "                break\n",
    "        state.append('r' if are_foes else 'g')\n",
    "    node2init[node_id] = state\n",
    "\n",
    "# 어떤 연결과도 상충이 일어나지는 않지만, 신호가 부여되어 있는 경우에는 r을 부여\n",
    "for _, row in histids.iterrows():\n",
    "    node_id = row['node_id']\n",
    "    inc_edge_A = row.inc_edge_A\n",
    "    inc_edge_B = row.inc_edge_B\n",
    "    out_edge_A = row.out_edge_A\n",
    "    out_edge_B = row.out_edge_B\n",
    "\n",
    "    if pd.isna(inc_edge_A) or pd.isna(out_edge_A):\n",
    "        pass\n",
    "    else:\n",
    "        inc_edge_A = net.getEdge(inc_edge_A)\n",
    "        out_edge_A = net.getEdge(out_edge_A)\n",
    "        for conn in inc_edge_A.getConnections(out_edge_A):\n",
    "            index = conn.getTLLinkIndex()\n",
    "            if index >= 0:\n",
    "                node2init[node_id][index] = 'r'\n",
    "\n",
    "    if pd.isna(inc_edge_B) or pd.isna(out_edge_B):\n",
    "        pass\n",
    "    else:\n",
    "        inc_edge_B = net.getEdge(inc_edge_B)\n",
    "        out_edge_B = net.getEdge(out_edge_B)\n",
    "        for conn in inc_edge_B.getConnections(out_edge_B):\n",
    "            index = conn.getTLLinkIndex()\n",
    "            if index >= 0:\n",
    "                node2init[node_id][index] = 'r'\n",
    "for node_id in node_ids:\n",
    "    print(node_id, \"\".join(node2init[node_id]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1704411900\n",
      "2024-01-05 08:45:00\n"
     ]
    },
    {
     "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>node_id</th>\n",
       "      <th>start_unix</th>\n",
       "      <th>phase_sumo</th>\n",
       "      <th>duration</th>\n",
       "      <th>state</th>\n",
       "      <th>start_dt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>GGggGGG</td>\n",
       "      <td>2024-01-05 08:25:39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>1</td>\n",
       "      <td>25</td>\n",
       "      <td>rrggrrr</td>\n",
       "      <td>2024-01-05 08:25:39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>2</td>\n",
       "      <td>71</td>\n",
       "      <td>rrggrrr</td>\n",
       "      <td>2024-01-05 08:25:39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>i2</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>3</td>\n",
       "      <td>34</td>\n",
       "      <td>rrggGGG</td>\n",
       "      <td>2024-01-05 08:25:39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>u20</td>\n",
       "      <td>1704410739</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>ggrggg</td>\n",
       "      <td>2024-01-05 08:25:39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>313</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>3</td>\n",
       "      <td>26</td>\n",
       "      <td>ggggrgggg</td>\n",
       "      <td>2024-01-05 08:40:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>314</th>\n",
       "      <td>u00</td>\n",
       "      <td>1704411630</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>ggggrgggg</td>\n",
       "      <td>2024-01-05 08:40:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>315</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>0</td>\n",
       "      <td>37</td>\n",
       "      <td>gGGGGGrgrr</td>\n",
       "      <td>2024-01-05 08:41:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>316</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>1</td>\n",
       "      <td>93</td>\n",
       "      <td>grrGGGGgrr</td>\n",
       "      <td>2024-01-05 08:41:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>317</th>\n",
       "      <td>i1</td>\n",
       "      <td>1704411670</td>\n",
       "      <td>2</td>\n",
       "      <td>40</td>\n",
       "      <td>grrrrrrgGG</td>\n",
       "      <td>2024-01-05 08:41:10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>318 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    node_id  start_unix  phase_sumo  duration       state            start_dt\n",
       "0        i2  1704410739           0        40     GGggGGG 2024-01-05 08:25:39\n",
       "1        i2  1704410739           1        25     rrggrrr 2024-01-05 08:25:39\n",
       "2        i2  1704410739           2        71     rrggrrr 2024-01-05 08:25:39\n",
       "3        i2  1704410739           3        34     rrggGGG 2024-01-05 08:25:39\n",
       "4       u20  1704410739           0        40      ggrggg 2024-01-05 08:25:39\n",
       "..      ...         ...         ...       ...         ...                 ...\n",
       "313     u00  1704411630           3        26   ggggrgggg 2024-01-05 08:40:30\n",
       "314     u00  1704411630           4        33   ggggrgggg 2024-01-05 08:40:30\n",
       "315      i1  1704411670           0        37  gGGGGGrgrr 2024-01-05 08:41:10\n",
       "316      i1  1704411670           1        93  grrGGGGgrr 2024-01-05 08:41:10\n",
       "317      i1  1704411670           2        40  grrrrrrgGG 2024-01-05 08:41:10\n",
       "\n",
       "[318 rows x 6 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(present_time)\n",
    "print(datetime.fromtimestamp(present_time))\n",
    "sigtable = histids.copy()\n",
    "sigtable['init_state'] = sigtable['node_id'].map(node2init)\n",
    "sigtable['state'] = sigtable['init_state'].map(lambda x:''.join(x))\n",
    "for i, row in sigtable.iterrows():\n",
    "    node_id = row.node_id\n",
    "    inc_edge_A = row.inc_edge_A\n",
    "    inc_edge_B = row.inc_edge_B\n",
    "    out_edge_A = row.out_edge_A\n",
    "    out_edge_B = row.out_edge_B\n",
    "    state = copy.deepcopy(node2init)[node_id]\n",
    "\n",
    "    if pd.isna(inc_edge_A) or pd.isna(out_edge_A):\n",
    "        continue\n",
    "    else:\n",
    "        inc_edge_A = net.getEdge(inc_edge_A)\n",
    "        out_edge_A = net.getEdge(out_edge_A)\n",
    "        for conn in inc_edge_A.getConnections(out_edge_A):\n",
    "            index = conn.getTLLinkIndex()\n",
    "            if index >= 0:\n",
    "                state[index] = 'G'\n",
    "        sigtable.at[i, 'state'] = ''.join(state)\n",
    "\n",
    "    if pd.isna(inc_edge_B) or pd.isna(out_edge_B):\n",
    "        continue\n",
    "    else:\n",
    "        inc_edge_B = net.getEdge(inc_edge_B)\n",
    "        out_edge_B = net.getEdge(out_edge_B)\n",
    "        for conn in inc_edge_B.getConnections(out_edge_B):\n",
    "            index = conn.getTLLinkIndex()\n",
    "            if index >= 0:\n",
    "                state[index] = 'G'\n",
    "        sigtable.at[i, 'state'] = ''.join(state)\n",
    "sigtable = sigtable.dropna(subset='state')\n",
    "sigtable = sigtable.reset_index(drop=True)\n",
    "sigtable['phase_sumo'] = sigtable.groupby(['node_id', 'start_unix']).cumcount()\n",
    "sigtable = sigtable[sigtable.start_unix >= sigtable_start]\n",
    "sigtable = sigtable[['node_id', 'start_unix', 'phase_sumo', 'duration', 'state']]\n",
    "sigtable = sigtable.sort_values(by=['start_unix', 'node_id'])\n",
    "sigtable['start_dt'] = sigtable['start_unix'].apply(lambda x:datetime.fromtimestamp(x))\n",
    "display(sigtable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "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>node_id</th>\n",
       "      <th>start_unix</th>\n",
       "      <th>phase_sumo</th>\n",
       "      <th>duration</th>\n",
       "      <th>state</th>\n",
       "      <th>start_dt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>0_g</td>\n",
       "      <td>33</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>0_y</td>\n",
       "      <td>4</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>1__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>1_g</td>\n",
       "      <td>34</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>1_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>2__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>2_g</td>\n",
       "      <td>37</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>2_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>3__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>3_g</td>\n",
       "      <td>16</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410790</td>\n",
       "      <td>3_y</td>\n",
       "      <td>4</td>\n",
       "      <td>yyyyyy</td>\n",
       "      <td>2024-01-05 08:26:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>0__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>0_g</td>\n",
       "      <td>33</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>0_y</td>\n",
       "      <td>4</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>1__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>1_g</td>\n",
       "      <td>34</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>1_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>2__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>2_g</td>\n",
       "      <td>37</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>2_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>3__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>3_g</td>\n",
       "      <td>16</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704410950</td>\n",
       "      <td>3_y</td>\n",
       "      <td>4</td>\n",
       "      <td>yyyyyy</td>\n",
       "      <td>2024-01-05 08:29:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>0__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>0_g</td>\n",
       "      <td>33</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>0_y</td>\n",
       "      <td>4</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>1__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>1_g</td>\n",
       "      <td>34</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>1_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>2__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>2_g</td>\n",
       "      <td>37</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>2_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>3__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>3_g</td>\n",
       "      <td>16</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411110</td>\n",
       "      <td>3_y</td>\n",
       "      <td>4</td>\n",
       "      <td>yyyyyy</td>\n",
       "      <td>2024-01-05 08:31:50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>0__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>0_g</td>\n",
       "      <td>33</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>0_y</td>\n",
       "      <td>4</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>1__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>1_g</td>\n",
       "      <td>34</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>1_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>2__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>2_g</td>\n",
       "      <td>37</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>2_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>3__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>3_g</td>\n",
       "      <td>16</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411270</td>\n",
       "      <td>3_y</td>\n",
       "      <td>4</td>\n",
       "      <td>yyyyyy</td>\n",
       "      <td>2024-01-05 08:34:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>0__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>0_g</td>\n",
       "      <td>33</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>0_y</td>\n",
       "      <td>4</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>1__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>1_g</td>\n",
       "      <td>34</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>1_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>2__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>2_g</td>\n",
       "      <td>37</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>2_y</td>\n",
       "      <td>4</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>3__r</td>\n",
       "      <td>1</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>3_g</td>\n",
       "      <td>16</td>\n",
       "      <td>GGGGGG</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411430</td>\n",
       "      <td>3_y</td>\n",
       "      <td>4</td>\n",
       "      <td>yyyyyy</td>\n",
       "      <td>2024-01-05 08:37:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>c30</td>\n",
       "      <td>1704411590</td>\n",
       "      <td>0__r</td>\n",
       "      <td>1</td>\n",
       "      <td>rrrrrr</td>\n",
       "      <td>2024-01-05 08:39:50</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   node_id  start_unix phase_sumo  duration   state            start_dt\n",
       "0      c30  1704410790        0_g        33  rrrrrr 2024-01-05 08:26:30\n",
       "1      c30  1704410790        0_y         4  rrrrrr 2024-01-05 08:26:30\n",
       "2      c30  1704410790       1__r         1  rrrrrr 2024-01-05 08:26:30\n",
       "3      c30  1704410790        1_g        34  GGGGGG 2024-01-05 08:26:30\n",
       "4      c30  1704410790        1_y         4  GGGGGG 2024-01-05 08:26:30\n",
       "5      c30  1704410790       2__r         1  GGGGGG 2024-01-05 08:26:30\n",
       "6      c30  1704410790        2_g        37  GGGGGG 2024-01-05 08:26:30\n",
       "7      c30  1704410790        2_y         4  GGGGGG 2024-01-05 08:26:30\n",
       "8      c30  1704410790       3__r         1  GGGGGG 2024-01-05 08:26:30\n",
       "9      c30  1704410790        3_g        16  GGGGGG 2024-01-05 08:26:30\n",
       "10     c30  1704410790        3_y         4  yyyyyy 2024-01-05 08:26:30\n",
       "11     c30  1704410950       0__r         1  rrrrrr 2024-01-05 08:29:10\n",
       "12     c30  1704410950        0_g        33  rrrrrr 2024-01-05 08:29:10\n",
       "13     c30  1704410950        0_y         4  rrrrrr 2024-01-05 08:29:10\n",
       "14     c30  1704410950       1__r         1  rrrrrr 2024-01-05 08:29:10\n",
       "15     c30  1704410950        1_g        34  GGGGGG 2024-01-05 08:29:10\n",
       "16     c30  1704410950        1_y         4  GGGGGG 2024-01-05 08:29:10\n",
       "17     c30  1704410950       2__r         1  GGGGGG 2024-01-05 08:29:10\n",
       "18     c30  1704410950        2_g        37  GGGGGG 2024-01-05 08:29:10\n",
       "19     c30  1704410950        2_y         4  GGGGGG 2024-01-05 08:29:10\n",
       "20     c30  1704410950       3__r         1  GGGGGG 2024-01-05 08:29:10\n",
       "21     c30  1704410950        3_g        16  GGGGGG 2024-01-05 08:29:10\n",
       "22     c30  1704410950        3_y         4  yyyyyy 2024-01-05 08:29:10\n",
       "23     c30  1704411110       0__r         1  rrrrrr 2024-01-05 08:31:50\n",
       "24     c30  1704411110        0_g        33  rrrrrr 2024-01-05 08:31:50\n",
       "25     c30  1704411110        0_y         4  rrrrrr 2024-01-05 08:31:50\n",
       "26     c30  1704411110       1__r         1  rrrrrr 2024-01-05 08:31:50\n",
       "27     c30  1704411110        1_g        34  GGGGGG 2024-01-05 08:31:50\n",
       "28     c30  1704411110        1_y         4  GGGGGG 2024-01-05 08:31:50\n",
       "29     c30  1704411110       2__r         1  GGGGGG 2024-01-05 08:31:50\n",
       "30     c30  1704411110        2_g        37  GGGGGG 2024-01-05 08:31:50\n",
       "31     c30  1704411110        2_y         4  GGGGGG 2024-01-05 08:31:50\n",
       "32     c30  1704411110       3__r         1  GGGGGG 2024-01-05 08:31:50\n",
       "33     c30  1704411110        3_g        16  GGGGGG 2024-01-05 08:31:50\n",
       "34     c30  1704411110        3_y         4  yyyyyy 2024-01-05 08:31:50\n",
       "35     c30  1704411270       0__r         1  rrrrrr 2024-01-05 08:34:30\n",
       "36     c30  1704411270        0_g        33  rrrrrr 2024-01-05 08:34:30\n",
       "37     c30  1704411270        0_y         4  rrrrrr 2024-01-05 08:34:30\n",
       "38     c30  1704411270       1__r         1  rrrrrr 2024-01-05 08:34:30\n",
       "39     c30  1704411270        1_g        34  GGGGGG 2024-01-05 08:34:30\n",
       "40     c30  1704411270        1_y         4  GGGGGG 2024-01-05 08:34:30\n",
       "41     c30  1704411270       2__r         1  GGGGGG 2024-01-05 08:34:30\n",
       "42     c30  1704411270        2_g        37  GGGGGG 2024-01-05 08:34:30\n",
       "43     c30  1704411270        2_y         4  GGGGGG 2024-01-05 08:34:30\n",
       "44     c30  1704411270       3__r         1  GGGGGG 2024-01-05 08:34:30\n",
       "45     c30  1704411270        3_g        16  GGGGGG 2024-01-05 08:34:30\n",
       "46     c30  1704411270        3_y         4  yyyyyy 2024-01-05 08:34:30\n",
       "47     c30  1704411430       0__r         1  rrrrrr 2024-01-05 08:37:10\n",
       "48     c30  1704411430        0_g        33  rrrrrr 2024-01-05 08:37:10\n",
       "49     c30  1704411430        0_y         4  rrrrrr 2024-01-05 08:37:10\n",
       "50     c30  1704411430       1__r         1  rrrrrr 2024-01-05 08:37:10\n",
       "51     c30  1704411430        1_g        34  GGGGGG 2024-01-05 08:37:10\n",
       "52     c30  1704411430        1_y         4  GGGGGG 2024-01-05 08:37:10\n",
       "53     c30  1704411430       2__r         1  GGGGGG 2024-01-05 08:37:10\n",
       "54     c30  1704411430        2_g        37  GGGGGG 2024-01-05 08:37:10\n",
       "55     c30  1704411430        2_y         4  GGGGGG 2024-01-05 08:37:10\n",
       "56     c30  1704411430       3__r         1  GGGGGG 2024-01-05 08:37:10\n",
       "57     c30  1704411430        3_g        16  GGGGGG 2024-01-05 08:37:10\n",
       "58     c30  1704411430        3_y         4  yyyyyy 2024-01-05 08:37:10\n",
       "59     c30  1704411590       0__r         1  rrrrrr 2024-01-05 08:39:50"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sigtable = []\n",
    "for node_id, group in sigtable.groupby('node_id'):\n",
    "    new_rows_list = []\n",
    "    for i in range(1, len(group)):\n",
    "        prev_row = group.iloc[i-1:i].copy()\n",
    "        next_row = group.iloc[i:i+1].copy()\n",
    "        new_rows = pd.concat([prev_row, prev_row, next_row]).reset_index(drop=True)\n",
    "        new_rows.loc[0, 'phase_sumo'] = str(prev_row.phase_sumo.iloc[0]) + '_g'\n",
    "        new_rows.loc[0, 'duration'] = new_rows.loc[0, 'duration'] - 5\n",
    "        new_rows.loc[1, 'phase_sumo'] = str(prev_row.phase_sumo.iloc[0]) + '_y'\n",
    "        new_rows.loc[1, 'duration'] = 4\n",
    "        yellow_state = ''\n",
    "        red_state = ''\n",
    "        for a, b in zip(prev_row.state.iloc[0], next_row.state.iloc[0]):\n",
    "            if a == 'G' and b == 'r':\n",
    "                yellow_state += 'y'\n",
    "                red_state += 'r'\n",
    "            else:\n",
    "                yellow_state += a\n",
    "                red_state += a\n",
    "        new_rows.loc[2, 'phase_sumo'] = str(next_row.phase_sumo.iloc[0]) + '__r'\n",
    "        new_rows.loc[2, 'duration'] = 1\n",
    "        new_rows.loc[1, 'state'] = yellow_state\n",
    "        new_rows.loc[2, 'state'] = red_state\n",
    "        new_rows_list.append(new_rows)\n",
    "    next_row['phase_sumo'] = str(next_row.phase_sumo.iloc[0]) + '_g'\n",
    "    next_row['duration'] -= 5\n",
    "    # next_row.loc['duration'] -= 5\n",
    "    new_rows_list.append(next_row)\n",
    "    new_rows = pd.concat(new_rows_list)\n",
    "    Sigtable.append(new_rows)\n",
    "Sigtable = pd.concat(Sigtable).sort_values(by=['node_id', 'start_unix', 'phase_sumo']).reset_index(drop=True)\n",
    "Sigtable[:60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-01-05 08:25:00\n",
      "2024-01-05 08:30:00\n",
      "2024-01-05 08:35:00\n",
      "2024-01-05 08:45:00\n"
     ]
    }
   ],
   "source": [
    "# sigtable 시작시각  : 현재시각 - 1200 = 08:25\n",
    "# 시뮬레이션 시작시각 : 현재시각 - 900 = 08:30\n",
    "# 시뮬레이션 종료시각 : 현재시각 - 600 = 08:35\n",
    "# 현재시각           : 08:45\n",
    "print(datetime.fromtimestamp(sigtable_start))\n",
    "print(datetime.fromtimestamp(sim_start))\n",
    "print(datetime.fromtimestamp(sim_end))\n",
    "print(datetime.fromtimestamp(present_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c30\n",
      "i0\n",
      "i1\n",
      "i2\n",
      "i3\n",
      "i6\n",
      "i8\n",
      "i9\n",
      "u00\n",
      "u20\n",
      "u30\n",
      "u31\n",
      "u32\n"
     ]
    }
   ],
   "source": [
    "for k, g in Sigtable.groupby('node_id'):\n",
    "    print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<additional>\n",
      "    <tlLogic id=\"c30\" type=\"static\" programID=\"c30_prog\" offset=\"-50\">\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"37\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"1\" state=\"GGGGGG\"/>\n",
      "      <phase duration=\"16\" state=\"GGGGGG\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i0\" type=\"static\" programID=\"i0_prog\" offset=\"-50\">\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrgrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrgrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrgrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrgrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrgrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyrgrrrgyyyyrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrygrrrgrrrrygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgrr\"/>\n",
      "      <phase duration=\"24\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGygrrrrrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGrgrrrrrgrr\"/>\n",
      "      <phase duration=\"21\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyrgrrrrrgGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrgrrrrrgGr\"/>\n",
      "      <phase duration=\"28\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i1\" type=\"static\" programID=\"i1_prog\" offset=\"-10\">\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrgyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"32\" state=\"gGGGGGrgrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyGGGrgrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrGGGrgrr\"/>\n",
      "      <phase duration=\"88\" state=\"grrGGGGgrr\"/>\n",
      "      <phase duration=\"4\" state=\"grryyyygrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrgrr\"/>\n",
      "      <phase duration=\"35\" state=\"grrrrrrgGG\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i2\" type=\"static\" programID=\"i2_prog\" offset=\"-90\">\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"1\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"1\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"1\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"1\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"1\" state=\"rrggGGG\"/>\n",
      "      <phase duration=\"35\" state=\"GGggGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyggyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"20\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"66\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrggrrr\"/>\n",
      "      <phase duration=\"29\" state=\"rrggGGG\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i3\" type=\"static\" programID=\"i3_prog\" offset=\"-50\">\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgyyyygrrrrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgyyyygrrrrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgyyyygrrrrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgyyyygrrrrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgyyyygrrrrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"33\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrgrrrrgyyyrgrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrygrrrrgrrrygrrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"37\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrgrrrrgrrrrgyyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrgrrrrgrrrrgrrrr\"/>\n",
      "      <phase duration=\"16\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i6\" type=\"static\" programID=\"i6_prog\" offset=\"-70\">\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"19\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgGGGrgrrgrrr\"/>\n",
      "      <phase duration=\"14\" state=\"grrrgGGGrgrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgyyyrgrrgGGr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgGGr\"/>\n",
      "      <phase duration=\"34\" state=\"grrrgrrrrgrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrgrrrrgrrgyyy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"60\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyygrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrgrrrrgrrgrrr\"/>\n",
      "      <phase duration=\"18\" state=\"grrrgrrrrgGGgrrr\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i8\" type=\"static\" programID=\"i8_prog\" offset=\"-20\">\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"gyyyrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"25\" state=\"grrrrrrrgGGGgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgyyygrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"31\" state=\"grrrrrrrgrrrgGGG\"/>\n",
      "      <phase duration=\"4\" state=\"grrrrrrrgrrrgGGy\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgGGr\"/>\n",
      "      <phase duration=\"13\" state=\"grrrGGGrgrrrgGGr\"/>\n",
      "      <phase duration=\"4\" state=\"grrrGGGrgrrrgyyr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrGGGrgrrrgrrr\"/>\n",
      "      <phase duration=\"53\" state=\"grrrGGGGgrrrgrrr\"/>\n",
      "      <phase duration=\"4\" state=\"grrryyyygrrrgrrr\"/>\n",
      "      <phase duration=\"1\" state=\"grrrrrrrgrrrgrrr\"/>\n",
      "      <phase duration=\"13\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"i9\" type=\"static\" programID=\"i9_prog\" offset=\"-40\">\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"109\" state=\"rrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"109\" state=\"rrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"109\" state=\"rrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"108\" state=\"rrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"110\" state=\"rrrr\"/>\n",
      "      <phase duration=\"4\" state=\"rrrr\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"41\" state=\"GGGG\"/>\n",
      "      <phase duration=\"4\" state=\"yyyy\"/>\n",
      "      <phase duration=\"1\" state=\"rrrr\"/>\n",
      "      <phase duration=\"109\" state=\"rrrr\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"u00\" type=\"static\" programID=\"u00_prog\" offset=\"-50\">\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggGgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggygggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"24\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"21\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrgggg\"/>\n",
      "      <phase duration=\"28\" state=\"ggggrgggg\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"u20\" type=\"static\" programID=\"u20_prog\" offset=\"-90\">\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"35\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"20\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"66\" state=\"ggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggrggg\"/>\n",
      "      <phase duration=\"29\" state=\"ggrggg\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"u30\" type=\"static\" programID=\"u30_prog\" offset=\"-50\">\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggGggg\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"u31\" type=\"static\" programID=\"u31_prog\" offset=\"-50\">\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"33\" state=\"ggggGggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggyggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"34\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"37\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"4\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"1\" state=\"ggggrggg\"/>\n",
      "      <phase duration=\"16\" state=\"ggggrggg\"/>\n",
      "    </tlLogic>\n",
      "    <tlLogic id=\"u32\" type=\"static\" programID=\"u32_prog\" offset=\"-50\">\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"33\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"34\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"37\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"4\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"1\" state=\"gggggggr\"/>\n",
      "      <phase duration=\"16\" state=\"gggggggr\"/>\n",
      "    </tlLogic>\n",
      "</additional>\n"
     ]
    }
   ],
   "source": [
    "offsets = {}\n",
    "SIGTABLE = []\n",
    "for node_id, group in Sigtable.groupby('node_id'):\n",
    "    lsbs = group[group['start_unix'] < sim_start]['start_unix'].max() # the last start_unix before sim_start\n",
    "    offsets[node_id] = lsbs - sim_start\n",
    "    group = group[(group['start_unix'] < sim_end) & (group['start_unix'] >= lsbs)]\n",
    "    SIGTABLE.append(group)\n",
    "SIGTABLE = pd.concat(SIGTABLE)\n",
    "\n",
    "strings = ['<additional>\\n']\n",
    "for node_id, group in Sigtable.groupby('node_id'):\n",
    "    strings.append(f'    <tlLogic id=\"{node_id}\" type=\"static\" programID=\"{node_id}_prog\" offset=\"{offsets[node_id]}\">\\n')\n",
    "    for i, row in group.iterrows():\n",
    "        duration = row.duration\n",
    "        state = row.state\n",
    "        strings.append(f'      <phase duration=\"{duration}\" state=\"{state}\"/>\\n')\n",
    "    strings.append('    </tlLogic>\\n')\n",
    "strings.append('</additional>')\n",
    "strings = ''.join(strings)\n",
    "# 저장\n",
    "path_output = '../../Data/networks/sn.add.xml'\n",
    "with open(path_output, 'w') as f:\n",
    "    f.write(strings)\n",
    "\n",
    "print(strings)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "rts",
   "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
