Skip to content

Commit

Permalink
Merge pull request #112 from TUDelft-CITG/feature/opentnsim-sync-core…
Browse files Browse the repository at this point in the history
…-objects

Feature/opentnsim sync core objects
  • Loading branch information
SiggyF committed Nov 30, 2022
2 parents ed50e68 + 3b81212 commit 5524592
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ FROM python:3.9-slim
ARG GITHUB_TOKEN

# upgrade packages
RUN apt update && apt install -y git procps
RUN apt update && apt install -y git procps build-essential libgeos-dev libgeos-c1v5 libgeos-3.9.0

RUN pip install --upgrade pip

RUN pip install jupyter
Expand Down
24 changes: 19 additions & 5 deletions src/openclsim/core/locatable.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
"""Component to locate the simulation objects."""
from typing import Optional

import pyproj
import shapely.geometry
from shapely.geometry.base import BaseGeometry


class Locatable:
"""
Something with a geometry (geojson format).
Can be a point as well as a polygon
"""Something with a geometry (geojson format). Can be a point as well as a
polygon. The object can also be located on a graph (with a node). That requires the extra and optional
node attribute. Make sure to also update the geometry when sailing over graphs.
Parameters
----------
geometry : Shapely object
geometry : Shapely Geometry that determines the position of an object.
Coordinates are expected to be in wgs84 lon, lat.
node: Optional string that locates an object on a graph.
"""

def __init__(self, geometry, *args, **kwargs):
def __init__(
self, geometry: BaseGeometry, node: Optional[str] = None, *args, **kwargs
):
super().__init__(*args, **kwargs)
"""Initialization"""
self.geometry = geometry
# an optional node for locating an object on a network
self.node = node
# used for distance computation
self.wgs84 = pyproj.Geod(ellps="WGS84")

def is_at(self, locatable, tolerance=100):
Expand All @@ -34,4 +45,7 @@ def get_state(self):
state = super().get_state()

state.update({"geometry": self.geometry})
if self.node is not None:
state["node"] = self.node

return state
3 changes: 2 additions & 1 deletion tests/test_delay_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test package."""

import pytest
import shapely.geometry
import simpy

Expand Down Expand Up @@ -166,7 +167,7 @@ def test_delay_plugin():
model.register_processes([while_activity])
my_env.run()

assert my_env.now == 6354.357654924601
assert my_env.now == pytest.approx(6354.357654924601)
assert_log(while_activity)
assert_log(hopper)
assert_log(from_site)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_move_activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test package."""

import pytest
import shapely.geometry
import simpy

Expand Down Expand Up @@ -74,7 +75,7 @@ def test_move_activity():
model.register_processes([activity])
my_env.run()

assert my_env.now == 942.8245912734186
assert my_env.now == pytest.approx(942.8245912734186)
assert_log(activity)
assert_log(hopper)
assert_log(to_site)
3 changes: 2 additions & 1 deletion tests/test_wraped_single_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test package."""
import pytest
import shapely.geometry
import simpy

Expand Down Expand Up @@ -88,7 +89,7 @@ def test_wraped_single_run():
model.register_processes([while_activity])
my_env.run()

assert my_env.now == 13699.734162066252
assert my_env.now == pytest.approx(13699.734162066252)

assert_log(hopper)
assert_log(from_site)
Expand Down

0 comments on commit 5524592

Please sign in to comment.