Skip to content

Commit

Permalink
temporary performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperg3 committed Aug 12, 2024
1 parent fd32796 commit d5f7e67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
26 changes: 13 additions & 13 deletions DemaScenarios/task_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion trajallocpy/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ 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


@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
Expand Down

0 comments on commit d5f7e67

Please sign in to comment.