Firefly Algorithm: 7. Function Main
Firefly Algorithm: 7. Function Main
1. #main function
2. // dis[] = array of distance from location to ambulance.
3. //equ[] = array of equipment level.
4. //rate[] = array of rating.
5. // disa[] = array of distance from location of accident to hospital.
6.
7. Function main ()
8.
9. For each ambulance in radius
10. distancela(dis[]);
11. equipment(equ[]);
12. rating(rate[]);
13. distancelh(disa[])
14. End loop
15.
16. For each ambulance in radius
17. Fitnessfunction(dis[],equ[],rate[],disa[])
18.
19. }
20.
21. Parameters for fitness function( getting dis[],equ[],rate[],disa[] from main)
22.
23. Function fitnessfuncion(parameters)
24. {
25. For each ambulance in radius
26. disla[i]=1-dis[i]; // Inverting the distance from location to ambulance weightage
27. to find best least distance.
28. dislh[i]=1-disa[i]; // Inverting the distance from location of accident to hospital
29. weightage to 1 find best least distance.
30.
31. End Loop
32.
33. Int max;
34. For each loop in radius
35. weight[]=disla[]+dislh[]+equ[]+rate[];
36. If weight > max
37.
38. max=weight[]; // this function will call the ambulance with maximum weightage
39.
40. End Loop
41.
42. }
43.
44. Parameters for function distancela (dis[] )
45. # dis[x] = value of distance from location to ambulance
46. # function from location to ambulance
47.
48. function distancela (parameters)
49. {
50. # finding max value to normalize distance
51. for each element in array dis[x]
52. if dis[x] > max
53. max=dis[x]
54. End Loop
55. # dividing the values to normalize distance on a scale of 0 to 1
56.
57. for each element in array dis[x]
58. norm[i]=dis[x]/max
59. i++;
60. End Loop
61. # finding and sending lowest distance to function
62. for each element in array norm[x]
63. if(norm[x]<mix)
64. min=norm[x];
65. End Loop
66. return values;
67. }
68.
69.
70. Parameters for function ( equ[] )
71. # equ= array of equipment hardcoded values
72. function equipment ( parameters )
73. {
74. Int max;
75. # normalizing value on a scale of 0 to 1
76. for each element in array equ[x]
77. if equ[i]>max
78. max= rate[i]
79. End Loop
80.
81. #dividing by max
82. for each element in array equ[x]
83. norm[i]=equ[i]/max
84. i++;
85. End Loop
86.
87. #returning the max value to function
88. for each element in array equ[x]
89. if(norm[x]>max)
90. max=norm[x];
91. End Loop
92.
93. return values;
94.
95. }
96.
97. Parameters for Function Rating (rate[])
98. # rate = array of rating values
99.
100. function rating ( parameters )
101. {
102. # normalizing value on a scale of 0 to 1
103. Int max;
104. for each element in array rate[x]
105. if rate[i]>max
106. max= rate[i]
107. End Loop
108.
109. #dividing by max
110. for each element in array rate[x]
111. norm[i]=rate[i]/max
112. i++;
113. End Loop
114.
115. for each element in array norm[x]
116. if(norm[x]>max)
117. max=norm[x];
118. End Loop
119.
120. return values
121.
122. }
123.
124. Parametes for Function distancelh (dis[x])
125. # disa[x] = value of distance from location to ambulance
126. #location from accident place to hospital
127.
128. function distancelh (parameters)
129. {
130. Int max;
131. # finding max value to normalize distance
132. for each element in array disa[x]
133. if disa[x] > max
134. max=disa[x]
135. End Loop
136.
137. # dividing the values to normalize distance on a scale of 0 to 1
138.
139. for each element in array disa[x]
140. norm[i]=disa[x]/max
141. i++;
142. End Loop
143.
144. # finding and sending lowest distance to function
145. for each element in array norm[x]
146. if(norm[x]<mix)
147. min=norm[x];
148. End Loop
149.
150. return values
151.
152. }
153.