-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevaluation.py
More file actions
34 lines (28 loc) · 1.07 KB
/
evaluation.py
File metadata and controls
34 lines (28 loc) · 1.07 KB
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
import math
import routemain
#This function will unpack the orders inorder to pass them separately
def unpack(individual,orders):
result = [[] for _ in range(max(individual)+1)]
for i, elem in enumerate(orders):
result[individual[i]].append(elem)
return result
#use another gentic algorithm to evaluate fitness
def fitness_fun(individual,orders,all_fitness,all_solution,routehis,routere,routesurvivor):
#if the result has been evulated before, we use the result we stored
key1 = str(individual)
if key1 in all_fitness:
return all_fitness[key1]
total_distance = 0
result = unpack(individual,orders)
s = []
for deliveryman in result:
if deliveryman == []:
total_distance = total_distance
else:
solutions = routemain.main(deliveryman,routehis,routere,routesurvivor)
total_distance = total_distance + solutions[0][0]
s.append(solutions[0][1])
all_solution.append([total_distance,s])
all_fitness[key1]=total_distance
# student code end
return total_distance