This repository contains MATLAB scripts and Simulink models used for the modeling, simulation, and optimization of a dynamic energy system. Two different demand response (DR) schemes are implemented:
-
Cost / CO₂ minimization:
The Grey Wolf Optimizer (GWO) is used to minimize the objective function related to energy cost and CO₂ emissions. -
Loss minimization:
The DR strategy aims at minimizing power losses in the network (power lines and transformer).
-
codes/
MATLAB scripts and functions. -
models/
Simulink models (.slx). -
results/
Simulation results (.mat,.fig). -
flowcharts of the 2 scenarios ('.png')
- MATLAB
- Simulink
- (Optional) Optimization / Global Optimization / Neural Network toolboxes, if required by the scripts.
- Open MATLAB.
- Run
initial_conditions.m. - Open and run
no_demand_res.slx.
After the simulation finishes, runno_demand_results.mto store the results. - Run
filter_no_signals.mto extract the correct 24-hour values for each measurement.
- Run one of the following optimization scripts:
gwo_nn_comb_co2.m(CO₂-oriented objective), orgwo_nn_comb_cost.m(cost-oriented objective).
- Open and run
with_demand_res_final_v5.slx.
After the simulation finishes, runwith_demand_results.m. - Run
filter_with_signals.mto extract the correct 24-hour values for each measurement.
→ Cost/CO₂-minimizing DR scenario completed.
- Close and reopen MATLAB (to clear the workspace).
- Run
initial_conditions.mto initialize the first iteration. - Open only
with_demand_res_final_v5_live.slx. - Run
gwo_live_simulation_v2.mand wait until all simulations and the GWO optimization are completed. - After completion, you will obtain:
loss_history_figure.figload_compar.matload_history.mat
- Now in order to have the simulation results from the load that minimize the losses open and run the "with_demand_res_loss_verify"
- Run
filter_with_loss_signals.mto extract the correct 24-hour values for each measurement. - Run
calculate_cost_kgCO2.mto compute the total cost and CO₂ emissions for this scenario.
- Compare the two DR scenarios (cost/CO₂ minimization vs. loss minimization) using the generated
.matfiles and figures inresults/.