forked from AtsushiSakai/PythonRobotics
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseClasses.py
More file actions
50 lines (43 loc) · 1.33 KB
/
BaseClasses.py
File metadata and controls
50 lines (43 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from abc import ABC, abstractmethod
from dataclasses import dataclass
import math
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
Grid,
Position,
)
from PathPlanning.TimeBasedPathPlanning.Node import NodePath
import random
import numpy.random as numpy_random
# Seed randomness for reproducibility
RANDOM_SEED = 50
random.seed(RANDOM_SEED)
numpy_random.seed(RANDOM_SEED)
class SingleAgentPlanner(ABC):
"""
Base class for single agent planners
"""
@staticmethod
@abstractmethod
def plan(grid: Grid, start: Position, goal: Position, verbose: bool = False) -> NodePath:
pass
@dataclass
class StartAndGoal:
# Index of this agent
index: int
# Start position of the robot
start: Position
# Goal position of the robot
goal: Position
def distance_start_to_goal(self) -> float:
return pow(self.goal.x - self.start.x, 2) + pow(self.goal.y - self.start.y, 2)
class MultiAgentPlanner(ABC):
"""
Base class for multi-agent planners
"""
@staticmethod
@abstractmethod
def plan(grid: Grid, start_and_goal_positions: list[StartAndGoal], verbose: bool = False) -> list[NodePath]:
"""
Plan for all agents. Returned paths are in the order of the `StartAndGoal` list this object was instantiated with
"""
pass