|
@@ -4,29 +4,44 @@ from intelligine.simulation.pheromone.Pheromone import Pheromone
|
4
|
4
|
|
5
|
5
|
class PheromoneFlavour():
|
6
|
6
|
|
7
|
|
- def __init__(self, point_data):
|
8
|
|
- self._point_data = point_data
|
|
7
|
+ @classmethod
|
|
8
|
+ def new_from_raw_data(cls, raw_data):
|
|
9
|
+ flavour = {}
|
|
10
|
+ for category in raw_data:
|
|
11
|
+ pheromones_by_category = raw_data[category]
|
|
12
|
+ for type in pheromones_by_category:
|
|
13
|
+ distance, intensity = pheromones_by_category[type]
|
|
14
|
+ flavour.update({category: {type: Pheromone(category, type, distance, intensity)}})
|
|
15
|
+ return cls(flavour)
|
|
16
|
+
|
|
17
|
+ def get_raw_data(self):
|
|
18
|
+ raw_data = {}
|
|
19
|
+ for category in self._flavour:
|
|
20
|
+ pheromones_by_category = self._flavour[category]
|
|
21
|
+ for type in pheromones_by_category:
|
|
22
|
+ pheromone = pheromones_by_category[type]
|
|
23
|
+ raw_data.update({category: {type: (pheromone.get_distance(), pheromone.get_intensity())}})
|
|
24
|
+ return raw_data
|
|
25
|
+
|
|
26
|
+ def __init__(self, flavour):
|
|
27
|
+ self._flavour = flavour
|
9
|
28
|
|
10
|
29
|
def get_pheromone(self, category, type):
|
11
|
30
|
types = self.get_types(category)
|
12
|
31
|
if type not in types:
|
13
|
32
|
raise NoTypeInPheromone()
|
14
|
|
- distance, intensity = types[type]
|
15
|
|
- return Pheromone(category, type, distance, intensity)
|
|
33
|
+ return types[type]
|
16
|
34
|
|
17
|
35
|
def get_types(self, category):
|
18
|
|
- if category not in self._point_data:
|
|
36
|
+ if category not in self._flavour:
|
19
|
37
|
raise NoCategoryInPheromone()
|
20
|
|
- return self._point_data[category]
|
|
38
|
+ return self._flavour[category]
|
21
|
39
|
|
22
|
|
- def update_pheromone(self, pheromone):
|
|
40
|
+ def set_pheromone(self, pheromone):
|
23
|
41
|
category = pheromone.get_category()
|
24
|
42
|
type = pheromone.get_type()
|
25
|
43
|
|
26
|
|
- if category not in self._point_data:
|
27
|
|
- self._point_data[category] = {}
|
|
44
|
+ if category not in self._flavour:
|
|
45
|
+ self._flavour[category] = {}
|
28
|
46
|
|
29
|
|
- self._point_data[category][type] = (pheromone.get_distance(), pheromone.get_intensity())
|
30
|
|
-
|
31
|
|
- def get_raw_data(self):
|
32
|
|
- return self._point_data
|
|
47
|
+ self._flavour[category][type] = pheromone
|