-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
98 lines (78 loc) · 2.64 KB
/
Copy pathmain.py
File metadata and controls
98 lines (78 loc) · 2.64 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import csv
import pickle
from collections import defaultdict
import numpy as np
from Node import Node
from VRP import VRP
from geom import Geometric
from scipy import stats
def t_test():
a_file = open("Datos diccionario 2.pkl", "rb")
output = pickle.load(a_file)
N = len(output["Determinista"])
for key in output.keys():
print(np.mean(output[key]))
determinista = output["Determinista"]
stocastico = output["Savings estocástico"]
var_a = np.var(determinista)
var_b = np.var(stocastico)
s = np.sqrt((var_a + var_b) / 2)
t = (np.mean(determinista) - np.mean(stocastico)) / (s * np.sqrt(2 / N))
df = 2 * N - 2
print("p value del t-test: "+ str(1-stats.t.cdf(t, df = df)))
def start(number_nodes, max_demand):
list = []
depot = []
depot.append(Node(5, 5, 0))
depot[0].insert_id("d0")
k = 0
for i in range(number_nodes):
node = Node(np.random.random()*20, np.random.random()*20, np.random.randint(1, max_demand))
node.insert_id(str(k))
list.append(node)
k += 1
return list, depot
if __name__ == '__main__':
Geom = Geometric(0.2, 0.3)
time = 1
iteraciones = 10
resultados = {"Determinista": [], "Estocástico": [], "Savings estocástico": [], "Local Search estocástico": []}
i = 0
while i < iteraciones:
list_original, depot_original = start(20, 5)
list, depot = list_original, depot_original
Sol1 = VRP(list, depot, 10, Geom)
Sol1 = Sol1.deterministic_solve(time)
resultados["Determinista"].append(Sol1.best_mean)
#Sol1.show()
del Sol1
list, depot = list_original, depot_original
Sol2 = VRP(list, depot, 10, Geom)
Sol2 = Sol2.stochastic_solve(time)
resultados["Estocástico"].append(Sol2.best_mean)
#Sol2.show()
del Sol2
list, depot = list_original, depot_original
Sol3 = VRP(list, depot, 10, Geom)
Sol3 = Sol3.stochastic_savings_solve(time)
resultados["Savings estocástico"].append(Sol3.best_mean)
#Sol3.show()
del Sol3
list, depot = list_original, depot_original
Sol4 = VRP(list, depot, 10, Geom)
Sol4 = Sol4.stochastic_local_search_solve(time)
resultados["Local Search estocástico"].append(Sol4.best_mean)
#Sol4.show()
del Sol4
print("\n")
i += 1
a_file = open("Datos diccionario.pkl", "wb")
pickle.dump(resultados, a_file)
a_file.close()
'''
a_file = open("Datos diccionario 2.pkl", "rb")
output = pickle.load(a_file)
print(output)
'''
#print(resultados)
t_test()