-
Notifications
You must be signed in to change notification settings - Fork 1
/
robotgroup.py
41 lines (30 loc) · 1.06 KB
/
robotgroup.py
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
from abc import abstractmethod
from core.deeco import EnsembleDefinition, BaseKnowledge
from core.deeco import Role
from core.position import Position
from robot import Robot
# Role
class Group(Role):
def __init__(self):
super().__init__()
self.center = None
self.members = []
class RobotGroup(EnsembleDefinition):
class RobotGroupKnowledge(BaseKnowledge, Group):
def __init__(self):
super().__init__()
def __str__(self):
return self.__class__.__name__ + " centered at " + str(self.center) + " with component ids " + str(list(map(lambda x: x.id, self.members)))
def fitness(self, a: Robot.Knowledge, b: Robot.Knowledge):
return 1 / a.position.dist_to(b.position)
def membership(self, a: Robot, b: Robot):
assert type(a) == Robot.Knowledge
assert type(b) == Robot.Knowledge
return True
def knowledge(self, a: Robot.Knowledge, b: Robot.Knowledge):
knowledge = self.RobotGroupKnowledge()
knowledge.center = Position.average(a.position, b.position)
knowledge.members = [a, b]
return knowledge
def __str__(self):
return self.__class__.__name__