forked from KuMiShi/Optim_Metaheuristique
Adding Power constraints to simulation
This commit is contained in:
9
data/grid_capacity.txt
Normal file
9
data/grid_capacity.txt
Normal 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
62
main.py
@@ -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}')
|
print(f'Capacities of vehicles (kwh): ${capacities}')
|
||||||
return 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 ---
|
# --- EXECUTION FUNCTION ---
|
||||||
def run_scenario(scenario_name, model_type=None):
|
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):
|
||||||
elec_price_csv = 'data/elec_prices.csv'
|
A_MAX, X_MAX, X_MIN = get_power_constants(nb_vehicles=nb_vehicles)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
print(f"\n--- Launching Scenario: {scenario_name} ---")
|
print(f"\n--- Launching Scenario: {scenario_name} ---")
|
||||||
start_time = time.time()
|
|
||||||
|
|
||||||
# Simulation parameters
|
# Simulation parameters
|
||||||
params = {
|
params = {
|
||||||
'A_max': 500, 'price_mean': 0.15, 'price_std': 0.05,
|
'A_max': A_MAX, 'price_mean': price_mean, 'price_std': price_std,
|
||||||
'capacities': [50]*10, 'n': 20, 't': 50,
|
'capacities': capacities, 'n': n, 't': t,
|
||||||
'w': 0.4, 'c1': 2.0, 'c2': 2.0,
|
'w': w, 'c1': c1, 'c2': c2,
|
||||||
'nb_vehicles': 10, 'delta_t': 60, 'nb_of_ticks': 72
|
'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
|
# Instantiate extended class
|
||||||
optimizer = SmartMOPSO(model_type=model_type, **params)
|
optimizer = SmartMOPSO(model_type=model_type, **params)
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
# Run simulation
|
# Run simulation
|
||||||
optimizer.iterate()
|
optimizer.iterate()
|
||||||
|
|
||||||
@@ -144,6 +135,23 @@ def run_scenario(scenario_name, model_type=None):
|
|||||||
|
|
||||||
# --- MAIN ---
|
# --- MAIN ---
|
||||||
if __name__ == "__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 = {}
|
results = {}
|
||||||
|
|
||||||
# 1. Without Surrogate (Baseline)
|
# 1. Without Surrogate (Baseline)
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ class Particle():
|
|||||||
self.x[tick][i] = self.x[tick][i] * 0.9
|
self.x[tick][i] = self.x[tick][i] * 0.9
|
||||||
current_power = self.get_current_grid_stress(tick)
|
current_power = self.get_current_grid_stress(tick)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_position(self):
|
def generate_position(self):
|
||||||
pos = []
|
pos = []
|
||||||
for _ in range(self.nb_of_ticks):
|
for _ in range(self.nb_of_ticks):
|
||||||
|
|||||||
Reference in New Issue
Block a user