{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"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>start_unix</th>\n",
|
|
" <th>node_id</th>\n",
|
|
" <th>dphase</th>\n",
|
|
" <th>dura</th>\n",
|
|
" <th>signal</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>grrgrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>32</td>\n",
|
|
" <td>gGGgrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>gyygrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>grrgrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>34</td>\n",
|
|
" <td>grrgGGGgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>grrgyyygrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>6</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>6</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>grrgrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>7</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>7</td>\n",
|
|
" <td>25</td>\n",
|
|
" <td>grrgrrrgGGgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>8</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>8</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>grrgrrrgyygrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>9</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>9</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>grrgrrrgrrgrrr</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>10</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>10</td>\n",
|
|
" <td>29</td>\n",
|
|
" <td>grrgrrrgrrgGGG</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>11</th>\n",
|
|
" <td>1704384400</td>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>11</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>grrgrrrgrrgyyy</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" start_unix node_id dphase dura signal\n",
|
|
"0 1704384400 i0 0 1 grrgrrrgrrgrrr\n",
|
|
"1 1704384400 i0 1 32 gGGgrrrgrrgrrr\n",
|
|
"2 1704384400 i0 2 4 gyygrrrgrrgrrr\n",
|
|
"3 1704384400 i0 3 1 grrgrrrgrrgrrr\n",
|
|
"4 1704384400 i0 4 34 grrgGGGgrrgrrr\n",
|
|
"5 1704384400 i0 5 4 grrgyyygrrgrrr\n",
|
|
"6 1704384400 i0 6 1 grrgrrrgrrgrrr\n",
|
|
"7 1704384400 i0 7 25 grrgrrrgGGgrrr\n",
|
|
"8 1704384400 i0 8 4 grrgrrrgyygrrr\n",
|
|
"9 1704384400 i0 9 1 grrgrrrgrrgrrr\n",
|
|
"10 1704384400 i0 10 29 grrgrrrgrrgGGG\n",
|
|
"11 1704384400 i0 11 4 grrgrrrgrrgyyy"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<tlLogics>\n",
|
|
" <tlLogic id=\"i0\" type=\"static\" programID=\"i0\" offset=\"999\">\n",
|
|
" <phase duration=\"1\" state=\"grrgrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"32\" state=\"gGGgrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"4\" state=\"gyygrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"1\" state=\"grrgrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"grrgGGGgrrgrrr\"/>\n",
|
|
" <phase duration=\"4\" state=\"grrgyyygrrgrrr\"/>\n",
|
|
" <phase duration=\"1\" state=\"grrgrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"25\" state=\"grrgrrrgGGgrrr\"/>\n",
|
|
" <phase duration=\"4\" state=\"grrgrrrgyygrrr\"/>\n",
|
|
" <phase duration=\"1\" state=\"grrgrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrgrrrgrrgGGG\"/>\n",
|
|
" <phase duration=\"4\" state=\"grrgrrrgrrgyyy\"/>\n",
|
|
" </tlLogic>\n",
|
|
"</tlLogics>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"path = 'one_cycle.csv'\n",
|
|
"df = pd.read_csv(path)\n",
|
|
"\n",
|
|
"# 적당히 지정하세요\n",
|
|
"node_id = df['node_id'][0]\n",
|
|
"offset = 999\n",
|
|
"\n",
|
|
"# xml양식대로 작성\n",
|
|
"strings = ['<tlLogics>\\n']\n",
|
|
"strings.append(f' <tlLogic id=\"{node_id}\" type=\"static\" programID=\"{node_id}\" offset=\"{offset}\">\\n')\n",
|
|
"for i, row in df.iterrows():\n",
|
|
" dur = row['dura']\n",
|
|
" state = row['signal']\n",
|
|
" strings.append(f' <phase duration=\"{dur}\" state=\"{state}\"/>\\n')\n",
|
|
"strings.append(' </tlLogic>\\n')\n",
|
|
"strings.append('</tlLogics>')\n",
|
|
"strings = ''.join(strings)\n",
|
|
"print(strings)\n",
|
|
"\n",
|
|
"# 저장\n",
|
|
"path_output = 'example.tll.xml'\n",
|
|
"with open(path_output, 'w') as f:\n",
|
|
" f.write(strings)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# netedit -s example.net.xml -i test.tll.xml"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"sumo_config_content = \"\"\"\n",
|
|
"<configuration>\n",
|
|
" <input>\n",
|
|
" <net-file value=\"example.net.xml\"/>\n",
|
|
" <additional-files value=\"test.tll.xml\"/>\n",
|
|
" <!-- <route-files value=\"your_routes.rou.xml\"/> -->\n",
|
|
" </input>\n",
|
|
" <time>\n",
|
|
" <begin value=\"0\"/>\n",
|
|
" <end value=\"3600\"/>\n",
|
|
" </time>\n",
|
|
"</configuration>\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"with open('your_configuration_file.sumocfg', 'w') as file:\n",
|
|
" file.write(sumo_config_content.strip())\n"
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|