# pip install pulp si besoin
import pulp as pl
# ==============================
# Paramètres du problème
# ==============================
T = 24 # nombre d'heures
time_range = range(T)
P_ch_max = 50.0 # kW, puissance max de charge
P_dis_max = 50.0 # kW, puissance max de décharge
E_max = 200.0 # kWh, capacité max de la batterie
eta_ch = 0.95 # rendement de charge
eta_dis = 0.95 # rendement de décharge
E_init = 100.0 # kWh, énergie initiale dans la batterie
# Exemple de profil PV disponible pour la charge batterie (à adapter)
P_PV_ch = {t: 0.0 for t in time_range} # ici mis à 0 pour l'exemple
# ==============================
# Modèle MILP
# ==============================
model = pl.LpProblem("Gestion_Batterie_PV_Reseau", pl.LpMinimize)
# ==============================
# Variables de décision
# ==============================
# Puissance de charge et décharge (continues, >= 0)
P_ch = pl.LpVariable.dicts("P_ch", time_range, lowBound=0, upBound=P_ch_max)
P_dis = pl.LpVariable.dicts("P_dis", time_range, lowBound=0, upBound=P_dis_max)
# Énergie stockée dans la batterie (SoC)
E = pl.LpVariable.dicts("E", time_range, lowBound=0, upBound=E_max)
# Variables binaires pour modes charge / décharge
u_ch = pl.LpVariable.dicts("u_ch", time_range, lowBound=0, upBound=1, cat=pl.LpBinary)
u_dis = pl.LpVariable.dicts("u_dis", time_range, lowBound=0, upBound=1, cat=pl.LpBinary)
# ==============================
# Contraintes
# ==============================
for t in time_range:
# 1) Lien puissances ↔ binaires (activation par les binaires)