clear all
close all
clc
set(0,'defaultTextInterpreter','latex');


%% FILE DESCRIPTION

% This file is used to generate a specified number of dOCs starting from an
% sOC. 

% REFERENCES

% [1] L Romano, P Johannesson, F Bruzelius, and B Jacobson. " An enhanced
% stochastic operating cycle description including weather and traffic
% models". Transportation research part D: transport and environment 97,
% (2021).
% Available from: https://doi.org/10.1016/j.trd.2021.102878.

% [2] L Romano, P Johannesson, E Nordström, F Bruzelius, R Andersson, and B
% Jacobson. "A classification method of road transport missions and
% applications using the operating cycle format". IEEE Access 10, (2022).
% Available from: https://doi.org/10.1109/ACCESS.2022.3188872.

% [3] L Romano, M Godio, P Johannesson, F Bruzelius, T Ghandriz, and B
% Jacobson. "Development of an operating cycle for long-haul heavy-duty
% trucks: theory, analysis and applications". Submitted for publication.

% Please, cite the above references when using this script for purposes of
% academic or industrial research


%% INITIALISATION

% Add paths to needed packages (wafo, toporoll, etc.)
addpath(genpath(fullfile(['C:\Users\luigir\Desktop\backup\scripts\toolbox\stochastic generation toolbox\wafo25'])));  
addpath(genpath(fullfile(['C:\Users\luigir\Desktop\matlab\data analysis\Curve analysis\Toolboxes\toporoll']))); 
addpath(genpath(fullfile(['C:\Users\luigir\Desktop\wafo-wafo-v2017.1\wafo-wafo-v2017.1\wafo'])));
addpath(genpath(fullfile(['C:\Users\luigir\Desktop\backup\scripts\toolbox\stochastic generation toolbox\auxiliary functions'])));

% Save to designation directory
designationDir = 'C:\Users\luigir\Desktop\Mission distribution paper\sOC for Anandh\sOC for Anandh\generated_dOCs';

% Load an sOC
load('C:\Users\luigir\Desktop\sOC for Anandh\mean_sOC\sOCVästraGötaland.mat')


%% GENERATE dOCs

% Set sOC initialisation parameters
plotResult = false;
useExactLegalSpeed = false;
generateSpeedSeparately = true;
useDirectAssignment = true;
saveData = true;
saveElementarySequences = true;
isForFigureInSection4 = false;
doSaveRawData = false;
doUseCurveClustering = false;

curveLengthUpperBound = 8e3;
minimumCurveLength = 5;

cargoWeight = 25e3;
auxiliaryParameters = [];

% seasonIndex = 1; % 1 = winter, 2 = spring, 3 = summer, 4 = autumn
numberOfDays = 1;


% Generate road parameters for the sOC
StatisticalOC_Road = statOC.Road;

% Total number of dOCs to be generated
totalNumber=1;

for nFiles=1:totalNumber

    cargoProb = rand;
    if cargoProb < 0.19
        cargoWeight = 15792;
    elseif cargoProb < 0.57
        cargoWeight = 22616;
    elseif cargoProb < 0.77
        cargoWeight = 28911;
    else
        cargoWeight = 54215;
    end
    % Generate dOC
    [OperatingCycleOneWay, ocVersion, FigHandle, roadTypeOneWay, CurvinessOneWay, ...
        roadGradeOneWay] = generate_dOC_Road(StatisticalOC_Road, cargoWeight, ...
        plotResult, auxiliaryParameters, [], generateSpeedSeparately, useDirectAssignment,...
        curveLengthUpperBound, doSaveRawData, doUseCurveClustering, minimumCurveLength);
    OperatingCycle = ExtendOperatingCycle_v2(OperatingCycleOneWay);
     OperatingCycle = OperatingCycleOneWay;

%     Save dOC
    numberToAppend = num2str(nFiles);
    save([designationDir '\dOC_' numberToAppend], 'OperatingCycle')

end





