-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathBaseClasses.py
More file actions
50 lines (43 loc) · 1.4 KB
/
BaseClasses.py
File metadata and controls
50 lines (43 loc) · 1.4 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
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
Grid,
Position,
)
from PathPlanning.TimeBasedPathPlanning.ConstraintTree import AgentId
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, agent_idx: AgentId, verbose: bool = False) -> NodePath:
pass
@dataclass
class StartAndGoal:
# Index of this agent
agent_id: AgentId
# 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], single_agent_planner_class: SingleAgentPlanner, verbose: bool = False) -> dict[AgentId, NodePath]:
"""
Plan for all agents. Returned paths found for each agent
"""
pass