# Tutorial 1: EVs and Scenarios See `tutorial/tutorial_1_EVs_and_Scenarios.mlx`. This tutorial includes advanced topics on `EV` and `Scenario`. You can refer to [EV](../src/class/EV.md) and [Scenario](../src/class/Scenario.md) while following this tutorial to better understand the methods and properties discussed here. ## An `EV` object ### 1. Create an `EV` object An `EV`object contains information such as the arrival/departure time of an EV, battery capacity, initially stored energy, reference energy. The following syntax creates EV objects. ```matlab ev1 = EV(); % Create an EV object with default parameters. ev2 = EV(Arr_time=2, Dep_time=6); % Create an EV object with name-value arguments. ``` Once created, the properties of an EV object can be modified using `set()` method. (Directly changing the properties is forbidden.) ```matlab ev1 = set(ev1,E_ini=40); ev2 = ev2.set(E_ref=80); ``` ### 2. Validate an `EV` object Each EV object has a property named `valid`, which indicates whether the object has passed a validation process. ```matlab ev1.valid ev2.valid ``` The following syntax executes a validation process and chage `valid` true if all the requirements (e.g., `Arr_time < Dep_time`, `E_ref <= E_cap`) for an EV object are satisfied. ```matlab ev1 = validate(ev1); ev2 = ev2.validate(); ev1.valid ev2.valid ``` However, modifying a property afterward requires an additional validation. ```matlab ev1 = set(ev1,U_max=15); ev1.valid ``` ## A `Scenario` object A `Scenario` object is an object that contains all information describing a charging scheduling problem, such as the base load profile, electricity price, limits on charging powers, EV behaviors, and topology of communication infrastructure. ### 1. Import a scenario from json Navigate to the `tutorial/Sample_Lf` folder. Inspect the following files. "Sample_LF_cent.json" and "Sample_LF_dist.json" that contain all key information - "Baseload.xlsx" that contains a base load profile - "EV_Lf.xlsx" that contains all EV information: arrival/departure times, battery capacities, etc To create a scenario object by importing the information provided in these files, execute the following. ```matlab scenario1 = import_scenario('Sample_Lf_cent.json'); ``` ### 2. Create a scenario manually Indeed, it is possible to create a scenario object manually. ```matlab Problem_type = "Lf"; % We focus on the load flattening problem T = 3; % Consider three time slots Delta = 10; % of length 10 minutes. D = [100; 150; 100]; % The base load at each time slot is 100kW, 150kW, 100kW. N_c = 2; % We consider two chargers N_ev = 2; % and two EVs. EVs = [ev1, ev2]; % EVs contains information about the two EVs. scenario2 = Scenario(Problem_type=Problem_type, ... T=T, ... Delta=Delta, ... D=D, ... N_c=N_c, ... N_ev=N_ev,... EVs=EVs); % Now we can create a scenario object. ``` ### 3. Generate a scenario from ScenarioGenerator object Another method is to instanciate a ScenarioGenerator object and generate a scenario from it. ```matlab gen = PoissonScenarioGenerator(T=24); % Instantiate a PoissonScenarioGenerator % object that generates scenarios of length 24. % Here, we set other parameters to default values. scenario3 = generate(gen); % Then, generate a scenario from it. ``` ### 4. Validate a scenario A Scenario object also has a property named `valid` which indicates whether the object has passed the validation process. ```matlab scenario1.valid scenario2.valid scenario3.valid ``` One can see that both `scenario_1` and `scenario_3` are valid, whereas `scenario_2` is not. This is because the functions `import_scenario()` and `generate()` of `PoissonScenarioGenerator` automatically perform a validation process. Here, we demonstrate the validation process for `scenario_2`. ```matlab scenario2 = validate(scenario2); scenario2.valid ``` All scheduling functions provided in SH-V2G-Simulatior undergo this scenario validation process before executing the scheduling. ```{note} `validate()` includes the validation of all contained EV objects. ``` ### 5.Modifying properties of a scenario The properties of a scenario object can be modified by `set()` method. ```matlab scenario2 = set(scenario2,Delta=30); scenario2 = scenario2.set(N_c=3); ``` A single EV object can be replaced using `set_ev()` method. ```matlab ev2_new = EV(Charger_ind=3); scenario2 = scenario2.set_ev(2,ev2_new); ``` However, again, modifying a property afterward requires an additional validation. ```matlab scenario2.valid ``` ### 6. Obtaining a subscenario from a scenario In some cases, it is required to generate a subscenario from a given scenario, for example, when performing scheduling in a receding horizon manner or when analyzing the results. The method `get_subscenario()` supports this functionality with various options. The name-value arguments `ini` and `fin` specify the initial time slot and the final time slot for obtaining a subscenario. ```matlab subscenario_1a = scenario1.get_subscenario(ini=2,fin=5); ``` - `subscenario_1a` corresponds to the time slot 2, 3, 4 of the `scenario1`. - `subscenario_1a.EVs` consists of the EVs that is connected to a charger at some time slot among 2, 3, 4. Setting `future_evs=false` makes the subscenario exclude the EVs that arrives in the future (i.e., at time slots after `ini`). ```matlab subscenario_1b = scenario1.get_subscenario(ini=2,fin=5,future_evs=false); ``` - `subscenario_1b.EVs` consists of the EVs that is connected to a charger at time slot 2. By providing `E_ini` argument we can set the E_ini of the EVs in the subscenario. ```matlab subscenario_1c = scenario1.get_subscenario(ini=2,fin=5,E_ini=zeros(1,50)); subscenario_1a.EVs(1).E_ini subscenario_1c.EVs(1).E_ini ``` - For each i, `subscenario_1c.EVs(i).E_ini` is set to 0.