From 8bf38aec8dc23f5c6b4d45f4aa47c57101aaeca3 Mon Sep 17 00:00:00 2001 From: Fedor Baart Date: Sun, 9 Jul 2023 14:23:04 +0200 Subject: [PATCH] fix old class orders in docs --- docs/usage.rst | 44 ++++++++++++++------------ notebooks/02_MoveActivity.ipynb | 13 ++++---- notebooks/03_ShiftAmountActivity.ipynb | 18 +++++------ 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 86d47b9d..29393889 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -9,13 +9,15 @@ Import required components To use OpenCLSim in a project you have to import the following three components: .. code:: python3 + # Import simpy for the simulation environment + import simpy + # Shapely for geometries + import shapely # Import openclsim for the logistical components import openclsim.model as model import openclsim.core as core - # Import simpy for the simulation environment - import simpy Using Mixins and Metaclasses @@ -24,17 +26,19 @@ Using Mixins and Metaclasses The Open Complex Logistics Simulation package is developed with the goal of reusable and generic components in mind. A new class can be instatiated by combining mixins from the *openclsim.core*, such as presented below. The following lines of code demonstrate how a containervessel can be defined: .. code:: python3 - # Define the core components # A generic class for an object that can move and transport material - ContainerVessel = type('ContainerVessel', - (core.Identifiable, # Give it a name and unique UUID - core.Log, # Allow logging of all discrete events - core.ContainerDependentMovable,# It can transport an amount - core.HasResource, # Add information on serving equipment - ), - {}) - + ContainerVessel = type( + 'ContainerVessel', + ( + core.ContainerDependentMovable,# It can transport an amount + core.HasResource, # Add information on serving equipment + core.Identifiable, # Give it a name and unique UUID + core.Log, # Allow logging of all discrete events + ), + {} + ) + # The next step is to define all the required parameters for the defined metaclass # For more realistic simulation you might want to have speed dependent on the filling degree v_full = 8 # meters per second @@ -42,20 +46,20 @@ The Open Complex Logistics Simulation package is developed with the goal of reus def variable_speed(v_empty, v_full): return lambda x: x * (v_full - v_empty) + v_empty - + # Other variables data_vessel = { - "env": simpy.Environment(), # The simpy environment - "name": "Vessel 01", # Name - "geometry": shapely.geometry.Point(0, 0), # The lat, lon coordinates - "capacity": 5_000, # Capacity of the vessel - "compute_v": variable_speed(v_empty, v_full), # Variable speed - } - + "env": simpy.Environment(), # The simpy environment + "name": "Vessel 01", # Name + "geometry": shapely.geometry.Point(0, 0), # The lat, lon coordinates + "capacity": 5_000, # Capacity of the vessel + "compute_v": variable_speed(v_empty, v_full), # Variable speed + } + # Create an object based on the metaclass and vessel data vessel_01 = ContainerVessel(**data_vessel) For more elaboration and examples please check the `examples`_ documentation. In-depth `Jupyter Notebooks`_ can also be used. .. _examples: https://openclsim.readthedocs.io/en/latest/examples -.. _Jupyter Notebooks: https://github.com/TUDelft-CITG/OpenCLSim-Notebooks \ No newline at end of file +.. _Jupyter Notebooks: https://github.com/TUDelft-CITG/OpenCLSim-Notebooks diff --git a/notebooks/02_MoveActivity.ipynb b/notebooks/02_MoveActivity.ipynb index 64161113..bd3d9543 100644 --- a/notebooks/02_MoveActivity.ipynb +++ b/notebooks/02_MoveActivity.ipynb @@ -81,9 +81,10 @@ "TransportProcessingResource = type(\n", " \"TransportProcessingResource\",\n", " (\n", - " core.HasResource,\n", " core.Processor,\n", " core.ContainerDependentMovable,\n", + " core.Identifiable,\n", + " core.HasResource,\n", " ),\n", " {},\n", ")" @@ -139,7 +140,7 @@ " \"compute_v\": lambda x: 10\n", " }\n", "# instantiate vessel_01 \n", - "vessel01 = TransportProcessingResource(**data_vessel01)" + "vessel01 = TransportProcessingResource(**data_vessel01)\n" ] }, { @@ -235,13 +236,13 @@ " \n", " \n", " 0\n", - " 88ed2a20-c6ea-4e59-9671-459d6a313ae2\n", + " 116be63e-1901-496a-9487-dcf5756e2e8f\n", " 1970-01-01 00:00:00.000000\n", " START\n", " \n", " \n", " 1\n", - " 88ed2a20-c6ea-4e59-9671-459d6a313ae2\n", + " 116be63e-1901-496a-9487-dcf5756e2e8f\n", " 1970-01-01 00:15:42.824591\n", " STOP\n", " \n", @@ -251,8 +252,8 @@ ], "text/plain": [ " Activity Timestamp \\\n", - "0 88ed2a20-c6ea-4e59-9671-459d6a313ae2 1970-01-01 00:00:00.000000 \n", - "1 88ed2a20-c6ea-4e59-9671-459d6a313ae2 1970-01-01 00:15:42.824591 \n", + "0 116be63e-1901-496a-9487-dcf5756e2e8f 1970-01-01 00:00:00.000000 \n", + "1 116be63e-1901-496a-9487-dcf5756e2e8f 1970-01-01 00:15:42.824591 \n", "\n", " ActivityState \n", "0 START \n", diff --git a/notebooks/03_ShiftAmountActivity.ipynb b/notebooks/03_ShiftAmountActivity.ipynb index 6ee0c5c3..7288062f 100644 --- a/notebooks/03_ShiftAmountActivity.ipynb +++ b/notebooks/03_ShiftAmountActivity.ipynb @@ -367,8 +367,8 @@ " Activity\n", " Timestamp\n", " ActivityState\n", - " geometry\n", " container level\n", + " geometry\n", " \n", " \n", " \n", @@ -377,29 +377,29 @@ " Shift amount activity\n", " 1970-01-01 00:00:00\n", " START\n", - " POINT (4.18055556 52.18664444)\n", " 0.0\n", + " POINT (4.18055556 52.18664444)\n", " \n", " \n", " 1\n", " Shift amount activity\n", " 1970-01-01 00:01:00\n", " STOP\n", - " POINT (4.18055556 52.18664444)\n", " 5.0\n", + " POINT (4.18055556 52.18664444)\n", " \n", " \n", "\n", "" ], "text/plain": [ - " Activity Timestamp ActivityState \\\n", - "0 Shift amount activity 1970-01-01 00:00:00 START \n", - "1 Shift amount activity 1970-01-01 00:01:00 STOP \n", + " Activity Timestamp ActivityState container level \\\n", + "0 Shift amount activity 1970-01-01 00:00:00 START 0.0 \n", + "1 Shift amount activity 1970-01-01 00:01:00 STOP 5.0 \n", "\n", - " geometry container level \n", - "0 POINT (4.18055556 52.18664444) 0.0 \n", - "1 POINT (4.18055556 52.18664444) 5.0 " + " geometry \n", + "0 POINT (4.18055556 52.18664444) \n", + "1 POINT (4.18055556 52.18664444) " ] }, "metadata": {},