forked from johnBuffer/AntSimulator
-
Notifications
You must be signed in to change notification settings - Fork 6
/
psudocode
48 lines (40 loc) · 1.26 KB
/
psudocode
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
Main:
CALL initColony
FOR each_ant in colony
CALL updateAnt
END FOR
Function initColony:
SET patience to patience_max
SET distance_covered = 0
END Function
Function updateAnt:
FOR direction in front semicircle
CALL updatePheromonesIntensity
IF ant_mode is find_food
CALL secretHomePheromone
IF found_food THEN
SET patience to patience_max
SET ant_mode to deliver_food
SET direction to (direction + PI)
RETURN
IF food_pheromone_intensity == 0
SET patience to patience_max
move ant randomly
ELSE IF food_pheromone_intensity < caution_pheromone_intensity
CALL secretPheromoneCautionPheromone
move ant to follow food_pheromone direction
ELSE
move ant randomly
END IF
CALL move_ant
END Function
Function secretHomePheromone
SET coef = 0.01
intensity = 1000*exp(-coef * distance_covered++)
deposit home_pheromone with intensity
END Function
Function secretPheromoneCautionPheromone
SET coef = 0.01
intensity = 1000*exp(-coef * patience--)
deposit home_pheromone with intensity
END Function