Skip to content

Commit

Permalink
Changed coverage problem input
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperg3 committed Aug 29, 2024
1 parent 20b6136 commit 71432c6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
17 changes: 5 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from shapely.affinity import scale, translate
from shapely.ops import transform

from trajallocpy import Agent, CoverageProblem, Experiment, Utility
from trajallocpy import Agent, CoverageProblem, Experiment, Task, Utility


def saveResults(experiment_title, results, directory="experiments/"):
Expand Down Expand Up @@ -98,11 +98,14 @@ def run_experiment(experiment_title, n_agents, capacity, show_plots, debug, resu

# Create a new MultiPolygon with scaled polygons
scaled_multi_polygon = shapely.geometry.MultiPolygon(scaled_polygons)
task_list = []
for id, task in enumerate(geometries["tasks"].geoms):
task_list.append(Task.TrajectoryTask(id, task))

cp = CoverageProblem.CoverageProblem(
restricted_areas=scaled_multi_polygon,
search_area=geometries["boundary"],
tasks=geometries["tasks"],
tasks=task_list,
)

initial = cp.generate_random_point_in_problem().coords.xy
Expand All @@ -114,16 +117,6 @@ def run_experiment(experiment_title, n_agents, capacity, show_plots, debug, resu

exp.solve(profiling_enabled=False, debug=debug)

# TODO rewrite this as a function
# if export:
# temp = []
# for agent_id, route in allocations.items():
# new_route = []
# for coordinate in route:
# new_route.append((coordinate[0] + min_x, coordinate[1] + min_y))
# temp.append(new_route)
# open("allocations.json", "w").write(geojson.dumps({"routes": temp}))

# Save the results in a csv file
(
totalRouteLength,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "trajallocpy"
version = "0.0.11"
version = "0.0.12"
description = "TrajAllocPy is a Python library that provides functionality for trajectory task Allocaition using Consensus based bundle algorithm"
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="trajallocpy",
version="0.0.11",
version="0.0.12",
description="TrajAllocPy is a Python library that provides functionality for trajectory task Allocation using Consensus based bundle algorithm",
long_description="",
long_description_content_type="text/markdown",
Expand Down
9 changes: 3 additions & 6 deletions trajallocpy/CoverageProblem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
from typing import List

import shapely.geometry
from extremitypathfinder import PolygonEnvironment
Expand All @@ -9,7 +10,7 @@
class CoverageProblem:
def __init__(
self,
tasks,
tasks: List[Task.TrajectoryTask],
search_area: shapely.Polygon,
restricted_areas: shapely.geometry.MultiPolygon,
):
Expand All @@ -26,11 +27,7 @@ def __init__(

self.environment.store(list(shapely.geometry.polygon.orient(search_area, 1.0).exterior.coords[:-1]), holes, validate=False)

task_list = []
for id, trajectory in enumerate(tasks.geoms):
task_list.append(Task.TrajectoryTask(id, trajectory))

self.__tasks = task_list
self.__tasks = tasks

def getRestrictedAreas(self):
return self.__restricted_areas
Expand Down

0 comments on commit 71432c6

Please # to comment.