From b172e93a8546546396ad38977895d9f9ea506104 Mon Sep 17 00:00:00 2001 From: SihamDaanouni Date: Sat, 17 Jan 2026 22:49:16 +0100 Subject: [PATCH] update without blocking errors --- particle.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/particle.py b/particle.py index 6fdf725..6157579 100644 --- a/particle.py +++ b/particle.py @@ -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,16 @@ class Particle(): current_grid_stress += self.x[tick][i] return current_grid_stress - def updating_socs(self, socs, capacities): - pass \ No newline at end of file + 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é) + 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]) + + self.socs[tick+1][i] = max(0.0, min(1.0, self.socs[tick+1][i])) \ No newline at end of file