Adding Power constraints to simulation

This commit is contained in:
KuMiShi
2026-01-18 13:43:44 +01:00
parent b3f51d8363
commit d1c2475d1b
3 changed files with 44 additions and 29 deletions

9
data/grid_capacity.txt Normal file
View File

@@ -0,0 +1,9 @@
| Maximum | Minimum
---------------------------------------------------
Consumption (Winter)| 87 028 Mwh | 46 847 Mwh
(Summer)| 52 374 Mwh | 29 819 Mwh
---------------------------------------------------
Production (Winter)| 91 341 Mwh | 72 926 Mwh
(Summer)| 86 579 Mwh | 49 127 Mwh
Winter correspond to S2-S5 and Summer correspond to S29-S32 (same as prices)

62
main.py
View File

@@ -90,44 +90,35 @@ def generate_capacities(csv_file:str, nb_vehicles:int, seed:int=42, sep:str=';')
print(f'Capacities of vehicles (kwh): ${capacities}')
return capacities
def get_power_constants(nb_vehicles:int, nb_consumers:int=67000000):
mean_consumption = (87028 + 46847 + 52374 + 29819)/4 # Mean of consumption in France in 2025 (estimate according to data/grid_capacity.txt)
sim_ratio = nb_vehicles / nb_consumers # Ratio to reduce A_max of simulation to realistic restrictions
a_max = sim_ratio * mean_consumption
x_max = a_max / nb_vehicles # For init, uniform charging/discharging for every vehicle
x_min = -x_max
return a_max, x_max, x_min
# --- EXECUTION FUNCTION ---
def run_scenario(scenario_name, model_type=None):
elec_price_csv = 'data/elec_prices.csv'
capacity_csv = 'data/vehicle_capacity.csv'
# Simulation parameters
N = 20 # Number of vehicles
T = 30 # Number of iterations (for the particles)
W = 0.4 # Inertia (for exploration)
C1 = 0.3 # Individual trust
C2 = 0.2 # Social trust
ARC_SIZE = 10 # Archive size
P_MEAN, P_STD = calculate_elec_prices(elec_price_csv)
CAPACITIES = generate_capacities(capacity_csv, N)
NB_TICKS = 48
DELTA = 60
A_MAX = 0
X_MAX = 0
X_MIN = 0
def run_scenario(scenario_name, capacities:list, price_mean:float, price_std:float, model_type=None, n:int=20, t:int=30, w:float=0.4, c1:float=0.3, c2:float=0.2, archive_size:int=10, nb_vehicles:int=10, delta_t:int=60, nb_of_ticks:int=48):
A_MAX, X_MAX, X_MIN = get_power_constants(nb_vehicles=nb_vehicles)
print(f"\n--- Launching Scenario: {scenario_name} ---")
start_time = time.time()
# Simulation parameters
params = {
'A_max': 500, 'price_mean': 0.15, 'price_std': 0.05,
'capacities': [50]*10, 'n': 20, 't': 50,
'w': 0.4, 'c1': 2.0, 'c2': 2.0,
'nb_vehicles': 10, 'delta_t': 60, 'nb_of_ticks': 72
'A_max': A_MAX, 'price_mean': price_mean, 'price_std': price_std,
'capacities': capacities, 'n': n, 't': t,
'w': w, 'c1': c1, 'c2': c2,
'nb_vehicles': nb_vehicles, 'delta_t': delta_t, 'nb_of_ticks': nb_of_ticks,
'x_min':X_MIN, 'x_max':X_MAX
}
# Instantiate extended class
optimizer = SmartMOPSO(model_type=model_type, **params)
start_time = time.time()
# Run simulation
optimizer.iterate()
@@ -144,6 +135,23 @@ def run_scenario(scenario_name, model_type=None):
# --- MAIN ---
if __name__ == "__main__":
# CSV files
elec_price_csv = 'data/elec_prices.csv'
capacity_csv = 'data/vehicle_capacity.csv'
# Global Simulation parameters
T = 30 # Number of iterations (for the particles)
W = 0.4 # Inertia (for exploration)
C1 = 0.3 # Individual trust
C2 = 0.2 # Social trust
ARC_SIZE = 10 # Archive size
P_MEAN, P_STD = calculate_elec_prices(elec_price_csv)
CAPACITIES = generate_capacities(capacity_csv, N)
NB_TICKS = 48
DELTA = 60
results = {}
# 1. Without Surrogate (Baseline)

View File

@@ -64,8 +64,6 @@ 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 generate_position(self):
pos = []