Skip to content

Commit

Permalink
Merge pull request #63 from TUDelft-CITG/feature/floor-lock-module
Browse files Browse the repository at this point in the history
Merge Floor's lock module
  • Loading branch information
SiggyF committed Mar 29, 2024
2 parents eea5af4 + 4a343c5 commit d2c3697
Show file tree
Hide file tree
Showing 13 changed files with 3,895 additions and 2,549 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Build docs
command: |
docker exec -it opentnsim bash -c "pip install sphinx"
docker exec -it opentnsim bash -c "python setup.py docs"
docker exec -it opentnsim bash -c "sphinx-build -b html docs docs/_build/html"
docker cp opentnsim:/OpenTNSim/docs/_build/html /tmp/artifacts/docs
- run:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/azure-static-web-apps-happy-bush-0c5d10603.yml
Expand Up @@ -4,10 +4,12 @@ on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
- feature/book
# # disable PR due to site limit @ azure
# pull_request:
# types: [opened, synchronize, reopened, closed]
# branches:
# - master

jobs:
build_and_deploy_job:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -75,3 +75,5 @@ MANIFEST
*.mp4
*.kml
.vscode/settings.json
notebooks/Port_of_Rotterdam/geospatial_data
notebooks/Port_of_Rotterdam
1,485 changes: 0 additions & 1,485 deletions notebooks/Example 17 - Lock.ipynb

This file was deleted.

34 changes: 29 additions & 5 deletions opentnsim/core.py
Expand Up @@ -163,8 +163,6 @@ class VesselProperties:
- renewable_fuel_required_space: renewable fuel required storage space (consider packaging factor) on board [m3]
"""

# TODO: add blockage factor S to vessel properties

def __init__(
self,
type,
Expand Down Expand Up @@ -319,13 +317,27 @@ def __init__(self, route, complete_path=None, *args, **kwargs):

@property
def graph(self):
"""
Return the graph of the underlying environment.
If it's multigraph cast to corresponding type
If you want the multidigraph use the HasMultiGraph mixin
"""
graph = None
if hasattr(self.env, "graph"):
return self.env.graph
graph = self.env.graph
elif hasattr(self.env, "FG"):
return self.env.FG
graph = self.env.FG
else:
raise ValueError("Routable expects .graph to be present on env")

if isinstance(graph, nx.MultiDiGraph):
return nx.DiGraph(graph)
elif isinstance(graph, nx.MultiGraph):
return nx.Graph(graph)
return graph


@deprecated.deprecated(reason="Use Routable instead of Routeable")
class Routeable(Routable):
Expand All @@ -347,6 +359,7 @@ def __init__(self, v: float, *args, **kwargs):
self.v = v
super().__init__(*args, **kwargs)
self.on_pass_edge_functions = []
self.on_pass_node_functions = []
self.wgs84 = pyproj.Geod(ellps="WGS84")

def move(self, destination: Union[Locatable, Geometry, str] = None, engine_order: float = 1.0, duration: float = None):
Expand Down Expand Up @@ -389,9 +402,15 @@ def move(self, destination: Union[Locatable, Geometry, str] = None, engine_order
# name it a, b here, to avoid confusion with destination argument
a, b = edge

node = a

yield from self.pass_node(node)

# we are now at the node
self.node = node

# update to current position
self.geometry = nx.get_node_attributes(self.graph, "geometry")[a]
self.node = a
self.position_on_route = i

# are we already at destination?
Expand All @@ -418,6 +437,11 @@ def move(self, destination: Union[Locatable, Geometry, str] = None, engine_order
else:
logger.debug(" current_speed: not set")

def pass_node(self, node):
# call all on_pass_node_functions
for on_pass_node_function in self.on_pass_node_functions:
yield from on_pass_node_function(node)

def pass_edge(self, origin, destination):
edge = self.graph.edges[origin, destination]
orig = nx.get_node_attributes(self.graph, "geometry")[origin]
Expand Down

0 comments on commit d2c3697

Please sign in to comment.