diff --git a/DemaScenarios/task_generator.py b/DemaScenarios/task_generator.py index f9812da..a9411c5 100644 --- a/DemaScenarios/task_generator.py +++ b/DemaScenarios/task_generator.py @@ -48,9 +48,9 @@ def export_to_geojson(tasks: GeoMultiTrajectory, polygon: GeoPolygon): import osmnx as ox if __name__ == "__main__": - # polygon_file = "examples/DemaScenarios/FlatTerrainNature.geojson" - # polygon_file = "examples/DemaScenarios/HillyTerrainNature.geojson" - # polygon_file = "examples/DemaScenarios/Urban.geojson" + # polygon_file = "DemaScenarios/FlatTerrainNature.geojson" + # polygon_file = "DemaScenarios/HillyTerrainNature.geojson" + # polygon_file = "DemaScenarios/Urban.geojson" polygon_file = "DemaScenarios/Water.geojson" # Load the GeoJSON data @@ -61,24 +61,24 @@ def export_to_geojson(tasks: GeoMultiTrajectory, polygon: GeoPolygon): coordinates = data["features"][0]["geometry"]["coordinates"][0] # Create the shapely Polygon object - polygon = GeoPolygon(shapely.Polygon(coordinates)).set_crs("EPSG:2197") + polygon = GeoPolygon(shapely.Polygon(coordinates)).set_crs("EPSG:4093") polygon.plot(facecolor="none", edgecolor="black", linewidth=2) query_polygon = GeoPolygon(shapely.Polygon(coordinates)).set_crs("WGS84") - features = query_features( - query_polygon, - { - "natural": ["coastline"], - }, - ) - GeoMultiTrajectory(features["natural"]).set_crs("EPSG:2197").plot(color="blue", linewidth=2) + # features = query_features( + # query_polygon, + # { + # "natural": ["coastline"], + # }, + # ) + # GeoMultiTrajectory(features["natural"]).set_crs("EPSG:4093").plot(color="blue", linewidth=2) tasks = get_line_segments(polygon) - multi_traj = GeoMultiTrajectory(tasks, "EPSG:2197") + multi_traj = GeoMultiTrajectory(tasks, "EPSG:4093") multi_traj.plot(color="red") - Utils.plot_basemap(provider=cx.providers.OpenStreetMap.Mapnik, crs="EPSG:2197") + Utils.plot_basemap(provider=cx.providers.OpenStreetMap.Mapnik, crs="EPSG:4093") export_to_geojson(multi_traj, polygon) # No axis on the plot diff --git a/trajallocpy/Agent.py b/trajallocpy/Agent.py index c2a22c1..ee5366a 100644 --- a/trajallocpy/Agent.py +++ b/trajallocpy/Agent.py @@ -37,7 +37,6 @@ class BidInformation: def distanceToCost(dist, max_velocity=3, max_acceleration=1): - # Velocity ramp d_a = (max_velocity**2) / max_acceleration result = math.sqrt(4 * dist / max_acceleration) if dist < d_a else max_velocity / max_acceleration + dist / max_velocity return result @@ -45,6 +44,10 @@ def distanceToCost(dist, max_velocity=3, max_acceleration=1): @cache def getDistance(start, end, environment=None): + # TODO this is a temporary fix for improving the performance of the code + dist = [(a - b) ** 2 for a, b in zip(start, end)] + dist = math.sqrt(sum(dist)) + return dist # If there is no environment defined, use euclidean if environment is None: # This is a optimised way of calculating euclidean distance: https://stackoverflow.com/questions/37794849/efficient-and-precise-calculation-of-the-euclidean-distance