From e5aa8337fd8be76f70c262c45fcb191223ba0a9c Mon Sep 17 00:00:00 2001
From: mvgijn <100591885+mvgijn@users.noreply.github.com>
Date: Thu, 12 May 2022 14:34:39 +0200
Subject: [PATCH] Made some improvements #41
Added some extra explanatory text to 'create graph' from example 10.
---
notebooks/Example 10 - Lock.ipynb | 94 +++++++++++++++++++++++++------
1 file changed, 78 insertions(+), 16 deletions(-)
diff --git a/notebooks/Example 10 - Lock.ipynb b/notebooks/Example 10 - Lock.ipynb
index 1d2a344f..bbf2cf89 100644
--- a/notebooks/Example 10 - Lock.ipynb
+++ b/notebooks/Example 10 - Lock.ipynb
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Locks real-world data\n",
+ "## Vessels passing a lock in a real-world example\n",
"In this example we will discuss how to implement an existing lock from real-world data in OpenTNSim and how to analyse specific locking output.\n",
"\n",
"We take the following steps:\n",
@@ -33,7 +33,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"metadata": {},
"outputs": [
{
@@ -51,7 +51,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -129,21 +129,48 @@
"```"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The shapefile `Vaarwegvakken.shp` is used as a basis for creating the graph for this simulation. To make things easier, the directory (location) of the shapefile is expressed as the variable `location_graph`. The name of the file is expressed as the variable `name_graph`. This will be used troughout the rest of the code. "
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 17,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\maxva\\AppData\\Local\\Temp\\ipykernel_2660\\554145821.py:2: DeprecationWarning:\n",
+ "\n",
+ "read_shp is deprecated and will be removed in 3.0.See https://networkx.org/documentation/latest/auto_examples/index.html#geospatial.\n",
+ "\n"
+ ]
+ }
+ ],
"source": [
+ "# Create a directed graph with single edges using read_shp\n",
"FG = nx.read_shp(os.path.join(location_graph, name_graph), simplify=True)\n",
"\n",
- "# The read_shp creates a directed graph with single edges\n",
"# We require a directed graph but two-way traffic\n",
"\n",
"FG = FG.to_undirected()\n",
"FG = FG.to_directed()"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### Convert to WGS84\n",
+ "\n",
+ "WGS84 is the latest version of the World Geodetic System. More information can be found [here](https://en.wikipedia.org/wiki/World_Geodetic_System)."
+ ]
+ },
{
"cell_type": "code",
"execution_count": 4,
@@ -193,6 +220,17 @@
"text": [
"Succes!\n"
]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "C:\\Users\\maxva\\AppData\\Local\\Temp\\ipykernel_2660\\848080082.py:32: DeprecationWarning:\n",
+ "\n",
+ "info is deprecated and will be removed in version 3.0.\n",
+ "\n",
+ "\n"
+ ]
}
],
"source": [
@@ -299,7 +337,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 21,
"metadata": {
"scrolled": false
},
@@ -307,13 +345,13 @@
{
"data": {
"text/html": [
- "
"
+ "Make this Notebook Trusted to load map: File -> Trust Notebook
"
],
"text/plain": [
- ""
+ ""
]
},
- "execution_count": 10,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
@@ -356,7 +394,7 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -383,7 +421,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -407,9 +445,21 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 16,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "KeyError",
+ "evalue": "'(4.430289, 51.700047)'",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_2660\\567025772.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;34m\"name\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"Vessel\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;34m\"route\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"(4.430289, 51.700047)\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"(4.392555, 51.681251)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;34m\"geometry\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mnx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_node_attributes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mFG_new\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"geometry\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"(4.430289, 51.700047)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \"capacity\": 1_000}\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mKeyError\u001b[0m: '(4.430289, 51.700047)'"
+ ]
+ }
+ ],
"source": [
"Vessel = type('Vessel', \n",
" (core.Identifiable, core.Movable, core.HasContainer, core.HasResource, core.Routeable), {})\n",
@@ -436,9 +486,21 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 15,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'data_vessel_one' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_2660\\3922957051.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mvessels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mvessel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mVessel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mdata_vessel_one\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mvessels\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvessel\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[0menv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mprocess\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvessel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'data_vessel_one' is not defined"
+ ]
+ }
+ ],
"source": [
"# Start simpy environment\n",
"env.FG = FG_new\n",
| |