Skip to content

Commit c452c43

Browse files
caiselvasrogerbaigespaupratAI
committed
falta exp 5
Co-authored-by: rogerbaiges <[email protected]> Co-authored-by: paupratAI <[email protected]>
1 parent f296a1d commit c452c43

24 files changed

+502
-174
lines changed
8.45 KB
Binary file not shown.
Binary file not shown.
826 Bytes
Binary file not shown.
252 Bytes
Binary file not shown.

beneficio_respecto_furgonetas.png

27.9 KB
Loading

beneficios.png

-21.3 KB
Binary file not shown.

beneficios_h1.png

19.9 KB
Loading

beneficios_h2.png

19.9 KB
Loading

distancias.png

-17.6 KB
Binary file not shown.

distancias_h1.png

20.9 KB
Loading

distancias_h2.png

23.5 KB
Loading

evolucion_tiempos_aumento.png

48.9 KB
Loading

experimento2.png

30.6 KB
Loading

functions_bicing.py

+248-112
Large diffs are not rendered by default.

generate_initial_state_bicing.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ def generate_initial_state(opt: int = 0, \
5757

5858
n_estaciones_origen = len(lista_est_excedente)
5959
n_estaciones_destino = len(lista_est_faltante)
60-
60+
61+
# Para evitar que el código se rompa si no hay suficientes estaciones con diferencia positiva o negativa
62+
while len(lista_est_excedente) < n_furgonetas:
63+
nueva_estacion = rng.randint(0, n_estaciones - 1)
64+
if nueva_estacion not in lista_est_excedente:
65+
lista_est_excedente.append(nueva_estacion)
66+
lista_est_faltante.pop(lista_est_faltante.index(nueva_estacion))
67+
68+
while len(lista_est_faltante) < 1:
69+
nueva_estacion = rng.randint(0, n_estaciones -1)
70+
if nueva_estacion not in lista_est_excedente:
71+
lista_est_faltante.append(nueva_estacion)
72+
73+
6174
for furgoneta in lista_furgonetas:
6275
# Asignamos una estación de origen a la furgoneta
6376
id_est_o = rng.randint(0, n_estaciones_origen - 1)
@@ -85,8 +98,26 @@ def generate_initial_state(opt: int = 0, \
8598
elif est['dif'] > 0 and est['disp'] > 0:
8699
lista_est_excedente.append((est['dif'], est['index']))
87100

101+
n_estaciones_origen = len(lista_est_excedente)
102+
n_estaciones_destino = len(lista_est_faltante)
103+
88104
lista_est_excedente.sort(reverse=True)
89105
lista_est_faltante.sort()
106+
107+
# Para evitar que el código se rompa si no hay suficientes estaciones con diferencia positiva o negativa
108+
while len(lista_est_excedente) < n_furgonetas:
109+
nueva_estacion = rng.randint(0, n_estaciones - 1)
110+
if nueva_estacion not in lista_est_excedente:
111+
lista_est_excedente.append((None, nueva_estacion))
112+
for i, est in enumerate(lista_est_faltante):
113+
if est[1] == nueva_estacion:
114+
lista_est_faltante.pop(i)
115+
break
116+
117+
while len(lista_est_faltante) < 2*n_furgonetas:
118+
nueva_estacion = rng.randint(0, n_estaciones -1)
119+
if nueva_estacion not in lista_est_excedente and nueva_estacion not in lista_est_faltante:
120+
lista_est_faltante.append((None, nueva_estacion))
90121

91122
# Asignación tipo 1
92123
j = 0
@@ -95,16 +126,6 @@ def generate_initial_state(opt: int = 0, \
95126
furgoneta.id_est_dest1 = lista_est_faltante[j][1]
96127
furgoneta.id_est_dest2 = lista_est_faltante[j+1][1]
97128
j += 2
98-
99-
# Asignación tipo 2
100-
"""j = 0
101-
for i, furgoneta in enumerate(lista_furgonetas):
102-
furgoneta.id_est_origen = lista_est_excedente[i][1]
103-
104-
furgoneta.id_est_dest1 = lista_est_faltante[j][1]
105-
furgoneta.id_est_dest2 = lista_est_faltante[j+params.n_furgonetas][1]
106-
j += 1"""
107-
108129

109130
state = EstadoBicing(lista_furgonetas=lista_furgonetas, operadores_activos=operadores_activos)
110131
return state

main.py

+79-42
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,120 @@
1-
from functions_bicing import comparar_all_operadores, mejor_initial_state, encontrar_parametros_SA ,comparar_resultados_HC_SA
2-
from math import exp
1+
from functions_bicing import comparar_all_operadores, mejor_initial_state, encontrar_parametros_SA ,comparar_resultados_HC_SA, tiempos_experimento_con_aumento, augmento_furgonetas
2+
import random
33

44
# Función de ejecución de experimentos
5-
def experimento1(opt: int, semilla: int) -> None:
5+
def experimento1(opt: int, lista_semillas: list, iteraciones_por_semilla: int) -> None:
66
# Experimento 1: Comparación de operadores
77
comparar_all_operadores(opt=opt, \
8-
semilla_rng=semilla, \
9-
iteraciones=15)
8+
lista_semillas=lista_semillas, \
9+
iteraciones_por_semilla=iteraciones_por_semilla)
1010

11-
12-
def experimento2(operadores_resultado_exp1: dict, semilla_rng: int, iteraciones: int) -> None:
11+
def experimento2(operadores_resultado_exp1: dict, lista_semillas: list, iteraciones_estrategias_aleatorias: int) -> None:
1312
# Experimento 2: Comparación de initial_state
14-
mejor_initial_state(iteraciones=iteraciones, \
15-
semilla_rng=semilla_rng, \
13+
mejor_initial_state(iteraciones_estrategias_aleatorias=iteraciones_estrategias_aleatorias, \
14+
lista_semillas=lista_semillas, \
1615
operadores_activos=operadores_resultado_exp1)
1716

18-
def experimento3(operadores_resultado_exp1: dict, opt_resultado_exp2: int, valores_k: list, valores_lam: list, limite: int) -> None:
17+
def experimento3(iteraciones_por_semilla: int, lista_semillas: list, operadores_resultado_exp1: dict, opt_resultado_exp2: int, valores_k: list, valores_lam: list, limite: int) -> None:
1918
# Experimento 3: Comparación de SA
20-
encontrar_parametros_SA(opt=opt_resultado_exp2, \
19+
encontrar_parametros_SA(lista_semillas=lista_semillas, \
20+
opt=opt_resultado_exp2, \
2121
operadores_activos=operadores_resultado_exp1, \
2222
valores_k=valores_k, \
2323
valores_lam=valores_lam, \
2424
limit=limite, \
25-
iteraciones_por_valor=10)
26-
27-
def experimento4() -> None:
25+
iteraciones_por_semilla=iteraciones_por_semilla)
26+
27+
def experimento4(operadores_resultado_exp1: dict, \
28+
opt_resultado_exp2: int, \
29+
incremento_estaciones: int, \
30+
incremento_furgonetas: int, \
31+
incremento_bicicletas: int, \
32+
lista_semillas: list, \
33+
n_incrementos: int) -> None:
2834
# Experimento 4: Comparación de HC
29-
comparar_resultados_HC_SA(opt=2, HC=True, SA=False, iterations=100)
30-
31-
def experimento5() -> None:
35+
tiempos_experimento_con_aumento(opt=opt_resultado_exp2, \
36+
operadores_activos=operadores_resultado_exp1, \
37+
incremento_estaciones=incremento_estaciones, \
38+
incremento_furgonetas=incremento_furgonetas, \
39+
incremento_bicicletas=incremento_bicicletas, \
40+
lista_semillas=lista_semillas,
41+
n_incrementos=n_incrementos)
42+
43+
def experimento5(operadores_resultado_exp1: dict, opt_resultado_exp2: int, k, lam ,limite, lista_semillas: list, iteraciones_por_replica: int) -> None:
3244
# Experimento 5: Comparación de HC y SA
33-
34-
def exp_schedule(k: float=k, lam: float=lam, limit: int=limit):
35-
return lambda t: (k * exp(-lam * t)) if t < limit else 0
36-
37-
comparar_resultados_HC_SA(opt=2, HC=True, SA=True, iterations=50, schedule_sa=exp_schedule())
38-
39-
def experimento6() -> None:
40-
# Experimento 6: Comparación de HC y SA
41-
42-
def exp_schedule(k: float=k, lam: float=lam, limit: int=limit):
43-
return lambda t: (k * exp(-lam * t)) if t < limit else 0
44-
45-
comparar_resultados_HC_SA(opt=2, HC=True, SA=True, iterations=50, schedule_sa=exp_schedule())
45+
comparar_resultados_HC_SA(opt=opt_resultado_exp2, \
46+
HC=True, \
47+
SA=True, \
48+
lista_semillas=lista_semillas, \
49+
k=k, \
50+
lam=lam, \
51+
limit=limite, \
52+
operadores_activos=operadores_resultado_exp1, \
53+
iteraciones_por_replica=iteraciones_por_replica, \
54+
coste_transporte=False)
55+
56+
comparar_resultados_HC_SA(opt=opt_resultado_exp2, \
57+
HC=True, \
58+
SA=True, \
59+
lista_semillas=lista_semillas, \
60+
k=k, \
61+
lam=lam, \
62+
limit=limite, \
63+
operadores_activos=operadores_resultado_exp1, \
64+
iteraciones_por_replica=iteraciones_por_replica, \
65+
coste_transporte=True)
66+
67+
def experimento6(operadores_resultado_exp1: dict, \
68+
opt_resultado_exp2: int, \
69+
incremento_furgonetas: int, \
70+
lista_semillas: list, \
71+
n_incrementos: int) -> None:
72+
# Experimento 6: Comparación de HC augmentando las furgonetas
73+
augmento_furgonetas(opt=opt_resultado_exp2, \
74+
operadores_activos=operadores_resultado_exp1, \
75+
incremento_furgonetas=incremento_furgonetas, \
76+
lista_semillas=lista_semillas,
77+
n_incrementos=n_incrementos)
4678

4779
#######################################################################################################################
4880

4981
# Programa principal
5082
if __name__ == "__main__":
83+
# Creación de la lista de semillas
84+
rng = random.Random(1234)
85+
n_semillas: int = 10
86+
lista_semillas: list = [42] + [rng.randint(0, 1000) for _ in range(n_semillas - 1)]
87+
print(f"Lista de {n_semillas} semillas para los experimentos: {lista_semillas}")
5188

5289
# ----- Experimento 1 -----
53-
#experimento1(opt=1, semilla=1234)
90+
#experimento1(opt=1, lista_semillas=lista_semillas, iteraciones_por_semilla=10)
5491

5592
operadores_exp1: dict = {'CambiarOrdenDescarga': True, \
5693
'IntercambiarEstacionDescarga': False, \
57-
'IntercambiarEstacionCarga': False, \
94+
'IntercambiarEstacionCarga': True, \
5895
'ReasignarFurgonetaInformado': True}
5996

6097
# ----- Experimento 2 -----
61-
#experimento2(operadores_resultado_exp1=operadores_exp1, semilla_rng=1234, iteraciones=100)
98+
#experimento2(operadores_resultado_exp1=operadores_exp1, lista_semillas=lista_semillas, iteraciones_estrategias_aleatorias=5)
6299

63100
opt_exp2: int = 2
64101

65102
# ----- Experimento 3 -----
66-
valores_k: list = [0.001, 0.01, 0.1, 1, 10, 100]
67-
valores_lam: list = [0.0001, 0.001, 0.01, 0.1, 0.99]
68-
limite: int = 15_000
103+
valores_k: list = [1, 0.01]#[0.001, 0.01, 0.1, 1, 10, 100]
104+
valores_lam: list = [0.1, 0.01, 0.001]#[0.0001, 0.001, 0.01, 0.1, 0.99]
105+
limite: int = 25_000
69106

70-
experimento3(operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2, valores_k=valores_k, valores_lam=valores_lam, limite=limite)
107+
#experimento3(iteraciones_por_semilla=1, lista_semillas=lista_semillas, operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2, valores_k=valores_k, valores_lam=valores_lam, limite=limite)
71108

72-
k_exp3: float = 0.1
109+
k_exp3: float = 1
73110
lam_exp3: float = 0.1
74-
limite_exp3: float = 15000
111+
limite_exp3: int = 1000
75112

76113
# ----- Experimento 4 -----
77-
#experimento4(operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2)
114+
#experimento4(lista_semillas=lista_semillas, operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2, incremento_estaciones=25, incremento_furgonetas=5, incremento_bicicletas=1250, n_incrementos=8)
78115

79116
# ----- Experimento 5 -----
80-
#experimento5(operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2)
117+
experimento5(iteraciones_por_replica=10, lista_semillas=lista_semillas, k=k_exp3, lam=lam_exp3, limite=limite_exp3, operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2)
81118

82119
# ----- Experimento 6 -----
83-
#experimento6(operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2)
120+
#experimento6(lista_semillas=lista_semillas, operadores_resultado_exp1=operadores_exp1, opt_resultado_exp2=opt_exp2, incremento_furgonetas=5, n_incrementos=9)

parameters_bicing.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
33
class Parameters:
44
def __init__(self, n_estaciones: int, n_bicicletas: int, n_furgonetas: int, seed: int, coste_transporte: bool = True, operadores_modificables: set = {}) -> None:
55
assert n_estaciones > n_furgonetas, "El número de estaciones debe ser mayor que el número de furgonetas"
6+
self.coste_transporte = coste_transporte
7+
self.operadores_modificables = operadores_modificables
8+
self.seed = seed
69
self.n_estaciones = n_estaciones
10+
self.n_furgonetas = n_furgonetas
711
self.n_bicicletas = n_bicicletas
12+
13+
self.actualizar_estaciones(n_estaciones=n_estaciones, n_furgonetas=n_furgonetas, n_bicicletas=n_bicicletas)
14+
15+
def actualizar_estaciones(self, \
16+
n_estaciones: int, \
17+
n_furgonetas: int, \
18+
n_bicicletas: int) -> None:
19+
self.n_estaciones = n_estaciones
820
self.n_furgonetas = n_furgonetas
9-
self.coste_transporte = coste_transporte
10-
self.seed = seed
11-
self.estaciones: list[Estacion] = Estaciones(num_estaciones=n_estaciones, num_bicicletas=n_bicicletas, semilla=seed).lista_estaciones
12-
self.operadores_modificables = operadores_modificables
21+
self.n_bicicletas = n_bicicletas
22+
self.estaciones = Estaciones(num_estaciones=n_estaciones, num_bicicletas=n_bicicletas, semilla=self.seed).lista_estaciones
23+
24+
def actualizar_semilla(self, semilla: int) -> None:
25+
self.seed = semilla
26+
self.actualizar_estaciones(n_estaciones=self.n_estaciones, n_furgonetas=self.n_furgonetas, n_bicicletas=self.n_bicicletas)
1327

1428
params = Parameters(n_estaciones=25, \
1529
n_bicicletas=1250, \

parametros_SA_2.png

-48.3 KB
Binary file not shown.

parametros_SA_25k.png

36.6 KB
Loading

0 commit comments

Comments
 (0)