update without blocking errors

This commit is contained in:
2026-01-17 23:19:22 +01:00
parent 41c3134c9f
commit 345ac1166c

View File

@@ -1,12 +1,14 @@
import random as rd
import copy
class Particle():
def __init__(self,socs:list, nb_vehicles:int=10, delta_t:int=60, nb_of_ticks:int=72, x_min=-100, x_max=100, alpha=0.1):
def __init__(self, socs:list, times:list, nb_vehicles:int=10, delta_t:int=60, nb_of_ticks:int=72, x_min=-100, x_max=100, alpha=0.1):
# Problem specific attributes
self.nb_vehicles = nb_vehicles # Number of vehicles handles for the generations of position x
self.delta_t = delta_t # delta_t for update purposes
self.nb_of_ticks = nb_of_ticks # Accounting for time evolution of the solution (multiplied by delta_t)
self.socs = socs # States of charges for the particle current position (self.x)
self.times = times
# Minima and maxima of a position value
self.x_min = x_min
@@ -62,11 +64,8 @@ class Particle():
if self.x[tick][i] > 0:
self.x[tick][i] = self.x[tick][i] * 0.9
current_power = self.get_current_grid_stress(tick)
def update_socs(self, capacities):
for tick in range(self.nb_of_ticks):
for i in range(self.nb_vehicles-1):
self.socs[tick][i+1] = self.socs[tick][i] + (self.x[tick][i] / capacities[i])
def generate_position(self):
pos = []
@@ -91,7 +90,7 @@ class Particle():
# Function objective
def evaluate(self,elec_prices,socs,socs_req,times):
f1 = self.f1(elec_prices)
f2 = self.f2(socs,socs_req,times)
f2 = self.f2(self.socs,socs_req,times)
f3 = self.f3()
# Keeping in memory evaluation of each objective for domination evaluation
@@ -103,13 +102,13 @@ class Particle():
self.f_current = f_current
def update_best(self):
current_better = (self.f_current[0] >= self.f_best[0]) and (self.f_current[1] >= self.f_best[1]) and (self.f_current[2] >= self.f_best[2])
current_better = (self.f_current[0] <= self.f_best[0]) and (self.f_current[1] <= self.f_best[1]) and (self.f_current[2] <= self.f_best[2])
if current_better:
# Not strict superiority yet
current_dominates = (self.f_current[0] > self.f_best[0]) or (self.f_current[1] > self.f_best[1]) or (self.f_current[2] > self.f_best[2])
current_dominates = (self.f_current[0] < self.f_best[0]) or (self.f_current[1] < self.f_best[1]) or (self.f_current[2] < self.f_best[2])
if current_dominates:
self.p_best = self.x
self.f_best = self.f_current
self.p_best = copy.deepcopy(self.x)
self.f_best = self.f_current[:]
# Calculate the price of the electricity consumption in the grid SUM(1_to_T)(Epsilon_t * A_t * delta_t)
def f1(self,elec_prices):
@@ -142,5 +141,18 @@ class Particle():
current_grid_stress += self.x[tick][i]
return current_grid_stress
def updating_socs(self, socs, capacities):
pass
def updating_socs(self, initial_socs, capacities):
# Calcul de l'évolution temporelle
for tick in range(self.nb_of_ticks - 1): # On s'arrête à l'avant-dernier pour calculer le suivant
for i in range(self.nb_vehicles):
# SoC(t+1) = SoC(t) + (Puissance(t) * delta_t / Capacité)
# Attention: x est en kW, delta_t en minutes -> conversion en heures (/60) si capacité en kWh
energy_added = (self.x[tick][i] * (self.delta_t / 60))
# Mise à jour du tick suivant basé sur le tick actuel
# On utilise initial_socs comme base si c'est une liste de listes [tick][vehicule]
self.socs[tick+1][i] = self.socs[tick][i] + (energy_added / capacities[i])
# Bornage entre 0 et 1 (0% et 100%)
self.socs[tick+1][i] = max(0.0, min(1.0, self.socs[tick+1][i]))