Skip to content

Commit

Permalink
Merge pull request #139 from TUDelft-CITG/fix/class-order
Browse files Browse the repository at this point in the history
fix old class orders in docs
  • Loading branch information
Fedor Baart authored Oct 16, 2023
2 parents 420f611 + 2a672ce commit 5e559c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
44 changes: 24 additions & 20 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,38 +26,40 @@ 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
v_empty = 5 # meters per second
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
.. _Jupyter Notebooks: https://github.com/TUDelft-CITG/OpenCLSim-Notebooks
13 changes: 7 additions & 6 deletions notebooks/02_MoveActivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
Expand Down Expand Up @@ -139,7 +140,7 @@
" \"compute_v\": lambda x: 10\n",
" }\n",
"# instantiate vessel_01 \n",
"vessel01 = TransportProcessingResource(**data_vessel01)"
"vessel01 = TransportProcessingResource(**data_vessel01)\n"
]
},
{
Expand Down Expand Up @@ -235,13 +236,13 @@
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>88ed2a20-c6ea-4e59-9671-459d6a313ae2</td>\n",
" <td>116be63e-1901-496a-9487-dcf5756e2e8f</td>\n",
" <td>1970-01-01 00:00:00.000000</td>\n",
" <td>START</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>88ed2a20-c6ea-4e59-9671-459d6a313ae2</td>\n",
" <td>116be63e-1901-496a-9487-dcf5756e2e8f</td>\n",
" <td>1970-01-01 00:15:42.824591</td>\n",
" <td>STOP</td>\n",
" </tr>\n",
Expand All @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions notebooks/03_ShiftAmountActivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@
" <th>Activity</th>\n",
" <th>Timestamp</th>\n",
" <th>ActivityState</th>\n",
" <th>geometry</th>\n",
" <th>container level</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
Expand All @@ -377,29 +377,29 @@
" <td>Shift amount activity</td>\n",
" <td>1970-01-01 00:00:00</td>\n",
" <td>START</td>\n",
" <td>POINT (4.18055556 52.18664444)</td>\n",
" <td>0.0</td>\n",
" <td>POINT (4.18055556 52.18664444)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Shift amount activity</td>\n",
" <td>1970-01-01 00:01:00</td>\n",
" <td>STOP</td>\n",
" <td>POINT (4.18055556 52.18664444)</td>\n",
" <td>5.0</td>\n",
" <td>POINT (4.18055556 52.18664444)</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": {},
Expand Down

0 comments on commit 5e559c4

Please sign in to comment.