-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevalutation.py
More file actions
55 lines (49 loc) · 1.34 KB
/
evalutation.py
File metadata and controls
55 lines (49 loc) · 1.34 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def cost(route, p, penality):
tot = 0
carico = 0
feasible = True
for i in range(len(route) - 1):
tot += p.dist[route[i]][route[i+1]]
carico += p.demand[route[i]]
if carico > p.C:
feasible = False
tot += (carico - p.C)*penality
return feasible, tot
def evalNWithDepot(sigmaLista):
sigmaList = []
for i in range(len(sigmaLista)):
route = sigmaLista[i][:]
route.append(0)
route.insert(0, 0)
sigmaList.append(route)
return evalN(sigmaList)
def costWithDepot(r, p, penality):
try:
tot = p.dist[0][r[0]] + p.dist[0][r[len(r) - 1]]
except:
return True, 0
feasible = True
carico = 0
for i in range(len(r) - 1):
tot += p.dist[r[i]][r[i+1]]
carico += p.demand[r[i]]
carico += p.demand[r[len(r) - 1]]
if carico > p.C:
feasible = False
tot += (carico - p.C)*penality
return tot
def costWithDepot2(r, p, penality):
try:
tot = p.dist[0][r[0]] + p.dist[0][r[len(r) - 1]]
except:
return True, 0
feasible = True
carico = 0
for i in range(len(r) - 1):
tot += p.dist[r[i]][r[i+1]]
carico += p.demand[r[i]]
carico += p.demand[r[len(r) - 1]]
if carico > p.C:
feasible = False
tot += (carico - p.C)*penality
return feasible, tot