Skip to content

Commit

Permalink
Picked the right notebooks #41
Browse files Browse the repository at this point in the history
Also applied the same lay-out/ formatting for all 4 notebooks as described by Mark.
  • Loading branch information
mvgijn committed May 11, 2022
1 parent c36864f commit 670ab75
Show file tree
Hide file tree
Showing 2 changed files with 975 additions and 181 deletions.
156 changes: 34 additions & 122 deletions notebooks/Example 10 - Lock.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Locks real-world data"
"## Locks real-world data\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",
"\n",
"1. [Imports](#1-imports)\n",
"2. [Create graph](#2-create-graph)\n",
"3. [Create locks](#3-create-locks)\n",
"4. [Create vessel](#4-create-vessel)\n",
"4. [Run simulation](#5-run-simulation)\n",
"5. [Inspect output](#6-inspect-ouput)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Imports"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imports\n",
"Import the required libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -35,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -88,7 +104,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create graph"
"### 2. Create graph"
]
},
{
Expand Down Expand Up @@ -219,7 +235,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Select only relevant area"
"#### Select only relevant area"
]
},
{
Expand Down Expand Up @@ -278,7 +294,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Show on map"
"#### Show on map"
]
},
{
Expand Down Expand Up @@ -327,7 +343,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create locks\n",
"### 3. Create locks\n",
"We can see on the maps that there are three locks on the graph, but that the information on the locks is limited. The following edges represent locks:\n",
"\n",
"- Voorhavens Jachtensluis\n",
Expand Down Expand Up @@ -386,7 +402,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Make vessels and paths"
"### 4. Create vessel"
]
},
{
Expand Down Expand Up @@ -415,7 +431,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Start simulation"
"### 5. Run simulation"
]
},
{
Expand All @@ -442,6 +458,13 @@
"env.run()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6. Inspect ouput"
]
},
{
"cell_type": "code",
"execution_count": 15,
Expand Down Expand Up @@ -747,20 +770,6 @@
"pd.DataFrame.from_dict(lock_nr_1.log).head(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 18,
Expand Down Expand Up @@ -1047,103 +1056,6 @@
"# Tenth ship should be the first one the start waiting to enter the waiting area\n",
"pd.DataFrame.from_dict(vessels[9].log)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Visualize sailed path\n",
"https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Plugins.ipynb#Timestamped-GeoJSON"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1, 0\n",
"[<PriorityRequest() object at 0x1b11a0b7320>, <PriorityRequest() object at 0x1b11a0b7208>, <PriorityRequest() object at 0x1b11a0b74a8>, <PriorityRequest() object at 0x1b11a0b7470>]\n",
"\n",
"5, -1\n",
"[<PriorityRequest() object at 0x1b11a0b7208>, <PriorityRequest() object at 0x1b11a0b74a8>, <PriorityRequest() object at 0x1b11a0b7470>]\n",
"\n",
"2, -0.6266180102112903\n",
"[<PriorityRequest() object at 0x1b11a0b74a8>, <PriorityRequest() object at 0x1b11a0b7470>]\n",
"\n",
"3, -0.7535128117883658\n",
"[<PriorityRequest() object at 0x1b11a0b7470>]\n",
"\n",
"4, -0.3062137446940345\n",
"[]\n",
"\n"
]
}
],
"source": [
"import random\n",
"def resource_user(name, env, resource, prio):\n",
" req = resource.request(priority=prio)\n",
"\n",
" yield req\n",
" print(\"{}, {}\".format(name, req.priority))\n",
" yield env.timeout(3)\n",
" resource.release(req)\n",
" \n",
" for i in resource.queue:\n",
" if env.now - 4 > i.time:\n",
" i.priority = -random.random()\n",
" \n",
" print(resource.queue)\n",
" print(\"\")\n",
"\n",
"env = simpy.Environment()\n",
"res = simpy.PriorityResource(env, capacity=1)\n",
"p1 = env.process(resource_user(1, env, res, prio=0))\n",
"p2 = env.process(resource_user(2, env, res, prio=0))\n",
"p3 = env.process(resource_user(3, env, res, prio=0))\n",
"p4 = env.process(resource_user(4, env, res, prio=0))\n",
"p5 = env.process(resource_user(5, env, res, prio=-1))\n",
"env.run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -1162,7 +1074,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 670ab75

Please sign in to comment.