Browse Source

Rename Pheromone in molecule

Bastien Sevajol 8 years ago
parent
commit
2732d557e9

+ 1 - 1
TODO View File

@@ -2,4 +2,4 @@
2 2
 * Pygame: smell, pheromons: rendre + generique
3 3
 * Smell: Calcul de la distance max
4 4
 * Ant: MOVE_MODE_HOME && rien à faire (pas de truc à stocker, switch to mode EXPLO)
5
-* Plus de pheromone deposer a l'explo !
5
+* Plus de molecule deposer a l'explo !

+ 4 - 4
intelligine/core/Context.py View File

@@ -1,17 +1,17 @@
1 1
 from synergine_xyz.Context import Context as XyzContext
2 2
 from intelligine.cst import IMPENETRABLE
3 3
 from synergine_xyz.cst import POSITIONS
4
-from intelligine.synergy.stigmergy.PheromonesManager import PheromonesManager
4
+from intelligine.synergy.stigmergy.MoleculesManager import MoleculesManager
5 5
 
6 6
 
7 7
 class Context(XyzContext):
8 8
 
9 9
     def __init__(self):
10 10
         super().__init__()
11
-        self._pheromones = PheromonesManager(self)
11
+        self._molecules = MoleculesManager(self)
12 12
 
13
-    def pheromones(self):
14
-        return self._pheromones
13
+    def molecules(self):
14
+        return self._molecules
15 15
 
16 16
     def position_is_penetrable(self, position):
17 17
         """

+ 7 - 7
intelligine/core/exceptions.py View File

@@ -13,27 +13,27 @@ class UnableToFoundMovement(MovementException):
13 13
     pass
14 14
 
15 15
 
16
-class PheromoneException(Exception):
16
+class MoleculeException(Exception):
17 17
     pass
18 18
 
19 19
 
20
-class NoPheromone(PheromoneException):
20
+class NoMolecule(MoleculeException):
21 21
     pass
22 22
 
23 23
 
24
-class NoPheromoneMove(PheromoneException, MovementException):
24
+class NoMoleculeMove(MoleculeException, MovementException):
25 25
     pass
26 26
 
27 27
 
28
-class NoTypeInPheromone(NoPheromone):
28
+class NoTypeInMolecule(NoMolecule):
29 29
     pass
30 30
 
31 31
 
32
-class NoCategoryInPheromone(NoPheromone):
32
+class NoCategoryInMolecule(NoMolecule):
33 33
     pass
34 34
 
35 35
 
36
-class BestPheromoneHere(PheromoneException):
36
+class BestMoleculeHere(MoleculeException):
37 37
 
38 38
     def __init__(self, best_distance,  *args, **kwargs):
39 39
         super().__init__(*args, **kwargs)
@@ -42,7 +42,7 @@ class BestPheromoneHere(PheromoneException):
42 42
     def get_best_distance(self):
43 43
         return self._best_distance
44 44
 
45
-class PheromoneGlandDisabled(PheromoneException):
45
+class MoleculeGlandDisabled(MoleculeException):
46 46
     pass
47 47
 
48 48
 

+ 2 - 2
intelligine/cst.py View File

@@ -13,7 +13,7 @@ CARRIED = IncrementedNamedInt.get('intelligine.carried')
13 13
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
14 14
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15 15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
16
-PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.pheromone_searching')
16
+PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.molecule_searching')
17 17
 
18 18
 # TODO: Renommer "move_mode" en "mode"
19 19
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
@@ -58,4 +58,4 @@ BRAIN_PART_PUT = IncrementedNamedInt.get('intelligine.brain.part.put')
58 58
 BRAIN_PART_ATTACK = IncrementedNamedInt.get('intelligine.brain.part.attack')
59 59
 
60 60
 BODY_SCHEMA = IncrementedNamedInt.get('intelligine.body_schema')
61
-BODY_PART_PHEROMONE_GLAND = IncrementedNamedInt.get('intelligine.body.part.pheromone_gland')
61
+BODY_PART_PHEROMONE_GLAND = IncrementedNamedInt.get('intelligine.body.part.molecule_gland')

+ 21 - 21
intelligine/display/Pygame.py View File

@@ -1,4 +1,4 @@
1
-from intelligine.core.exceptions import NoPheromone
1
+from intelligine.core.exceptions import NoMolecule
2 2
 from synergine_xyz.display.Pygame import Pygame as XyzPygame
3 3
 import pygame
4 4
 from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS, POINTS_SMELL, \
@@ -11,17 +11,17 @@ class Pygame(XyzPygame):
11 11
 
12 12
     def __init__(self, config, context, synergy_manager):
13 13
         super().__init__(config, context, synergy_manager)
14
-        self._is_display_pheromones = False
14
+        self._is_display_molecules = False
15 15
         self._is_display_smells = False
16 16
 
17 17
     def receive(self, actions_done):
18 18
         super().receive(actions_done)
19 19
 
20
-        if self._is_display_pheromones:
21
-            pheromones_positions = self._context.metas.list.get(PHEROMON_POSITIONS,
20
+        if self._is_display_molecules:
21
+            molecules_positions = self._context.metas.list.get(PHEROMON_POSITIONS,
22 22
                                                                 PHEROMON_POSITIONS,
23 23
                                                                 allow_empty=True)
24
-            self._display_pheromones(pheromones_positions, self._context)
24
+            self._display_molecules(molecules_positions, self._context)
25 25
 
26 26
         if self._is_display_smells:
27 27
             smell_positions = self._context.metas.list.get(POINTS_SMELL,
@@ -29,23 +29,23 @@ class Pygame(XyzPygame):
29 29
                                                            allow_empty=True)
30 30
             self._display_smells(smell_positions, self._context)
31 31
 
32
-    def _display_pheromones(self, pheromones_positions, context):
33
-        pheromone_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
34
-        pheromone_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
32
+    def _display_molecules(self, molecules_positions, context):
33
+        molecule_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
34
+        molecule_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
35 35
 
36
-        for point in pheromones_positions:
37
-            point_flavour = context.pheromones().get_flavour(point)
36
+        for point in molecules_positions:
37
+            point_flavour = context.molecules().get_flavour(point)
38 38
             try:
39
-                point_flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
40
-                self.draw_surface(point, pheromone_home_surface)
41
-            except NoPheromone:
42
-                pass # No pheromone here
39
+                point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
40
+                self.draw_surface(point, molecule_home_surface)
41
+            except NoMolecule:
42
+                pass # No molecule here
43 43
 
44 44
             try:
45
-                point_flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
46
-                self.draw_surface(point, pheromone_exploration_surface)
47
-            except NoPheromone:
48
-                pass # No pheromone here
45
+                point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
46
+                self.draw_surface(point, molecule_exploration_surface)
47
+            except NoMolecule:
48
+                pass # No molecule here
49 49
 
50 50
     def _display_smells(self, smell_positions, context):
51 51
         smell_egg_surface = self._object_visualizer.get_surface(SURFACE_SMELL_EGG)
@@ -61,10 +61,10 @@ class Pygame(XyzPygame):
61 61
     def _key_pressed(self, key):
62 62
 
63 63
         if key == pygame.K_p:
64
-            if self._is_display_pheromones:
65
-                self._is_display_pheromones = False
64
+            if self._is_display_molecules:
65
+                self._is_display_molecules = False
66 66
             else:
67
-                self._is_display_pheromones = True
67
+                self._is_display_molecules = True
68 68
 
69 69
         if key == pygame.K_s:
70 70
             if self._is_display_smells:

+ 2 - 2
intelligine/display/pygame/visualisation.py View File

@@ -14,8 +14,8 @@ from os import getcwd
14 14
 from synergine_xyz.cst import PREVIOUS_DIRECTION
15 15
 from synergine_xyz.tmx.TileMapConnector import TileMapConnector
16 16
 
17
-SURFACE_PHEROMONE_HOME = 'pheromone_home'
18
-SURFACE_PHEROMONE_EXPLORATION = 'pheromone_exploration'
17
+SURFACE_PHEROMONE_HOME = 'molecule_home'
18
+SURFACE_PHEROMONE_EXPLORATION = 'molecule_exploration'
19 19
 
20 20
 SURFACE_SMELL_EGG = 'smell_egg'
21 21
 SURFACE_SMELL_FOOD = 'smell_food'

+ 85 - 0
intelligine/simulation/molecule/DirectionMolecule.py View File

@@ -0,0 +1,85 @@
1
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_POSITIONS
2
+from intelligine.core.exceptions import NoMolecule
3
+from random import shuffle
4
+from synergine_xyz.geometry import get_degree_from_north
5
+from intelligine.synergy.event.move.direction import get_direction_for_degrees
6
+
7
+
8
+class DirectionMolecule():
9
+
10
+    @staticmethod
11
+    def appose(context, point, molecule):
12
+        context.molecules().increment_with_molecule(point, molecule)
13
+        context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
14
+
15
+    @classmethod
16
+    def get_direction_for_point(cls, context, point, molecule_type):
17
+        flavour = context.molecules().get_flavour(point)
18
+        molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
19
+
20
+        distance = molecule.get_distance()
21
+        around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance
22
+        around_molecules_points = cls._get_around_molecules(context, point, molecule_type,
23
+                                                              molecule_filter=around_molecule_filter)
24
+
25
+        if not around_molecules_points:
26
+            raise NoMolecule()
27
+
28
+        shuffle(around_molecules_points)
29
+        around_molecules_sorted = sorted(around_molecules_points, key=lambda x: x[1].get_intensity(), reverse=True)
30
+        max_intensity = around_molecules_sorted[0][1].get_intensity()
31
+
32
+        around_molecules_max = []
33
+        for around_molecule_sorted in around_molecules_sorted:
34
+            if around_molecule_sorted[1].get_intensity() == max_intensity:
35
+                around_molecules_max.append(around_molecule_sorted)
36
+
37
+        around_molecules_sorted_by_distance = sorted(around_molecules_max,
38
+                                                      key=lambda x: x[1].get_distance(),
39
+                                                      reverse=False)
40
+
41
+        go_to_point = around_molecules_sorted_by_distance[0][0]
42
+
43
+        direction_degrees = get_degree_from_north(point, go_to_point)
44
+        direction = get_direction_for_degrees(direction_degrees)
45
+
46
+        return direction
47
+
48
+    @staticmethod
49
+    def _get_around_molecules(context, reference_point, molecule_type,
50
+                               molecule_filter=lambda around_molecule: True):
51
+        around_points = context.get_around_points_of_point(reference_point)
52
+        around_molecules_points = []
53
+        for around_point in around_points:
54
+            flavour = context.molecules().get_flavour(around_point)
55
+            try:
56
+                around_molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
57
+                if molecule_filter(around_molecule):
58
+                    around_molecules_points.append((around_point, around_molecule))
59
+            except NoMolecule:
60
+                pass  # No molecule, ok continue to sniff around
61
+
62
+        return around_molecules_points
63
+
64
+    @staticmethod
65
+    def get_best_molecule_direction_in(context, reference_point, points, molecule_type):
66
+        around_molecules_points = []
67
+        for around_point in points:
68
+            flavour = context.molecules().get_flavour(around_point)
69
+            try:
70
+                around_molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
71
+                around_molecules_points.append((around_point, around_molecule))
72
+            except NoMolecule:
73
+                pass  # Ok, no molecule, continue to sniff around
74
+
75
+        if not around_molecules_points:
76
+            raise NoMolecule()
77
+
78
+        shuffle(around_molecules_points)
79
+        around_molecules_sorted = sorted(around_molecules_points, key=lambda x: x[1].get_intensity(), reverse=True)
80
+        go_to_point = around_molecules_sorted[0][0]
81
+
82
+        direction_degrees = get_degree_from_north(reference_point, go_to_point)
83
+        direction = get_direction_for_degrees(direction_degrees)
84
+
85
+        return direction

intelligine/simulation/pheromone/Pheromone.py → intelligine/simulation/molecule/Molecule.py View File

@@ -1,4 +1,4 @@
1
-class Pheromone():
1
+class Molecule():
2 2
 
3 3
     def __init__(self, category, type, distance=None, intensity=0):
4 4
         self._category = category

+ 51 - 0
intelligine/simulation/molecule/MoleculeFlavour.py View File

@@ -0,0 +1,51 @@
1
+from intelligine.core.exceptions import NoTypeInMolecule, NoCategoryInMolecule
2
+from intelligine.simulation.molecule.Molecule import Molecule
3
+
4
+
5
+class MoleculeFlavour():
6
+
7
+    @classmethod
8
+    def new_from_raw_data(cls, raw_data):
9
+        flavour = {}
10
+        for category in raw_data:
11
+            molecules_by_category = raw_data[category]
12
+            for type in molecules_by_category:
13
+                distance, intensity = molecules_by_category[type]
14
+                if category not in flavour:
15
+                    flavour[category] = {}
16
+                flavour[category][type] = Molecule(category, type, distance, intensity)
17
+        return cls(flavour)
18
+
19
+    def get_raw_data(self):
20
+        raw_data = {}
21
+        for category in self._flavour:
22
+            molecules_by_category = self._flavour[category]
23
+            for type in molecules_by_category:
24
+                molecule = molecules_by_category[type]
25
+                if category not in raw_data:
26
+                    raw_data[category] = {}
27
+                raw_data[category][type] = (molecule.get_distance(), molecule.get_intensity())
28
+        return raw_data
29
+
30
+    def __init__(self, flavour):
31
+        self._flavour = flavour
32
+
33
+    def get_molecule(self, category, type):
34
+        types = self.get_types(category)
35
+        if type not in types:
36
+            raise NoTypeInMolecule()
37
+        return types[type]
38
+
39
+    def get_types(self, category):
40
+        if category not in self._flavour:
41
+            raise NoCategoryInMolecule()
42
+        return self._flavour[category]
43
+
44
+    def set_molecule(self, molecule):
45
+        category = molecule.get_category()
46
+        type = molecule.get_type()
47
+
48
+        if category not in self._flavour:
49
+            self._flavour[category] = {}
50
+
51
+        self._flavour[category][type] = molecule

+ 18 - 18
intelligine/simulation/object/brain/AntBrain.py View File

@@ -23,47 +23,47 @@ class AntBrain(Brain):
23 23
         super().__init__(context, host)
24 24
         self._movement_mode = MOVE_MODE_HOME
25 25
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
26
-        self._pheromone_searching = PHEROMON_DIR_EXPLO
26
+        self._molecule_searching = PHEROMON_DIR_EXPLO
27 27
 
28 28
     def switch_to_mode(self, mode):
29 29
         # TODO: Mode explo: reinit exploration vector
30 30
         self._movement_mode = mode
31
-        self._update_pheromone_gland(mode)
31
+        self._update_molecule_gland(mode)
32 32
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
33 33
         self._distance_from_objective = 0
34
-        self._update_pheromone_searching(mode)
34
+        self._update_molecule_searching(mode)
35 35
 
36
-    def _update_pheromone_gland(self, mode):
36
+    def _update_molecule_gland(self, mode):
37 37
         if mode == MOVE_MODE_EXPLO:
38
-            pheromone_direction_type = PHEROMON_DIR_HOME
38
+            molecule_direction_type = PHEROMON_DIR_HOME
39 39
         elif mode == MOVE_MODE_GOHOME:
40
-            pheromone_direction_type = PHEROMON_DIR_EXPLO
40
+            molecule_direction_type = PHEROMON_DIR_EXPLO
41 41
         elif mode == MOVE_MODE_NURSE:
42
-            pheromone_direction_type = None
42
+            molecule_direction_type = None
43 43
         elif mode == MOVE_MODE_HOME:
44
-            pheromone_direction_type = None
44
+            molecule_direction_type = None
45 45
         else:
46 46
             raise NotImplementedError()
47 47
 
48
-        if pheromone_direction_type:
49
-            self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
50
-            self._host.get_movement_pheromone_gland().enable()
48
+        if molecule_direction_type:
49
+            self._host.get_movement_molecule_gland().set_molecule_type(molecule_direction_type)
50
+            self._host.get_movement_molecule_gland().enable()
51 51
         else:
52
-            self._host.get_movement_pheromone_gland().disable()
52
+            self._host.get_movement_molecule_gland().disable()
53 53
 
54
-    def _update_pheromone_searching(self, mode):
54
+    def _update_molecule_searching(self, mode):
55 55
         if mode == MOVE_MODE_EXPLO:
56
-            pheromone_searching = PHEROMON_DIR_EXPLO
56
+            molecule_searching = PHEROMON_DIR_EXPLO
57 57
         elif mode == MOVE_MODE_GOHOME:
58
-            pheromone_searching = PHEROMON_DIR_HOME
58
+            molecule_searching = PHEROMON_DIR_HOME
59 59
         elif mode == MOVE_MODE_NURSE:
60
-            pheromone_searching = PHEROMON_DIR_NONE
60
+            molecule_searching = PHEROMON_DIR_NONE
61 61
         elif mode == MOVE_MODE_HOME:
62 62
             return
63 63
         else:
64 64
             raise NotImplementedError()
65
-        self._pheromone_searching = pheromone_searching
66
-        self._context.metas.value.set(PHEROMONE_SEARCHING, self._host.get_id(), pheromone_searching)
65
+        self._molecule_searching = molecule_searching
66
+        self._context.metas.value.set(PHEROMONE_SEARCHING, self._host.get_id(), molecule_searching)
67 67
 
68 68
     def get_movement_mode(self):
69 69
         return self._movement_mode

+ 23 - 23
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

@@ -1,10 +1,10 @@
1 1
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
2 2
 from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
3 3
 from synergine_xyz.cst import POSITION
4
-from intelligine.core.exceptions import NoPheromone
4
+from intelligine.core.exceptions import NoMolecule
5 5
 from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, \
6 6
     MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, EXPLORATION_VECTOR, POINTS_SMELL
7
-from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
7
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
8 8
 from synergine_xyz.geometry import get_degree_from_north
9 9
 
10 10
 
@@ -26,8 +26,8 @@ class AntMoveBrainPart(MoveBrainPart):
26 26
         move_mode = context.metas.value.get(MOVE_MODE, object_id)
27 27
         if move_mode == MOVE_MODE_EXPLO:
28 28
             try:
29
-                return cls._get_direction_with_pheromones(context, object_id)
30
-            except NoPheromone:
29
+                return cls._get_direction_with_molecules(context, object_id)
30
+            except NoMolecule:
31 31
                 return super().get_direction(context, object_id)
32 32
         elif move_mode == MOVE_MODE_GOHOME:
33 33
             return cls._get_direction_with_exploration_vector(context, object_id)
@@ -35,32 +35,32 @@ class AntMoveBrainPart(MoveBrainPart):
35 35
         return super().get_direction(context, object_id)
36 36
 
37 37
     @classmethod
38
-    def _get_direction_with_pheromones(cls, context, object_id):
38
+    def _get_direction_with_molecules(cls, context, object_id):
39 39
         object_point = context.metas.value.get(POSITION, object_id)
40
-        pheromone_type = context.metas.value.get(PHEROMONE_SEARCHING, object_id)
40
+        molecule_type = context.metas.value.get(PHEROMONE_SEARCHING, object_id)
41 41
         try:
42
-            direction = cls._get_pheromone_direction_for_point(context, object_point, pheromone_type)
43
-        except NoPheromone:
42
+            direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type)
43
+        except NoMolecule:
44 44
             try:
45
-                direction = cls._get_direction_of_pheromone(context, object_point, pheromone_type)
46
-            except NoPheromone:
45
+                direction = cls._get_direction_of_molecule(context, object_point, molecule_type)
46
+            except NoMolecule:
47 47
                 raise
48 48
         return direction
49 49
 
50 50
     @staticmethod
51
-    def _get_pheromone_direction_for_point(context, point, pheromone_type):
52
-        return DirectionPheromone.get_direction_for_point(context, point, pheromone_type)
51
+    def _get_molecule_direction_for_point(context, point, molecule_type):
52
+        return DirectionMolecule.get_direction_for_point(context, point, molecule_type)
53 53
 
54 54
     @staticmethod
55
-    def _get_direction_of_pheromone(context, point, pheromone_type):
56
-        search_pheromone_in_points = context.get_around_points_of_point(point)
55
+    def _get_direction_of_molecule(context, point, molecule_type):
56
+        search_molecule_in_points = context.get_around_points_of_point(point)
57 57
         try:
58
-            best_pheromone_direction = DirectionPheromone.get_best_pheromone_direction_in(context,
58
+            best_molecule_direction = DirectionMolecule.get_best_molecule_direction_in(context,
59 59
                                                                                           point,
60
-                                                                                          search_pheromone_in_points,
61
-                                                                                          pheromone_type)
62
-            return best_pheromone_direction
63
-        except NoPheromone as err:
60
+                                                                                          search_molecule_in_points,
61
+                                                                                          molecule_type)
62
+            return best_molecule_direction
63
+        except NoMolecule as err:
64 64
             raise err
65 65
 
66 66
     @staticmethod
@@ -79,14 +79,14 @@ class AntMoveBrainPart(MoveBrainPart):
79 79
     # TODO: obj pas necessaire, il est dans _host
80 80
     def done(self, obj, context):
81 81
         super().done(obj, context)
82
-        self._appose_pheromone(obj)
82
+        self._appose_molecule(obj)
83 83
         self._check_context(obj, context)
84 84
         self._apply_context(obj, context)
85 85
 
86 86
     @staticmethod
87
-    def _appose_pheromone(obj):
88
-        if obj.get_movement_pheromone_gland().is_enabled():
89
-            obj.get_movement_pheromone_gland().appose()
87
+    def _appose_molecule(obj):
88
+        if obj.get_movement_molecule_gland().is_enabled():
89
+            obj.get_movement_molecule_gland().appose()
90 90
 
91 91
     def _check_context(self, obj, context):
92 92
         """

+ 1 - 1
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py View File

@@ -22,4 +22,4 @@ class AntTakeBrainPart(TakeBrainPart):
22 22
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
23 23
         if isinstance(take_object, Resource):
24 24
             obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
25
-            obj.get_movement_pheromone_gland().appose()
25
+            obj.get_movement_molecule_gland().appose()

+ 41 - 0
intelligine/simulation/object/molecule/MoleculeGland.py View File

@@ -0,0 +1,41 @@
1
+from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
2
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
3
+
4
+class MoleculeGland():
5
+
6
+    def __init__(self, host, context):
7
+        self._molecule_type = None
8
+        self._host = host
9
+        self._context = context
10
+        self._enabled = False
11
+
12
+    def set_molecule_type(self, molecule_type):
13
+        self._molecule_type = molecule_type
14
+
15
+    def get_molecule_type(self):
16
+        if self._molecule_type is None:
17
+            raise Exception("molecule_type not specified")
18
+        return self._molecule_type
19
+
20
+    def get_molecule(self):
21
+        raise NotImplementedError()
22
+
23
+    def appose(self):
24
+        if not self._enabled:
25
+            raise MoleculeGlandDisabled()
26
+
27
+        try:
28
+            DirectionMolecule.appose(self._context,
29
+                                      self._host.get_position(),
30
+                                      self.get_molecule())
31
+        except BestMoleculeHere as best_molecule_here:
32
+            self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
33
+
34
+    def disable(self):
35
+        self._enabled = False
36
+
37
+    def enable(self):
38
+        self._enabled = True
39
+
40
+    def is_enabled(self):
41
+        return self._enabled

+ 12 - 0
intelligine/simulation/object/molecule/MovementMoleculeGland.py View File

@@ -0,0 +1,12 @@
1
+from intelligine.cst import PHEROMON_DIRECTION
2
+from intelligine.simulation.object.molecule.MoleculeGland import MoleculeGland
3
+from intelligine.simulation.molecule.Molecule import Molecule
4
+
5
+
6
+class MovementMoleculeGland(MoleculeGland):
7
+
8
+    def get_molecule(self):
9
+        """
10
+        :return: Molecule
11
+        """
12
+        return Molecule(PHEROMON_DIRECTION, self._molecule_type, self._host.get_brain().get_distance_from_objective(), 1)

+ 0 - 12
intelligine/simulation/object/pheromone/MovementPheromoneGland.py View File

@@ -1,12 +0,0 @@
1
-from intelligine.cst import PHEROMON_DIRECTION
2
-from intelligine.simulation.object.pheromone.PheromoneGland import PheromoneGland
3
-from intelligine.simulation.pheromone.Pheromone import Pheromone
4
-
5
-
6
-class MovementPheromoneGland(PheromoneGland):
7
-
8
-    def get_pheromone(self):
9
-        """
10
-        :return: Pheromone
11
-        """
12
-        return Pheromone(PHEROMON_DIRECTION, self._pheromone_type, self._host.get_brain().get_distance_from_objective(), 1)

+ 0 - 41
intelligine/simulation/object/pheromone/PheromoneGland.py View File

@@ -1,41 +0,0 @@
1
-from intelligine.core.exceptions import BestPheromoneHere, PheromoneGlandDisabled
2
-from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
3
-
4
-class PheromoneGland():
5
-
6
-    def __init__(self, host, context):
7
-        self._pheromone_type = None
8
-        self._host = host
9
-        self._context = context
10
-        self._enabled = False
11
-
12
-    def set_pheromone_type(self, pheromone_type):
13
-        self._pheromone_type = pheromone_type
14
-
15
-    def get_pheromone_type(self):
16
-        if self._pheromone_type is None:
17
-            raise Exception("pheromone_type not specified")
18
-        return self._pheromone_type
19
-
20
-    def get_pheromone(self):
21
-        raise NotImplementedError()
22
-
23
-    def appose(self):
24
-        if not self._enabled:
25
-            raise PheromoneGlandDisabled()
26
-
27
-        try:
28
-            DirectionPheromone.appose(self._context,
29
-                                      self._host.get_position(),
30
-                                      self.get_pheromone())
31
-        except BestPheromoneHere as best_pheromone_here:
32
-            self._host.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())
33
-
34
-    def disable(self):
35
-        self._enabled = False
36
-
37
-    def enable(self):
38
-        self._enabled = True
39
-
40
-    def is_enabled(self):
41
-        return self._enabled

+ 0 - 85
intelligine/simulation/pheromone/DirectionPheromone.py View File

@@ -1,85 +0,0 @@
1
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_POSITIONS
2
-from intelligine.core.exceptions import NoPheromone
3
-from random import shuffle
4
-from synergine_xyz.geometry import get_degree_from_north
5
-from intelligine.synergy.event.move.direction import get_direction_for_degrees
6
-
7
-
8
-class DirectionPheromone():
9
-
10
-    @staticmethod
11
-    def appose(context, point, pheromone):
12
-        context.pheromones().increment_with_pheromone(point, pheromone)
13
-        context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
14
-
15
-    @classmethod
16
-    def get_direction_for_point(cls, context, point, pheromone_type):
17
-        flavour = context.pheromones().get_flavour(point)
18
-        pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
19
-
20
-        distance = pheromone.get_distance()
21
-        around_pheromone_filter = lambda around_pheromone: around_pheromone.get_distance() < distance
22
-        around_pheromones_points = cls._get_around_pheromones(context, point, pheromone_type,
23
-                                                              pheromone_filter=around_pheromone_filter)
24
-
25
-        if not around_pheromones_points:
26
-            raise NoPheromone()
27
-
28
-        shuffle(around_pheromones_points)
29
-        around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1].get_intensity(), reverse=True)
30
-        max_intensity = around_pheromones_sorted[0][1].get_intensity()
31
-
32
-        around_pheromones_max = []
33
-        for around_pheromone_sorted in around_pheromones_sorted:
34
-            if around_pheromone_sorted[1].get_intensity() == max_intensity:
35
-                around_pheromones_max.append(around_pheromone_sorted)
36
-
37
-        around_pheromones_sorted_by_distance = sorted(around_pheromones_max,
38
-                                                      key=lambda x: x[1].get_distance(),
39
-                                                      reverse=False)
40
-
41
-        go_to_point = around_pheromones_sorted_by_distance[0][0]
42
-
43
-        direction_degrees = get_degree_from_north(point, go_to_point)
44
-        direction = get_direction_for_degrees(direction_degrees)
45
-
46
-        return direction
47
-
48
-    @staticmethod
49
-    def _get_around_pheromones(context, reference_point, pheromone_type,
50
-                               pheromone_filter=lambda around_pheromone: True):
51
-        around_points = context.get_around_points_of_point(reference_point)
52
-        around_pheromones_points = []
53
-        for around_point in around_points:
54
-            flavour = context.pheromones().get_flavour(around_point)
55
-            try:
56
-                around_pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
57
-                if pheromone_filter(around_pheromone):
58
-                    around_pheromones_points.append((around_point, around_pheromone))
59
-            except NoPheromone:
60
-                pass  # No pheromone, ok continue to sniff around
61
-
62
-        return around_pheromones_points
63
-
64
-    @staticmethod
65
-    def get_best_pheromone_direction_in(context, reference_point, points, pheromone_type):
66
-        around_pheromones_points = []
67
-        for around_point in points:
68
-            flavour = context.pheromones().get_flavour(around_point)
69
-            try:
70
-                around_pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
71
-                around_pheromones_points.append((around_point, around_pheromone))
72
-            except NoPheromone:
73
-                pass  # Ok, no pheromone, continue to sniff around
74
-
75
-        if not around_pheromones_points:
76
-            raise NoPheromone()
77
-
78
-        shuffle(around_pheromones_points)
79
-        around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1].get_intensity(), reverse=True)
80
-        go_to_point = around_pheromones_sorted[0][0]
81
-
82
-        direction_degrees = get_degree_from_north(reference_point, go_to_point)
83
-        direction = get_direction_for_degrees(direction_degrees)
84
-
85
-        return direction

+ 0 - 51
intelligine/simulation/pheromone/PheromoneFlavour.py View File

@@ -1,51 +0,0 @@
1
-from intelligine.core.exceptions import NoTypeInPheromone, NoCategoryInPheromone
2
-from intelligine.simulation.pheromone.Pheromone import Pheromone
3
-
4
-
5
-class PheromoneFlavour():
6
-
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
-                if category not in flavour:
15
-                    flavour[category] = {}
16
-                flavour[category][type] = Pheromone(category, type, distance, intensity)
17
-        return cls(flavour)
18
-
19
-    def get_raw_data(self):
20
-        raw_data = {}
21
-        for category in self._flavour:
22
-            pheromones_by_category = self._flavour[category]
23
-            for type in pheromones_by_category:
24
-                pheromone = pheromones_by_category[type]
25
-                if category not in raw_data:
26
-                    raw_data[category] = {}
27
-                raw_data[category][type] = (pheromone.get_distance(), pheromone.get_intensity())
28
-        return raw_data
29
-
30
-    def __init__(self, flavour):
31
-        self._flavour = flavour
32
-
33
-    def get_pheromone(self, category, type):
34
-        types = self.get_types(category)
35
-        if type not in types:
36
-            raise NoTypeInPheromone()
37
-        return types[type]
38
-
39
-    def get_types(self, category):
40
-        if category not in self._flavour:
41
-            raise NoCategoryInPheromone()
42
-        return self._flavour[category]
43
-
44
-    def set_pheromone(self, pheromone):
45
-        category = pheromone.get_category()
46
-        type = pheromone.get_type()
47
-
48
-        if category not in self._flavour:
49
-            self._flavour[category] = {}
50
-
51
-        self._flavour[category][type] = pheromone

+ 8 - 8
intelligine/synergy/object/ant/Ant.py View File

@@ -1,17 +1,17 @@
1
-from intelligine.core.exceptions import PheromoneException
1
+from intelligine.core.exceptions import MoleculeException
2 2
 from intelligine.synergy.object.Bug import Bug
3 3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4 4
     COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5 5
     COL_TRANSPORTER_CARRYING, MOVE_MODE_NURSE, MOVE_MODE_HOME
6 6
 from intelligine.synergy.object.Food import Food
7
-from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
7
+from intelligine.simulation.object.molecule.MovementMoleculeGland import MovementMoleculeGland
8 8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
9 9
 
10 10
 
11 11
 class Ant(Bug):
12 12
 
13 13
     _body_parts = {
14
-        BODY_PART_PHEROMONE_GLAND: MovementPheromoneGland
14
+        BODY_PART_PHEROMONE_GLAND: MovementMoleculeGland
15 15
     }
16 16
 
17 17
     def __init__(self, collection, context):
@@ -36,7 +36,7 @@ class Ant(Bug):
36 36
     def _get_brain_instance(self):
37 37
         return AntBrain(self._context, self)
38 38
 
39
-    def get_movement_pheromone_gland(self):
39
+    def get_movement_molecule_gland(self):
40 40
         return self.get_body_part(BODY_PART_PHEROMONE_GLAND)
41 41
 
42 42
     def put_carry(self, obj, position=None):
@@ -61,7 +61,7 @@ class Ant(Bug):
61 61
         # TODO: pour le moment hardcode, a gerer dans AntTakeBrainPart (callback en fct de ce qui est depose)
62 62
         if isinstance(obj, Food):
63 63
             self.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
64
-            self.get_movement_pheromone_gland().appose()
64
+            self.get_movement_molecule_gland().appose()
65 65
 
66 66
     def is_carrying(self):
67 67
         if self._carried:
@@ -77,10 +77,10 @@ class Ant(Bug):
77 77
 
78 78
     def initialize(self):
79 79
         super().initialize()
80
-        if self.get_movement_pheromone_gland().is_enabled():
80
+        if self.get_movement_molecule_gland().is_enabled():
81 81
             try:
82
-                self.get_movement_pheromone_gland().appose()
83
-            except PheromoneException:
82
+                self.get_movement_molecule_gland().appose()
83
+            except MoleculeException:
84 84
                 pass
85 85
 
86 86
     def get_colony(self):

+ 49 - 0
intelligine/synergy/stigmergy/MoleculesManager.py View File

@@ -0,0 +1,49 @@
1
+from intelligine.core.exceptions import BestMoleculeHere, NoMolecule
2
+from intelligine.cst import PHEROMON_INFOS
3
+from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
4
+from intelligine.simulation.molecule.Molecule import Molecule
5
+
6
+
7
+class MoleculesManager():
8
+
9
+    def __init__(self, context):
10
+        self._context = context
11
+
12
+    def get_flavour(self, position):
13
+        point_molecules = self._context.metas.value.get(PHEROMON_INFOS,
14
+                                                         position,
15
+                                                         allow_empty=True,
16
+                                                         empty_value={})
17
+        return MoleculeFlavour.new_from_raw_data(point_molecules)
18
+
19
+    def set_flavour(self, position, flavour):
20
+        self._context.metas.value.set(PHEROMON_INFOS, position, flavour.get_raw_data())
21
+
22
+    def get_molecule(self, position, category, type, allow_empty=False):
23
+        flavour = self.get_flavour(position)
24
+        try:
25
+            return flavour.get_molecule(category, type)
26
+        except NoMolecule:
27
+            if allow_empty:
28
+                return Molecule()
29
+            raise
30
+
31
+    def increment_with_molecule(self, position, apposed_molecule):
32
+        flavour = self.get_flavour(position)
33
+        try:
34
+            position_molecule = flavour.get_molecule(apposed_molecule.get_category(), apposed_molecule.get_type())
35
+        except NoMolecule:
36
+            position_molecule = Molecule(apposed_molecule.get_category(),
37
+                                           apposed_molecule.get_type(),
38
+                                           distance=apposed_molecule.get_distance())
39
+
40
+        position_molecule.increment_intensity(apposed_molecule.get_intensity())
41
+
42
+        if apposed_molecule.get_distance() < position_molecule.get_distance():
43
+            position_molecule.set_distance(apposed_molecule.get_distance())
44
+
45
+        flavour.set_molecule(position_molecule)
46
+        self.set_flavour(position, flavour)
47
+
48
+        if apposed_molecule.get_distance() > position_molecule.get_distance():
49
+            raise BestMoleculeHere(position_molecule.get_distance())

+ 0 - 49
intelligine/synergy/stigmergy/PheromonesManager.py View File

@@ -1,49 +0,0 @@
1
-from intelligine.core.exceptions import BestPheromoneHere, NoPheromone
2
-from intelligine.cst import PHEROMON_INFOS
3
-from intelligine.simulation.pheromone.PheromoneFlavour import PheromoneFlavour
4
-from intelligine.simulation.pheromone.Pheromone import Pheromone
5
-
6
-
7
-class PheromonesManager():
8
-
9
-    def __init__(self, context):
10
-        self._context = context
11
-
12
-    def get_flavour(self, position):
13
-        point_pheromones = self._context.metas.value.get(PHEROMON_INFOS,
14
-                                                         position,
15
-                                                         allow_empty=True,
16
-                                                         empty_value={})
17
-        return PheromoneFlavour.new_from_raw_data(point_pheromones)
18
-
19
-    def set_flavour(self, position, flavour):
20
-        self._context.metas.value.set(PHEROMON_INFOS, position, flavour.get_raw_data())
21
-
22
-    def get_pheromone(self, position, category, type, allow_empty=False):
23
-        flavour = self.get_flavour(position)
24
-        try:
25
-            return flavour.get_pheromone(category, type)
26
-        except NoPheromone:
27
-            if allow_empty:
28
-                return Pheromone()
29
-            raise
30
-
31
-    def increment_with_pheromone(self, position, apposed_pheromone):
32
-        flavour = self.get_flavour(position)
33
-        try:
34
-            position_pheromone = flavour.get_pheromone(apposed_pheromone.get_category(), apposed_pheromone.get_type())
35
-        except NoPheromone:
36
-            position_pheromone = Pheromone(apposed_pheromone.get_category(),
37
-                                           apposed_pheromone.get_type(),
38
-                                           distance=apposed_pheromone.get_distance())
39
-
40
-        position_pheromone.increment_intensity(apposed_pheromone.get_intensity())
41
-
42
-        if apposed_pheromone.get_distance() < position_pheromone.get_distance():
43
-            position_pheromone.set_distance(apposed_pheromone.get_distance())
44
-
45
-        flavour.set_pheromone(position_pheromone)
46
-        self.set_flavour(position, flavour)
47
-
48
-        if apposed_pheromone.get_distance() > position_pheromone.get_distance():
49
-            raise BestPheromoneHere(position_pheromone.get_distance())

+ 8 - 8
intelligine/tests/simulation/mode/TestChangeMode.py View File

@@ -1,6 +1,6 @@
1 1
 from os import getcwd
2 2
 from sys import path as ppath
3
-from intelligine.core.exceptions import NoPheromone
3
+from intelligine.core.exceptions import NoMolecule
4 4
 
5 5
 ppath.insert(1,getcwd()+'/modules')
6 6
 
@@ -16,7 +16,7 @@ from intelligine.tests.src.event.MoveAction import MoveAction as TestMoveAction
16 16
 from synergine.synergy.collection.SynergyCollection import SynergyCollection
17 17
 from synergine.synergy.collection.Configuration import Configuration
18 18
 from intelligine.core.Context import Context
19
-from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, MOVE_MODE
19
+from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, MOVE_MODE, MOVE_MODE_HOME
20 20
 from intelligine.cst import PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO
21 21
 
22 22
 
@@ -101,7 +101,7 @@ class TestChangeMode(Base):
101 101
     def test_from_exploration_to_go_home(self):
102 102
         self._run_and_get_core(0)
103 103
         self.assertEquals((0, 0, 0), self.ant.get_position())
104
-        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
104
+        self.assertEquals(MOVE_MODE_HOME, self.ant.get_brain().get_movement_mode())
105 105
         self.assertFalse(self.ant.is_carrying())
106 106
 
107 107
         self._run_and_get_core(1)
@@ -115,11 +115,11 @@ class TestChangeMode(Base):
115 115
         self.assertTrue(self.ant.is_carrying())
116 116
         self.assertIsNotNone(self.ant.get_carried())
117 117
         self.assertEquals(self.food.__class__, self.ant.get_carried().__class__)
118
-        pheromone = self.ant.get_movement_pheromone_gland().get_pheromone()
119
-        # Now it appose exploration pheromone
120
-        self.assertEquals((PHEROMON_DIR_EXPLO, 0), (pheromone.get_type(), pheromone.get_distance()))
118
+        molecule = self.ant.get_movement_molecule_gland().get_molecule()
119
+        # Now it appose exploration molecule
120
+        self.assertEquals((PHEROMON_DIR_EXPLO, 0), (molecule.get_type(), molecule.get_distance()))
121 121
         self.assertEquals(MOVE_MODE_GOHOME, self.ant.get_brain().get_movement_mode())
122
-        self.assertEquals(PHEROMON_DIR_EXPLO, self.ant.get_movement_pheromone_gland().get_pheromone_type())
122
+        self.assertEquals(PHEROMON_DIR_EXPLO, self.ant.get_movement_molecule_gland().get_molecule_type())
123 123
 
124 124
         self._run_and_get_core(3)
125 125
         self.assertEquals((0, 0, -1), self.ant.get_position())
@@ -130,4 +130,4 @@ class TestChangeMode(Base):
130 130
         # Ant has put his food piece
131 131
         self.assertFalse(self.ant.is_carrying())
132 132
         self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
133
-        self.assertEquals(PHEROMON_DIR_HOME, self.ant.get_movement_pheromone_gland().get_pheromone_type())
133
+        self.assertEquals(PHEROMON_DIR_HOME, self.ant.get_movement_molecule_gland().get_molecule_type())

intelligine/tests/simulation/pheromone/Base.py → intelligine/tests/simulation/molecule/Base.py View File


intelligine/tests/simulation/pheromone/TestDirection.py → intelligine/tests/simulation/molecule/TestDirection.py View File

@@ -1,13 +1,13 @@
1 1
 from os import getcwd
2 2
 from sys import path as ppath
3
-from intelligine.core.exceptions import NoPheromone
4
-from intelligine.simulation.pheromone.Pheromone import Pheromone
5
-from intelligine.simulation.pheromone.PheromoneFlavour import PheromoneFlavour
3
+from intelligine.core.exceptions import NoMolecule
4
+from intelligine.simulation.molecule.Molecule import Molecule
5
+from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
6 6
 
7 7
 ppath.insert(1,getcwd()+'/modules')
8 8
 
9
-from intelligine.tests.simulation.pheromone.Base import Base
10
-from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
9
+from intelligine.tests.simulation.molecule.Base import Base
10
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
11 11
 from intelligine.core.Context import Context
12 12
 from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_DIR_HOME
13 13
 from intelligine.synergy.event.move.direction import NORTH, NORTH_EST, EST, SOUTH_EST, SOUTH, SOUTH_WEST, WEST, \
@@ -24,47 +24,47 @@ class TestDirection(Base):
24 24
     def setUp(self):
25 25
         self._context = Context()
26 26
 
27
-    def _set_up_pheromones(self, pheromones, re_init=True):
27
+    def _set_up_molecules(self, molecules, re_init=True):
28 28
         if re_init:
29 29
             self._context = Context()
30
-        for position in pheromones:
31
-            self._context.pheromones().set_flavour(position, PheromoneFlavour.new_from_raw_data(pheromones[position]))
30
+        for position in molecules:
31
+            self._context.molecules().set_flavour(position, MoleculeFlavour.new_from_raw_data(molecules[position]))
32 32
 
33
-    def _test_direction_for_point(self, pheromones, direction, pheromone_type=PHEROMON_DIR_EXPLO,
33
+    def _test_direction_for_point(self, molecules, direction, molecule_type=PHEROMON_DIR_EXPLO,
34 34
                                   reference_point=_p(CENTER), re_init=True):
35 35
         """
36 36
 
37
-        :param pheromones:
37
+        :param molecules:
38 38
         :param direction:
39
-        :param pheromone_type:
39
+        :param molecule_type:
40 40
         :param reference_point:
41 41
         :return:
42 42
         """
43
-        self._set_up_pheromones(pheromones, re_init=re_init)
44
-        direction_tested = DirectionPheromone.get_direction_for_point(self._context, reference_point, pheromone_type)
43
+        self._set_up_molecules(molecules, re_init=re_init)
44
+        direction_tested = DirectionMolecule.get_direction_for_point(self._context, reference_point, molecule_type)
45 45
         self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
46 46
 
47
-    def _test_direction_for_points(self, pheromones, direction, pheromone_type=PHEROMON_DIR_EXPLO,
47
+    def _test_direction_for_points(self, molecules, direction, molecule_type=PHEROMON_DIR_EXPLO,
48 48
                                    reference_point=_p(CENTER), re_init=True):
49 49
         """
50 50
 
51
-        :param pheromones:
51
+        :param molecules:
52 52
         :param direction:
53
-        :param pheromone_type:
53
+        :param molecule_type:
54 54
         :param reference_point:
55 55
         :return:
56 56
         """
57
-        self._set_up_pheromones(pheromones, re_init=re_init)
57
+        self._set_up_molecules(molecules, re_init=re_init)
58 58
         around_points = self._context.get_around_points_of_point(reference_point)
59
-        direction_tested = DirectionPheromone.get_best_pheromone_direction_in(self._context,
59
+        direction_tested = DirectionMolecule.get_best_molecule_direction_in(self._context,
60 60
                                                                               reference_point,
61 61
                                                                               around_points,
62
-                                                                              pheromone_type)
62
+                                                                              molecule_type)
63 63
         self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
64 64
 
65 65
     def test_route_direct_route(self):
66 66
         """
67
-        Test easy direction with 1 best pheromones just near actual position
67
+        Test easy direction with 1 best molecules just near actual position
68 68
         :return:
69 69
         """
70 70
         test_data = {
@@ -107,7 +107,7 @@ class TestDirection(Base):
107 107
 
108 108
     def test_route_with_multiple_same_intensity(self):
109 109
         """
110
-        Test find route in middle of multiple pheromones
110
+        Test find route in middle of multiple molecules
111 111
         :return:
112 112
         """
113 113
         test_data = {
@@ -135,7 +135,7 @@ class TestDirection(Base):
135 135
 
136 136
     def test_route_with_multiple_different_intensity(self):
137 137
         """
138
-        Test find route in middle of multiple pheromones
138
+        Test find route in middle of multiple molecules
139 139
         :return:
140 140
         """
141 141
         test_data = {
@@ -148,7 +148,7 @@ class TestDirection(Base):
148 148
                 _p(CENTER): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 2)}},
149 149
                 _p(NORTH_WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}},
150 150
                 _p(SOUTH_EST): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (8, 1)}},
151
-                _p(SOUTH_EST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (5, 10)}}  # an other pheromone type
151
+                _p(SOUTH_EST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (5, 10)}}  # an other molecule type
152 152
             }
153 153
         }
154 154
 
@@ -162,7 +162,7 @@ class TestDirection(Base):
162 162
             },
163 163
             NORTH: {
164 164
                 _p(NORTH): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}},
165
-                _p(NORTH_WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}}  # An other pheromone type
165
+                _p(NORTH_WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}}  # An other molecule type
166 166
             }
167 167
         }
168 168
 
@@ -178,7 +178,7 @@ class TestDirection(Base):
178 178
             },
179 179
             NORTH: {
180 180
                 _p(NORTH): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5)}},
181
-                _p(WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}},  # An other pheromone_type
181
+                _p(WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}},  # An other molecule_type
182 182
                 _p(SOUTH_EST): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}},
183 183
                 _p(NORTH_WEST): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}}
184 184
             }
@@ -187,55 +187,55 @@ class TestDirection(Base):
187 187
         for direction in test_data:
188 188
             self._test_direction_for_points(test_data[direction], direction)
189 189
 
190
-    def test_no_pheromones_around(self):
191
-        # No pheromone
190
+    def test_no_molecules_around(self):
191
+        # No molecule
192 192
         try:  # WTF ?
193
-            self.assertRaises(NoPheromone, self._test_direction_for_points({}, -1))
194
-        except NoPheromone:
193
+            self.assertRaises(NoMolecule, self._test_direction_for_points({}, -1))
194
+        except NoMolecule:
195 195
             self.assertTrue(True)
196 196
 
197
-        # Wrong pheromone type
197
+        # Wrong molecule type
198 198
         try:  # WTF ?
199
-            self.assertRaises(NoPheromone, self._test_direction_for_points({
199
+            self.assertRaises(NoMolecule, self._test_direction_for_points({
200 200
                 _p(SOUTH_EST): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 5)}}
201 201
             }, -1))
202
-        except NoPheromone:
202
+        except NoMolecule:
203 203
             self.assertTrue(True)
204 204
 
205 205
     def test_appose(self):
206
-        self._test_point_raise_no_pheromone()
207
-        self._test_points_raise_no_pheromone()
206
+        self._test_point_raise_no_molecule()
207
+        self._test_points_raise_no_molecule()
208 208
 
209
-        # Une pheromone au centre
210
-        DirectionPheromone.appose(self._context,
209
+        # Une molecule au centre
210
+        DirectionMolecule.appose(self._context,
211 211
                                   _p(CENTER),
212
-                                  self._get_pheromone(PHEROMON_DIR_EXPLO, 2))
212
+                                  self._get_molecule(PHEROMON_DIR_EXPLO, 2))
213 213
         # Ne permet pas de trouver une route
214
-        self._test_point_raise_no_pheromone(re_init=False)
215
-        self._test_points_raise_no_pheromone(re_init=False)
214
+        self._test_point_raise_no_molecule(re_init=False)
215
+        self._test_points_raise_no_molecule(re_init=False)
216 216
 
217
-        # Une pheromone au nord
218
-        DirectionPheromone.appose(self._context,
217
+        # Une molecule au nord
218
+        DirectionMolecule.appose(self._context,
219 219
                                   _p(NORTH),
220
-                                  self._get_pheromone(PHEROMON_DIR_EXPLO, 1))
220
+                                  self._get_molecule(PHEROMON_DIR_EXPLO, 1))
221 221
         # le permet
222 222
         self._test_direction_for_points({}, NORTH, re_init=False)
223 223
         self._test_direction_for_point({}, NORTH, re_init=False)
224 224
 
225 225
 
226
-    def _test_point_raise_no_pheromone(self, pheromones={}, direction=-1, pheromone_type=PHEROMON_DIR_EXPLO,
226
+    def _test_point_raise_no_molecule(self, molecules={}, direction=-1, molecule_type=PHEROMON_DIR_EXPLO,
227 227
                                  reference_point=_p(CENTER), re_init=True):
228 228
         try:  # WTF ?
229
-            self._test_direction_for_point(pheromones, direction, re_init=re_init)
230
-        except NoPheromone:
229
+            self._test_direction_for_point(molecules, direction, re_init=re_init)
230
+        except NoMolecule:
231 231
             self.assertTrue(True)
232 232
 
233
-    def _test_points_raise_no_pheromone(self, pheromones={}, direction=-1, pheromone_type=PHEROMON_DIR_EXPLO,
233
+    def _test_points_raise_no_molecule(self, molecules={}, direction=-1, molecule_type=PHEROMON_DIR_EXPLO,
234 234
                                  reference_point=_p(CENTER), re_init=True):
235 235
         try:  # WTF ?
236
-            self._test_direction_for_points(pheromones, direction, re_init=re_init)
237
-        except NoPheromone:
236
+            self._test_direction_for_points(molecules, direction, re_init=re_init)
237
+        except NoMolecule:
238 238
             self.assertTrue(True)
239 239
 
240
-    def _get_pheromone(self, type, distance):
241
-        return Pheromone(PHEROMON_DIRECTION, type, distance=distance)
240
+    def _get_molecule(self, type, distance):
241
+        return Molecule(PHEROMON_DIRECTION, type, distance=distance)

+ 2 - 2
tests.py View File

@@ -5,12 +5,12 @@ from sys import path as ppath
5 5
 ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
6 6
 
7 7
 """
8
-python3.4 -m unittest /home/bux/Projets/socialintengine/intelligine/tests/simulation/mode/TestChangeMode.py && python3.4 -m unittest intelligine/tests/simulation/pheromone/TestDirection.py
8
+python3.4 -m unittest /home/bux/Projets/socialintengine/intelligine/tests/simulation/mode/TestChangeMode.py && python3.4 -m unittest intelligine/tests/simulation/molecule/TestDirection.py
9 9
 """
10 10
 
11 11
 test_modules = [
12 12
     'intelligine.tests.simulation.mode.TestChangeMode.TestChangeMode',
13
-    'intelligine.tests.simulation.pheromone.TestDirection.TestDirection',
13
+    'intelligine.tests.simulation.molecule.TestDirection.TestDirection',
14 14
 ]
15 15
 
16 16
 suite = unittest.TestSuite()