Skip to content

Commit

Permalink
Corrected solution produced by the solver
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperg3 committed Aug 27, 2024
1 parent 4456322 commit 3a18f3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion trajallocpy/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ def getDistance(start, end, environment=None):

def getTravelPath(position, assigned_tasks, environment):
full_path = []
travel_paths = []
if len(assigned_tasks) > 0:
path, dist = environment.find_shortest_path(position, assigned_tasks[0].start, free_space_after=False, verify=False)
full_path.extend(path)
for i in range(len(assigned_tasks) - 1):
full_path.extend(assigned_tasks[i].trajectory.coords)
path, dist = environment.find_shortest_path(assigned_tasks[i].end, assigned_tasks[i + 1].start, free_space_after=False, verify=False)
full_path.extend(path)
travel_paths.append(path)
full_path.extend(assigned_tasks[-1].trajectory.coords)
return full_path
return full_path, travel_paths


@cache
Expand Down
13 changes: 8 additions & 5 deletions trajallocpy/Experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def __init__(self, coverage_problem: CoverageProblem.CoverageProblem, agents: li
self.communication_graph = np.ones((len(agents), len(agents)))
self.plot = enable_plotting

# Results
self.routes = {}
self.transport = {}
self.tasks = {}

def evaluateSolution(self):
total_path_length = 0
total_task_length = 0
Expand Down Expand Up @@ -196,17 +201,15 @@ def solve(self, profiling_enabled=False, debug=False):

self.end_time = timeit.default_timer()

# print("Robot Routes")
routes = {}
# Save the results in the object
for robot in self.robot_list.values():
routes[robot.id] = robot.getPathTasks()
self.routes[robot.id], self.transport[robot.id] = Agent.getTravelPath(robot.state, robot.getPathTasks(), robot.environment)
self.tasks[robot.id] = [[coord for coord in task.trajectory.coords] for task in robot.getPathTasks()]

# print(routes)
if self.plot:
plotter.plotAgents(self.robot_list.values())
if self.plot:
plotter.show()
return routes


# TODO refactor the experiment class, to provide utility to perform replanning.
Expand Down
2 changes: 1 addition & 1 deletion trajallocpy/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def plotAgents(self, robot_list: list[CBBA.agent]):
def plotAgent(self, robot: CBBA.agent, total_number_of_robots):
task_x = []
task_y = []
p = Agent.getTravelPath(robot.state, robot.getPathTasks(), robot.environment)
p, _ = Agent.getTravelPath(robot.state, robot.getPathTasks(), robot.environment)

for s in p:
task_x.append(s[0])
Expand Down

0 comments on commit 3a18f3d

Please # to comment.