# Quick Demo This quick demo enables users to solve an optimal scheduling problem and visualize the results, using the provided samples. Before running the demo, make sure you have completed the [Installation](install.md) steps. After installation, it is necessary to add the paths where the main functions are located. Perform the following command at the root directory. ``` addpath(genpath('src')) ``` This command adds the folders ``src`` and its sub-folders to the tentative paths. Unless you perform ``savepath``, these paths disappear when you quit MATLAB. ## Solve an optimal scheduling using a sample scenario Navigate to the ``tutorial/Samples/`` folder, and execute the following command: ```matlab % Step 1. Parse the JSON configuration file and two Excel inputs indicated in the JSON file my_sc = import_scenario('Sample_Lf.json'); ``` This creates a variable ``my_sc`` of the ``Scenario`` object. To inspect this variable, one can perform: ```matlab openvar('my_sc') ``` and browse the contents inside the variable. This variable contains all the necessary information to solve the optimization problem which is, in this case, the load flattening problem. Now perform ```matlab % Step 2. Solve the optimization problem out = schedule(my_sc, 'cent'); ``` which solves the optimization problem to find an optimal scheduling. Here we used the centralized method (indicated by the `'cent'` option) for example. The solution and its related information are contained in the structured variable `out`. One can inspect the variable by usual methods or by ``openvar('out')``. Now perform ```matlab U = out.u; T = 1:out.scenario.T; stem(T,U(:,28)) ``` which draw the charging/discharing schedule for the charger 28, for example. Note that this is the schedule of a charger. In order to figure out which EV uses the charger 28, one can perform: ```matlab for i = 1:my_sc.N_ev if my_sc.EVs(i).Charger_ind == 28 i disp(my_sc.EVs(i)) end end ``` which displays all the EVs that uses the charger 28. One can see the arrival and the departure time of the EVs as well. One can also employ a simulation command: ```matlab % Step 3. Run a batch simulation for comparison sim_out = simulate(my_sc, oracle = true, cent = true, dist = true) ``` to perform three different simulations using the same scenario; that is, a centralized & receding horizon optimization is performed by ``cent = true``, a distributed & receding horizon optimization is also performed by ``dist = true``, and finally a centralized (not receding-horizon) optimization is performed as well by ``oracle = true``. The outcomes of these three simulations are stored in the structure variable ``sim_out``. One can save the variable ``sim_out`` using the command ``save`` for future use (which creates the MATLAB data file with the extension ``.mat``). In this case, one should use the following command: ```matlab save("your_file_name.mat","-struct","sim_out") ``` When you retrieve the data, use ```matlab sim_out = load("your_file_name.mat") ``` to create the struct variable ``sim_out``. This above command ``simulate`` may take a long time because the distributed optimization solver is actually emulating all 50 chargers in a single CPU. (In practice, this computation load is distributed to all 50 chargers.) To save time, the outcome of the above command ``sim_out`` is already stored in ``Samples`` folder. (See four files with the extension ``.mat`` in the ``Samples`` folder.) You can retrieve the data by the above ``load`` command. Now, one can inspect the data in ``sim_out`` by a visualizer, which can be employed by: ```matlab % Step 4. Visualize the results analyze ``` and use the Load Data button in the App.