Skip to content

Commit 224dd3b

Browse files
committed
some cleanup
1 parent d722adc commit 224dd3b

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

PathPlanning/TimeBasedPathPlanning/BaseClasses.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
from abc import ABC, abstractmethod
2+
from dataclasses import dataclass
3+
import math
14
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
25
Grid,
36
Position,
47
)
58
from PathPlanning.TimeBasedPathPlanning.Node import NodePath
69
import random
710
import numpy.random as numpy_random
8-
from abc import ABC, abstractmethod
9-
from dataclasses import dataclass
1011

1112
# Seed randomness for reproducibility
1213
RANDOM_SEED = 50
@@ -32,6 +33,9 @@ class StartAndGoal:
3233
# Goal position of the robot
3334
goal: Position
3435

36+
def distance_start_to_goal(self) -> float:
37+
return pow(self.goal.x - self.start.x, 2) + pow(self.goal.y - self.start.y, 2)
38+
3539
class MultiAgentPlanner(ABC):
3640
"""
3741
Base class for multi-agent planners

PathPlanning/TimeBasedPathPlanning/Plotting.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[N
105105

106106
# Update each agent's position
107107
for (j, path) in enumerate(paths):
108+
path_postitions = []
108109
if i <= path.goal_reached_time():
109110
res = path.get_position(i)
110111
if not res:
111112
print(path)
112113
print(i)
113114
path_position = path.get_position(i)
115+
116+
# Verify position is valid
117+
assert not path_position in obs_positions
118+
assert not path_position in path_postitions
119+
path_postitions.append(path_position)
120+
114121
path_plots[j].set_data([path_position.x], [path_position.y])
115122

116123
plt.pause(0.2)

PathPlanning/TimeBasedPathPlanning/PriorityBasedPlanner.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
2-
TODO - doc comment
2+
Priority Based Planner for multi agent path planning.
3+
The planner generates an order to plan in, and generates plans for the robots in that order. Each planned
4+
path is reserved in the grid, and all future plans must avoid that path.
35
4-
sort of outlined in this paper: https://pure.tudelft.nl/ws/portalfiles/portal/67074672/07138650.pdf
5-
better paper: https://people.csail.mit.edu/tlp/publications/01087401.pdf
6+
Algorithm outlined in section III of this paper: https://pure.tudelft.nl/ws/portalfiles/portal/67074672/07138650.pdf
67
"""
78

89
import numpy as np
@@ -16,21 +17,24 @@
1617
from PathPlanning.TimeBasedPathPlanning.Node import NodePath
1718
from PathPlanning.TimeBasedPathPlanning.BaseClasses import SingleAgentPlanner
1819
from PathPlanning.TimeBasedPathPlanning.SafeInterval import SafeIntervalPathPlanner
19-
from PathPlanning.TimeBasedPathPlanning.SpaceTimeAStar import SpaceTimeAStar
2020
from PathPlanning.TimeBasedPathPlanning.Plotting import PlotNodePaths
2121
import time
2222

2323
class PriorityBasedPlanner(MultiAgentPlanner):
2424

25-
def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_class: SingleAgentPlanner, verbose: bool) -> list[NodePath]: # TODO: list of what
25+
def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_class: SingleAgentPlanner, verbose: bool) -> list[NodePath]:
2626

2727
print(f"Using planner: {single_agent_planner_class}")
2828

2929
# Reserve initial positions
3030
for start_and_goal in start_and_goals:
3131
grid.reserve_position(start_and_goal.start, start_and_goal.index, Interval(0, 10))
3232

33-
# TODO: smarter ordering
33+
# Plan in descending order of distance from start to goal
34+
start_and_goals = sorted(start_and_goals,
35+
key=lambda item: item.distance_start_to_goal(),
36+
reverse=True)
37+
3438
paths = []
3539
for start_and_goal in start_and_goals:
3640
if True:

0 commit comments

Comments
 (0)