%decin
clear all;
close all;
disp('Program vis_decin.m running');
disp('Initializing... (It might take a while)');
Vissim = actxserver('Vissim.Vissim.700'); % Start Vissim
Vissim.LoadNet
sim=Vissim.simulation;
vnet=Vissim.Net;
%Declaration:
scenario=zeros(3,2);                                       
step_time = 10;
max_cores = 4;
window = 5;
maxgap = getappdata(0,'ThresHold');
increase = (getappdata(0,'Increase')/100)+1;
period_time = getappdata(0,'PeriodTime');
random_seed = getappdata(0,'RandomSeed');
startcol = ceil(getappdata(0,'VehinStart')/5);
seed_change = getappdata(0,'RandomChange');
qm = getappdata(0,'Quickmode');
if getappdata(0,'scenario1')==1
    scenario(1,1) = 1;
    if getappdata(0,'Run2nd')==1
        scenario(1,2) = 1;
    end
end
if getappdata(0,'scenario2')==1
    scenario(2,1) = 1;
    if getappdata(0,'Run2nd')==1
        scenario(2,2) = 1;
    end
end
if getappdata(0,'scenario3')==1
    scenario(3,1) = 1;
    if getappdata(0,'Run2nd')==1
        scenario(3,2) = 1;
    end
end
rmappdata(0,'ThresHold')
rmappdata(0,'Increase')
rmappdata(0,'PeriodTime')
rmappdata(0,'RandomSeed')
rmappdata(0,'VehinStart')
rmappdata(0,'RandomChange')
rmappdata(0,'scenario1')
rmappdata(0,'scenario2')
rmappdata(0,'scenario3')
rmappdata(0,'Quickmode')
%Sim parameters assignment
sim.set('AttValue', 'SimPeriod', period_time);
sim.set('AttValue', 'SimRes', step_time);
sim.set('AttValue', 'NumCores', max_cores);
set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
set(Vissim.Graphics.CurrentNetworkWindow, 'AttValue', 'QuickMode', qm);
%Defining signal controllers & detectors
SCs = vnet.SignalControllers.GetAll; 
SG(1,1)=SCs{1}.SGs.ItemByKey(1);
SG(1,2)=SCs{1}.SGs.ItemByKey(2);
SG(2,1)=SCs{2}.SGs.ItemByKey(1);
SG(2,2)=SCs{2}.SGs.ItemByKey(2);
dets = SCs{1}.Detectors.GetAll;
det1 = dets{1};
%Defining composition
Composs= vnet.VehicleCompositions.GetAll;
Rel_Flows=Composs{2}.VehCompRelFlows.GetAll;
set(Rel_Flows{1}, 'AttValue', 'VehType',        100);
set(Rel_Flows{1}, 'AttValue', 'DesSpeedDistr',   50);
Rel_Flows=Composs{3}.VehCompRelFlows.GetAll;
set(Rel_Flows{1}, 'AttValue', 'VehType',        200);
set(Rel_Flows{1}, 'AttValue', 'DesSpeedDistr',   50);
Rel_Flows=Composs{4}.VehCompRelFlows.GetAll;
set(Rel_Flows{1}, 'AttValue', 'VehType',        300);
set(Rel_Flows{1}, 'AttValue', 'DesSpeedDistr',   50);
%Defining routing VehClasses
routingsource=vnet.VehicleRoutingDecisionsStatic.GetAll;
routingsource{1}.set('AttValue', 'AllVehTypes', 'false');
routingsource{1}.set('AttValue', 'VehClasses', 10);
routingsource{2}.set('AttValue', 'AllVehTypes', 'false');
routingsource{2}.set('AttValue', 'VehClasses', 20);
routingsource{3}.set('AttValue', 'AllVehTypes', 'false');
routingsource{3}.set('AttValue', 'VehClasses', 30);
routingsource{4}.set('AttValue', 'AllVehTypes', 'false');
routingsource{4}.set('AttValue', 'VehClasses', 10);
routingsource{5}.set('AttValue', 'AllVehTypes', 'false');
routingsource{5}.set('AttValue', 'VehClasses', 20);
routingsource{6}.set('AttValue', 'AllVehTypes', 'false');
routingsource{6}.set('AttValue', 'VehClasses', 30);
routingsource{7}.set('AttValue', 'AllVehTypes', 'false');
routingsource{7}.set('AttValue', 'VehClasses', 10);
routingsource{8}.set('AttValue', 'AllVehTypes', 'false');
routingsource{8}.set('AttValue', 'VehClasses', 20);
routingsource{9}.set('AttValue', 'AllVehTypes', 'false');
routingsource{9}.set('AttValue', 'VehClasses', 30);
routingsource{10}.set('AttValue', 'AllVehTypes', 'false');
routingsource{10}.set('AttValue', 'VehClasses', 10);
routingsource{11}.set('AttValue', 'AllVehTypes', 'false');
routingsource{11}.set('AttValue', 'VehClasses', 30);
routingsource{12}.set('AttValue', 'AllVehTypes', 'false');
routingsource{12}.set('AttValue', 'VehClasses', 10);
routingsource{13}.set('AttValue', 'AllVehTypes', 'false');
routingsource{13}.set('AttValue', 'VehClasses', 10);
%Defining VehCompositions on Inputs
vehins=vnet.VehicleInputs.GetAll;
vehins{1}.set('AttValue', 'VehComp(1)', 2);
vehins{2}.set('AttValue', 'VehComp(1)', 3);
vehins{3}.set('AttValue', 'VehComp(1)', 4);
vehins{4}.set('AttValue', 'VehComp(1)', 2);
vehins{5}.set('AttValue', 'VehComp(1)', 3);
vehins{6}.set('AttValue', 'VehComp(1)', 4);
vehins{7}.set('AttValue', 'VehComp(1)', 2);
vehins{8}.set('AttValue', 'VehComp(1)', 3);
vehins{9}.set('AttValue', 'VehComp(1)', 4);
vehins{10}.set('AttValue', 'VehComp(1)', 2);
vehins{11}.set('AttValue', 'VehComp(1)', 4);
vehins{12}.set('AttValue', 'VehComp(1)', 2);
vehins{13}.set('AttValue', 'VehComp(1)', 2);
%other simulation parameters
verify = [1 5*60];
offset = 22;
EOS=sum(scenario(:,1))+sum(scenario(:,2));
period_meas = 30;
%zero matrix for evaluation
x=period_meas:period_meas:period_time;
if rem(period_time, period_meas) ~= 0
   x(length(x)+1)=period_time;
end
DelayA=zeros(3,length(x));
DelayB=zeros(3,length(x));
TTA=zeros(3,length(x));
TTB=zeros(3,length(x));
QA=zeros(3,length(x));
QB=zeros(3,length(x));
DelayA2=zeros(3,length(x));
DelayB2=zeros(3,length(x));
TTA2=zeros(3,length(x));
TTB2=zeros(3,length(x));
QA2=zeros(3,length(x));
QB2=zeros(3,length(x));
maxQA=zeros(3,1);
maxQB=zeros(3,1);
avgQA=zeros(3,1);
avgQB=zeros(3,1);
maxDelayA=zeros(3,1);
maxDelayB=zeros(3,1);
avgDelayA=zeros(3,1);
avgDelayB=zeros(3,1);
maxTTA=zeros(3,1);
maxTTB=zeros(3,1);
avgTTA=zeros(3,1);
avgTTB=zeros(3,1);
avgDelaypA=zeros(3,1);
avgDelaypB=zeros(3,1);
avgDelaytA=zeros(3,1);
avgDelaytB=zeros(3,1);
avgDelaybA=zeros(3,1);
avgDelaybB=zeros(3,1);
avgTTpA=zeros(3,1);
avgTTpB=zeros(3,1);
avgTTtA=zeros(3,1);
avgTTtB=zeros(3,1);
avgTTbA=zeros(3,1);
avgTTbB=zeros(3,1);
maxQA2=zeros(3,1);
maxQB2=zeros(3,1);
avgQA2=zeros(3,1);
avgQB2=zeros(3,1);
maxDelayA2=zeros(3,1);
maxDelayB2=zeros(3,1);
avgDelayA2=zeros(3,1);
avgDelayB2=zeros(3,1);
maxTTA2=zeros(3,1);
maxTTB2=zeros(3,1);
avgTTA2=zeros(3,1);
avgTTB2=zeros(3,1);
avgDelaypA2=zeros(3,1);
avgDelaypB2=zeros(3,1);
avgDelaytA2=zeros(3,1);
avgDelaytB2=zeros(3,1);
avgDelaybA2=zeros(3,1);
avgDelaybB2=zeros(3,1);
avgTTpA2=zeros(3,1);
avgTTpB2=zeros(3,1);
avgTTtA2=zeros(3,1);
avgTTtB2=zeros(3,1);
avgTTbA2=zeros(3,1);
avgTTbB2=zeros(3,1);
%simulation
for j=1:EOS
if scenario(1,1)==1
    if (seed_change == 1) || (seed_change == 2)
        format longG
        random_seed = round(2147483646*rand)+1;
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 60;
    green(1) = 35;
    green(2) = green(1);
    maxgreen=0;
    load vehinsmatrix.txt;
    scenario(1,1)=2;
    disp('Scenario 1,1 running');
elseif scenario(1,2)==1
    if (seed_change == 1)
        format longG
        random_seed = round(2147483646*rand)+1; 
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 60;
    green(1) = 35;
    green(2) = green(1);
    maxgreen=0;
    load vehinsmatrix.txt;
    vehinsmatrix=vehinsmatrix*increase;
    scenario(1,2)=2;
    disp('Scenario 1,2 running');
elseif scenario(2,1)==1
    if (seed_change == 1) || (seed_change == 2)
        format longG
        random_seed = round(2147483646*rand)+1;
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 70;
    green(1) = 45;
    green(2) = green(1);
    maxgreen=0;
    load vehinsmatrix.txt;
    scenario(2,1)=2;
    disp('Scenario 2,1 running');
elseif scenario(2,2)==1
    if (seed_change == 1)
        format longG
        random_seed = round(2147483646*rand)+1; 
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 70;
    green(1) = 45;
    green(2) = green(1);
    maxgreen=0;
    load vehinsmatrix.txt;
    vehinsmatrix=vehinsmatrix*increase;    
    scenario(2,2)=2;
    disp('Scenario 2,2 running');
elseif scenario(3,1)==1
    if (seed_change == 1) || (seed_change == 2)
        format longG
        random_seed = round(2147483646*rand)+1; %+1 to avoid zero, max value is lower by 1
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 60;
    green(1) = 35;
    green(2) = green(1);
    maxgreen=45;
    load vehinsmatrix.txt;
    scenario(3,1)=2;
    disp('Scenario 3,1 running');
elseif scenario(3,2)==1
    if (seed_change == 1)
        format longG
        random_seed = round(2147483646*rand)+1; 
        set(Vissim.Simulation, 'AttValue', 'RandSeed', random_seed);
        format short
    end
    cycle = 60;
    green(1) = 35;
    green(2) = green(1);
    maxgreen=45;
    load vehinsmatrix.txt;
    vehinsmatrix=vehinsmatrix*increase;
    scenario(3,2)=2;
    disp('Scenario 3,2 running');
end
stage = [0 0];
change = [0 0;0 0];
terminate = [0 0];
start_time = [0 0];
sim_sec = 0;
claim1 = 1;
startshift = 0;
gap1 = 0;
c=1;
vehTTs1 = vnet.VehicleTravelTimeMeasurements.ItemByKey(1);
vehTTs2 = vnet.VehicleTravelTimeMeasurements.ItemByKey(2);
queue1 = vnet.QueueCounters.ItemByKey(1);
queue2 = vnet.QueueCounters.ItemByKey(2);
del1 = vnet.DelayMeasurement.ItemByKey(1);
del2 = vnet.DelayMeasurement.ItemByKey(2);
TT = [0;0];
Q = [0;0];
TTactual = [0;0];
TTsum = [0;0];
Qlenactual = [0;0];
Qsum = [0;0];
maxQ = [0;0];
delactual = [0;0];
DLactual = [0;0];
DLsum = [0;0];
DL = [0;0];
%Loading VehInputs
row2 = 1;
column = startcol;
for var1 = 1:length(vehins)
    vehins{var1}.set('AttValue', 'Volume(1)', vehinsmatrix(row2,column));
    if row2 < size(vehinsmatrix,1)
    row2=row2+1;
    end
end
%Loading routing data
row = 1;
load routmatrix.txt
routing=vnet.VehicleRoutingDecisionsStatic.GetAll;
for var1 = 1:length(routing)
routingx=routing{var1}.VehRoutSta.GetAll;
    for var2 = 1:length(routingx) 
    routingx{var2}.set('AttValue', 'RelFlow(1)', routmatrix(row,column));
        if row < size(routmatrix,1)
        row=row+1;
        end
    end
end
for i=0:(period_time*step_time)
    sim.RunSingleStep;
    if (maxgreen ~= 0) && (stage(1) == 1) && (start_time(1) >= (green(1)-3)) && (start_time(1) < maxgreen)
        if claim1 == 1
            gap1=det1.get('AttValue', 'GapTm');
            if gap1 > maxgap
                claim1 = 0;
            end
        end
    end   
    if rem(i/step_time, verify(1))==0
        if stage(1) == 0
           if (start_time(1) ~= 0) && (start_time(1) == terminate(1)) 
               stage(1) = 21;
           end
           if start_time(1) == 0
               SG(1,1).set('AttValue', 'State', 1);
               SG(1,2).set('AttValue', 'State', 3);
               SG(2,1).set('AttValue', 'State', 1);
               SG(2,2).set('AttValue', 'State', 3);
               terminate(1) = 3;
           end
           start_time(1) = start_time(1) + 1;
           if stage(1) == 21
               start_time(1) = 0;
               terminate(1) = 0;
           end  
        end
        if stage(1) == 21
           if (start_time(1) ~= 0) && (start_time(1) == change(1,1)) 
               SG(1,1).set('AttValue', 'State', 2);
           end
           if (start_time(1) ~= 0) && (start_time(1) == change(1,2)) 
               SG(1,2).set('AttValue', 'State', 1);
           end
           if (start_time(1) ~= 0) && (start_time(1) == terminate(1))
               stage(1) = 1;
           end
           if start_time(1) == 0
               SG(1,2).set('AttValue', 'State', 4);
               change(1,1) = 2;
               change(1,2) = 3;
           end
           start_time(1) = start_time(1) + 1;
           if stage(1) == 1
               start_time(1) = 0;
               terminate(1) = 0;
               change(1,:) = 0;
           end              
        end
        if stage(1) == 12
           if (start_time(1) ~= 0) && (start_time(1) == change(1,1)) 
               SG(1,1).set('AttValue', 'State', 1);
           end
           if (start_time(1) ~= 0) && (start_time(1) == change(1,2)) 
               SG(1,2).set('AttValue', 'State', 2);
           end
           if (start_time(1) ~= 0) && (start_time(1) == terminate(1))
               stage(1) = 2;
           end
           if start_time(1) == 0
               SG(1,1).set('AttValue', 'State', 4);
               terminate(1) = 6;
               change(1,1) = 3;
               change(1,2) = 4;
           end
           start_time(1) = start_time(1) + 1;
           if stage(1) == 2
               start_time(1) = 0;
               terminate(1) = 0;
               change(1,:) = 0;
           end              
        end 
        if stage(1) == 1
           if (maxgreen ~= 0) && (start_time(1) >= (terminate(1)-1)) && (start_time(1) < (maxgreen-1))
                   if claim1 == 1
                       terminate(1)=terminate(1)+1;
                   end
           end
           if (start_time(1) ~= 0) && (start_time(1) == (terminate(1)-1))
               stage(1) = 12;
           end
           if start_time(1) == 0
               SG(1,1).set('AttValue', 'State', 3);
               terminate(1) = green(1);
           end         
           start_time(1) = start_time(1) + 1;
           if stage(1) == 12
               start_time(1) = 0;
               terminate(1) = 0;
               startshift = 1;
           end              
        end
        
        if stage(1) == 2
           if (start_time(1) ~= 0) && (start_time(1) == (terminate(1)-1))
               stage(1) = 21;
           end
           if start_time(1) == 0
               SG(1,2).set('AttValue', 'State', 3);
               terminate(1) = cycle - (4 + 6 + green(1));
           end
           start_time(1) = start_time(1) + 1;
           if stage(1) == 21
               start_time(1) = 0;
               terminate(1) = 0;
           end
        end    
 %stages(2)       
        if stage(2) == 0
           if (start_time(2) ~= 0) && (start_time(2) == terminate(2)) 
               stage(2) = 21;
           end
           if start_time(2) == 0
               terminate(2) = (offset - 4);              
           end
           start_time(2) = start_time(2) + 1;
           if stage(2) == 21
               start_time(2) = 0;
               terminate(2) = 0;
           end
        end
        if stage(2) == 21
           if (start_time(2) ~= 0) && (start_time(2) == change(2,1)) 
               SG(2,1).set('AttValue', 'State', 2);
           end
           if (start_time(2) ~= 0) && (start_time(2) == change(2,2)) 
               SG(2,2).set('AttValue', 'State', 1);
           end
           if (start_time(2) ~= 0) && (start_time(2) == terminate(2))
               stage(2) = 1;
           end
           if start_time(2) == 0
               SG(2,2).set('AttValue', 'State', 4);
               terminate(2) = 8;
               change(2,1) = 6;
               change(2,2) = 3;
           end
           start_time(2) = start_time(2) + 1;
           if stage(2) == 1
               start_time(2) = 0;
               terminate(2) = 0;
               change(2,:) = 0;
           end              
        end
        if stage(2) == 12
           if (start_time(2) ~= 0) && (start_time(2) == change(2,1)) 
               SG(2,1).set('AttValue', 'State', 1);
           end
           if (start_time(2) ~= 0) && (start_time(2) == change(2,2)) 
               SG(2,2).set('AttValue', 'State', 2);
           end
           if (start_time(2) ~= 0) && (start_time(2) == terminate(2))
               stage(2) = 2;
           end
           if start_time(2) == 0
               SG(2,1).set('AttValue', 'State', 4);
               terminate(2) = 8;
               change(2,1) = 3;
               change(2,2) = 6;
           end
           start_time(2) = start_time(2) + 1;
           if stage(2) == 2
               start_time(2) = 0;
               terminate(2) = 0;
               change(2,:) = 0;
           end     
        end
        if stage(2) == 1
           if startshift == 1
               terminate(2) = start_time(2) + offset;
               startshift = 0;
           end
           if (start_time(2) ~= 0) && (start_time(2) == (terminate(2)-1))
               stage(2) = 12;
           end
           if start_time(2) == 0
               SG(2,1).set('AttValue', 'State', 3);
           end
           start_time(2) = start_time(2) + 1;
           if stage(2) == 12
               start_time(2) = 0;
               terminate(2) = 0;
               if (maxgreen ~= 0)
                   claim1 = 1;
               end
           end              
        end  
        if stage(2) == 2
           if (start_time(2) ~= 0) && (start_time(2) == (terminate(2)-1))
               stage(2) = 21;
           end
           if start_time(2) == 0
               SG(2,2).set('AttValue', 'State', 3);
               terminate(2) = cycle - green (2) - 8 - 8;
           end
           start_time(2) = start_time(2) + 1;
           if stage(2) == 21
               start_time(2) = 0;
               terminate(2) = 0;
           end              
        end
        sim_sec = sim_sec + 1;
    end   
    if (rem(i/step_time, verify(2))==0) && i~=0
        column = column + 1;
        row = 1;
        row2 = 1;
        if column <= length(vehinsmatrix)
        for var1 = 1:length(vehins)
            vehins{var1}.set('AttValue', 'Volume(1)', vehinsmatrix(row2,column));
            row2=row2+1;
        end
        end
        if column <= length(routmatrix)
        for var2 = 1:length(routingx) 
            routingx{var2}.set('AttValue', 'RelFlow(1)', routmatrix(row,column));
            row=row+1;
        end
        end
    end 
    %data collecting
    if (i~=0) && (rem((i)/step_time, period_meas)==0) && (i<((period_time*step_time)-1))
    TTactual(1,1) = get(vehTTs1,'AttValue', 'TravTm(Current,Total,All)');
    TTactual(2,1) = get(vehTTs2,'AttValue', 'TravTm(Current,Total,All)');
    Qlenactual(1,1) = get(queue1,'AttValue', 'QLen(Current,Total)');
    Qlenactual(2,1) = get(queue2,'AttValue', 'QLen(Current,Total)');
    DLactual(1,1) = get(del1, 'AttValue', 'VehDelay(Current,Total,All)');
    DLactual(2,1) = get(del2, 'AttValue', 'VehDelay(Current,Total,All)');
     if c ~= 1
        if isnan(TTactual(1,1))
            TT(1,c)=0;
        else
            TTsum(1,1) = TTsum(1,1) + TT(1,c-1);
            TT(1,c) = (TTactual(1,1) - TTsum(1,1));
        end
        if isnan(DLactual(1,1))
            DL(1,c)=0;
        else
            DLsum(1,1) = DLsum(1,1) + DL(1,c-1);
            DL(1,c) = (DLactual(1,1) - DLsum(1,1));
        end
        if isnan(Qlenactual(1,1))
            Q(1,c)=0;
        else
            Qsum(1,1) = Qsum(1,1) + Q(1,c-1);
            Q(1,c) = (Qlenactual(1,1) - Qsum(1,1));
        end
        %second direction
        if isnan(TTactual(2,1))
            TT(2,c)=0;
        else
            TTsum(2,1) = TTsum(2,1) + TT(2,c-1);
            TT(2,c) = (TTactual(2,1) - TTsum(2,1));
        end   
        if isnan(DLactual(2,1))
            DL(2,c)=0;
        else
            DLsum(2,1) = DLsum(2,1) + DL(2,c-1);
            DL(2,c) = (DLactual(2,1) - DLsum(2,1));
        end 
        if isnan(Qlenactual(2,1))
            Q(2,c)=0;
        else
            Qsum(2,1) = Qsum(2,1) + Q(2,c-1);
            Q(2,c) = (Qlenactual(2,1) - Qsum(2,1));
        end
        c=c+1;
     else
        if isnan(TTactual(1,1))
            TT(1,c)=0;
        else
            TT(1,c) = TTactual(1,1);
        end
        if isnan(DLactual(1,1))
            DL(1,c)=0;
        else
            DL(1,c) = DLactual(1,1);
        end
        if isnan(Qlenactual(1,1))
            Q(1,c)=0;
        else
            Q(1,c) = Qlenactual(1,1);
        end
        %second direction
        if isnan(TTactual(2,1))
            TT(2,c)=0;
        else
            TT(2,c) = TTactual(2,1);
        end
        if isnan(DLactual(2,1))
            DL(2,c)=0;
        else
            DL(2,c) = DLactual(2,1);
        end
        if isnan(Qlenactual(2,1))
            Q(2,c)=0;
        else
            Q(2,c) = Qlenactual(2,1);
        end        
        c=c+1;
     end
    end
if i==((period_time*step_time)-1)
    TTactual(1,1) = get(vehTTs1,'AttValue', 'TravTm(Current,Total,All)');
    TTactual(2,1) = get(vehTTs2,'AttValue', 'TravTm(Current,Total,All)');
    Qlenactual(1,1) = get(queue1,'AttValue', 'QLen(Current,Total)');
    Qlenactual(2,1) = get(queue2,'AttValue', 'QLen(Current,Total)');
    DLactual(1,1) = get(del1,'AttValue', 'VehDelay(Current,Total,All)');
    DLactual(2,1) = get(del2,'AttValue', 'VehDelay(Current,Total,All)');
        if isnan(TTactual(1,1))
            TT(1,c)=0;
        else
            TTsum(1,1) = TTsum(1,1) + TT(1,c-1);
            TT(1,c) = (TTactual(1,1) - TTsum(1,1));
        end
        if isnan(DLactual(1,1))
            DL(1,c)=0;
        else
            DLsum(1,1) = DLsum(1,1) + DL(1,c-1);
            DL(1,c) = (DLactual(1,1) - DLsum(1,1));
        end
        if isnan(Qlenactual(1,1))
            Q(1,c)=0;
        else
            Qsum(1,1) = Qsum(1,1) + Q(1,c-1);
            Q(1,c) = (Qlenactual(1,1) - Qsum(1,1));
        end
        %second direction
        if isnan(TTactual(2,1))
            TT(2,c)=0;
        else
            TTsum(2,1) = TTsum(2,1) + TT(2,c-1);
            TT(2,c) = (TTactual(2,1) - TTsum(2,1));
        end   
        if isnan(DLactual(2,1))
            DL(2,c)=0;
        else
            DLsum(2,1) = DLsum(2,1) + DL(2,c-1);
            DL(2,c) = (DLactual(2,1) - DLsum(2,1));
        end 
        if isnan(Qlenactual(2,1))
            Q(2,c)=0;
        else
            Qsum(2,1) = Qsum(2,1) + Q(2,c-1);
            Q(2,c) = (Qlenactual(2,1) - Qsum(2,1));
        end
        maxQ(1) = get(queue1,'AttValue', 'QLen(Current,Max)');
        maxQ(2) = get(queue2,'AttValue', 'QLen(Current,Max)');
        avgQ(1) = get(queue1,'AttValue', 'QLen(Current,Avg)');
        avgQ(2) = get(queue2,'AttValue', 'QLen(Current,Avg)');
        maxDelay(1) = get(del1,'AttValue', 'VehDelay(Current,Max,All)');
        maxDelay(2) = get(del2,'AttValue', 'VehDelay(Current,Max,All)');
        avgDelay(1) = get(del1,'AttValue', 'VehDelay(Current,Avg,All)');
        avgDelay(2) = get(del2,'AttValue', 'VehDelay(Current,Avg,All)');
        maxTT(1) = get(vehTTs1,'AttValue', 'TravTm(Current,Max,All)');
        maxTT(2) = get(vehTTs2,'AttValue', 'TravTm(Current,Max,All)');
        avgTT(1) = get(vehTTs1,'AttValue', 'TravTm(Current,Avg,All)');
        avgTT(2) = get(vehTTs2,'AttValue', 'TravTm(Current,Avg,All)');
        avgDelayp(1) = get(del1,'AttValue', 'VehDelay(Current,Avg,10)');
        avgDealyp(2) = get(del2,'AttValue', 'VehDelay(Current,Avg,10)');
        avgDelayt(1) = get(del1,'AttValue', 'VehDelay(Current,Avg,20)');
        avgDelayt(2) = get(del2,'AttValue', 'VehDelay(Current,Avg,20)');
        avgDelayb(1) = get(del1,'AttValue', 'VehDelay(Current,Avg,30)');
        avgDelayb(2) = get(del2,'AttValue', 'VehDelay(Current,Avg,30)');
        avgTTp(1) = get(vehTTs1,'AttValue', 'TravTm(Current,Avg,10)');
        avgTTp(2) = get(vehTTs2,'AttValue', 'TravTm(Current,Avg,10)');
        avgTTt(1) = get(vehTTs1,'AttValue', 'TravTm(Current,Avg,20)');
        avgTTt(2) = get(vehTTs2,'AttValue', 'TravTm(Current,Avg,20)');
        avgTTb(1) = get(vehTTs1,'AttValue', 'TravTm(Current,Avg,30)');
        avgTTb(2) = get(vehTTs2,'AttValue', 'TravTm(Current,Avg,30)');
end    
end
    sim.Stop;    
    if scenario(1,1)==2
        DelayA(1,:)=movmean(DL(1,:),window);
        DelayB(1,:)=movmean(DL(2,:),window);        
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA(1,:)=movmean(prov,window);        
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end        
        TTB(1,:)=movmean(prov,window);        
        QA(1,:)=movmean(Q(1,:),window);
        QB(1,:)=movmean(Q(2,:),window);
        maxQA(1)=maxQ(1);
        maxQB(1)=maxQ(2);
        avgQA(1)=avgQ(1);
        avgQB(1)=avgQ(2);
        maxDelayA(1)=maxDelay(1);
        maxDelayB(1)=maxDelay(2);
        avgDelayA(1)=avgDelay(1);
        avgDelayB(1)=avgDelay(2);
        maxTTA(1)=maxTT(1);
        maxTTB(1)=maxTT(2);
        avgTTA(1)=avgTT(1);
        avgTTB(1)=avgTT(2);
        avgDelaypA(1)=avgDelayp(1);
        avgDelaypB(1)=avgDealyp(2);
        avgDelaytA(1)=avgDelayt(1);
        avgDelaytB(1)=avgDelayt(2);
        avgDelaybA(1)=avgDelayb(1);
        avgDelaybB(1)=avgDelayb(2);
        avgTTpA(1)=avgTTp(1);
        avgTTpB(1)=avgTTp(2);
        avgTTtA(1)=avgTTt(1);
        avgTTtB(1)=avgTTt(2);
        avgTTbA(1)=avgTTb(1);
        avgTTbB(1)=avgTTb(2);
    scenario(1,1)=3;
    elseif scenario(1,2)==2
        DelayA2(1,:)=movmean(DL(1,:),window);
        DelayB2(1,:)=movmean(DL(2,:),window);        
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA2(1,:)=movmean(prov,window);
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end        
        TTB2(1,:)=movmean(prov,window);
        QA2(1,:)=movmean(Q(1,:),window);
        QB2(1,:)=movmean(Q(2,:),window);
        maxQA2(1)=maxQ(1);
        maxQB2(1)=maxQ(2);
        avgQA2(1)=avgQ(1);
        avgQB2(1)=avgQ(2);
        maxDelayA2(1)=maxDelay(1);
        maxDelayB2(1)=maxDelay(2);
        avgDelayA2(1)=avgDelay(1);
        avgDelayB2(1)=avgDelay(2);
        maxTTA2(1)=maxTT(1);
        maxTTB2(1)=maxTT(2);
        avgTTA2(1)=avgTT(1);
        avgTTB2(1)=avgTT(2);
        avgDelaypA2(1)=avgDelayp(1);
        avgDelaypB2(1)=avgDealyp(2);
        avgDelaytA2(1)=avgDelayt(1);
        avgDelaytB2(1)=avgDelayt(2);
        avgDelaybA2(1)=avgDelayb(1);
        avgDelaybB2(1)=avgDelayb(2);
        avgTTpA2(1)=avgTTp(1);
        avgTTpB2(1)=avgTTp(2);
        avgTTtA2(1)=avgTTt(1);
        avgTTtB2(1)=avgTTt(2);
        avgTTbA2(1)=avgTTb(1);
        avgTTbB2(1)=avgTTb(2);
    scenario(1,2)=3;
    elseif scenario(2,1)==2
        DelayA(2,:)=movmean(DL(1,:),window);
        DelayB(2,:)=movmean(DL(2,:),window);
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA(2,:)=movmean(prov,window);
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTB(2,:)=movmean(prov,window);
        QA(2,:)=movmean(Q(1,:),window);
        QB(2,:)=movmean(Q(2,:),window);
        maxQA(2)=maxQ(1);
        maxQB(2)=maxQ(2);
        avgQA(2)=avgQ(1);
        avgQB(2)=avgQ(2);
        maxDelayA(2)=maxDelay(1);
        maxDelayB(2)=maxDelay(2);
        avgDelayA(2)=avgDelay(1);
        avgDelayB(2)=avgDelay(2);
        maxTTA(2)=maxTT(1);
        maxTTB(2)=maxTT(2);
        avgTTA(2)=avgTT(1);
        avgTTB(2)=avgTT(2);
        avgDelaypA(2)=avgDelayp(1);
        avgDelaypB(2)=avgDealyp(2);
        avgDelaytA(2)=avgDelayt(1);
        avgDelaytB(2)=avgDelayt(2);
        avgDelaybA(2)=avgDelayb(1);
        avgDelaybB(2)=avgDelayb(2);
        avgTTpA(2)=avgTTp(1);
        avgTTpB(2)=avgTTp(2);
        avgTTtA(2)=avgTTt(1);
        avgTTtB(2)=avgTTt(2);
        avgTTbA(2)=avgTTb(1);
        avgTTbB(2)=avgTTb(2);
    scenario(2,1)=3;
    elseif scenario(2,2)==2
        DelayA2(2,:)=movmean(DL(1,:),window);
        DelayB2(2,:)=movmean(DL(2,:),window);
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA2(2,:)=movmean(prov,window);
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTB2(2,:)=movmean(prov,window);
        QA2(2,:)=movmean(Q(1,:),window);
        QB2(2,:)=movmean(Q(2,:),window);
        maxQA2(2)=maxQ(1);
        maxQB2(2)=maxQ(2);
        avgQA2(2)=avgQ(1);
        avgQB2(2)=avgQ(2);
        maxDelayA2(2)=maxDelay(1);
        maxDelayB2(2)=maxDelay(2);
        avgDelayA2(2)=avgDelay(1);
        avgDelayB2(2)=avgDelay(2);
        maxTTA2(2)=maxTT(1);
        maxTTB2(2)=maxTT(2);
        avgTTA2(2)=avgTT(1);
        avgTTB2(2)=avgTT(2);
        avgDelaypA2(2)=avgDelayp(1);
        avgDelaypB2(2)=avgDealyp(2);
        avgDelaytA2(2)=avgDelayt(1);
        avgDelaytB2(2)=avgDelayt(2);
        avgDelaybA2(2)=avgDelayb(1);
        avgDelaybB2(2)=avgDelayb(2);
        avgTTpA2(2)=avgTTp(1);
        avgTTpB2(2)=avgTTp(2);
        avgTTtA2(2)=avgTTt(1);
        avgTTtB2(2)=avgTTt(2);
        avgTTbA2(2)=avgTTb(1);
        avgTTbB2(2)=avgTTb(2);        
    scenario(2,2)=3;
    elseif scenario(3,1)==2
        DelayA(3,:)=movmean(DL(1,:),window);
        DelayB(3,:)=movmean(DL(2,:),window);
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA(3,:)=movmean(prov,window);
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTB(3,:)=movmean(prov,window);
        QA(3,:)=movmean(Q(1,:),window);
        QB(3,:)=movmean(Q(2,:),window);
        maxQA(3)=maxQ(1);
        maxQB(3)=maxQ(2);
        avgQA(3)=avgQ(1);
        avgQB(3)=avgQ(2);
        maxDelayA(3)=maxDelay(1);
        maxDelayB(3)=maxDelay(2);
        avgDelayA(3)=avgDelay(1);
        avgDelayB(3)=avgDelay(2);
        maxTTA(3)=maxTT(1);
        maxTTB(3)=maxTT(2);
        avgTTA(3)=avgTT(1);
        avgTTB(3)=avgTT(2);
        avgDelaypA(3)=avgDelayp(1);
        avgDelaypB(3)=avgDealyp(2);
        avgDelaytA(3)=avgDelayt(1);
        avgDelaytB(3)=avgDelayt(2);
        avgDelaybA(3)=avgDelayb(1);
        avgDelaybB(3)=avgDelayb(2);
        avgTTpA(3)=avgTTp(1);
        avgTTpB(3)=avgTTp(2);
        avgTTtA(3)=avgTTt(1);
        avgTTtB(3)=avgTTt(2);
        avgTTbA(3)=avgTTb(1);
        avgTTbB(3)=avgTTb(2);
    scenario(3,1)=3;
    elseif scenario(3,2)==2
        DelayA2(3,:)=movmean(DL(1,:),window);
        DelayB2(3,:)=movmean(DL(2,:),window);
        prov = TT(1,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTA2(3,:)=movmean(prov,window);
        prov = TT(2,:);
        pr = size(find(prov~=0));
        if pr(2)>=2
           prov = interp1(find(prov~=0),prov(prov~=0),1:length(prov),'nearest','extrap');
        end
        TTB2(3,:)=movmean(prov,window);
        QA2(3,:)=movmean(Q(1,:),window);
        QB2(3,:)=movmean(Q(2,:),window);
        maxQA2(3)=maxQ(1);
        maxQB2(3)=maxQ(2);
        avgQA2(3)=avgQ(1);
        avgQB2(3)=avgQ(2);
        maxDelayA2(3)=maxDelay(1);
        maxDelayB2(3)=maxDelay(2);
        avgDelayA2(3)=avgDelay(1);
        avgDelayB2(3)=avgDelay(2);
        maxTTA2(3)=maxTT(1);
        maxTTB2(3)=maxTT(2);
        avgTTA2(3)=avgTT(1);
        avgTTB2(3)=avgTT(2);
        avgDelaypA2(3)=avgDelayp(1);
        avgDelaypB2(3)=avgDealyp(2);
        avgDelaytA2(3)=avgDelayt(1);
        avgDelaytB2(3)=avgDelayt(2);
        avgDelaybA2(3)=avgDelayb(1);
        avgDelaybB2(3)=avgDelayb(2);
        avgTTpA2(3)=avgTTp(1);
        avgTTpB2(3)=avgTTp(2);
        avgTTtA2(3)=avgTTt(1);
        avgTTtB2(3)=avgTTt(2);
        avgTTbA2(3)=avgTTb(1);
        avgTTbB2(3)=avgTTb(2);
    scenario(3,2)=3;
    end
end
%Delays
figure('Name','Delays');
subplot(2,2,1); plot(x,DelayA(1,:),'r') 
hold on
subplot(2,2,1); plot(x,DelayA(2,:),'g')
hold on
subplot(2,2,1); plot(x,DelayA(3,:),'b')
title('Delay Ustecka-Podmokelska'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(DelayA))>0
    ylim([0 max(max(DelayA))])
end
subplot(2,2,2); plot(x,DelayA2(1,:),'r') 
hold on
subplot(2,2,2); plot(x,DelayA2(2,:),'g')
hold on
subplot(2,2,2); plot(x,DelayA2(3,:),'b')
title('Delay Ustecka-Podmokelska with traffic increased'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(DelayA2))>0
    ylim([0 max(max(DelayA2))])
end
subplot(2,2,3); plot(x,DelayB(1,:),'r') 
hold on
subplot(2,2,3); plot(x,DelayB(2,:),'g')
hold on
subplot(2,2,3); plot(x,DelayB(3,:),'b')
title('Delay Podmokelska-Ustecka'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(DelayB))>0
    ylim([0 max(max(DelayB))])
end
subplot(2,2,4); plot(x,DelayB2(1,:),'r') 
hold on
subplot(2,2,4); plot(x,DelayB2(2,:),'g')
hold on
subplot(2,2,4); plot(x,DelayB2(3,:),'b')
title('Delay Podmokelska-Ustecka with traffic increased'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(DelayB2))>0
    ylim([0 max(max(DelayB2))])
end
legend('Cycle = 60s', 'Cycle = 70s', '60-70 with dynamic', 'Location','Best')
%Queues
figure('Name','Queues')
subplot(2,2,1); plot(x,QA(1,:),'r') 
hold on
subplot(2,2,1); plot(x,QA(2,:),'g')
hold on
subplot(2,2,1); plot(x,QA(3,:),'b')
title('Queue Ustecka-Podmokelska'), xlabel('sample period'), ylabel('meters'), xlim([period_meas period_time])
if sum(sum(QA))>0
    ylim([0 max(max(QA))])
end
subplot(2,2,2); plot(x,QA2(1,:),'r') 
hold on
subplot(2,2,2); plot(x,QA2(2,:),'g')
hold on
subplot(2,2,2); plot(x,QA2(3,:),'b')
title('Queue Ustecka-Podmokelska with traffic increased'), xlabel('sample period'), ylabel('meters'), xlim([period_meas period_time])
if sum(sum(QA2))>0
    ylim([0 max(max(QA2))])
end
subplot(2,2,3); plot(x,QB(1,:),'r') 
hold on
subplot(2,2,3); plot(x,QB(2,:),'g')
hold on
subplot(2,2,3); plot(x,QB(3,:),'b')
title('Queue Podmokelska-Ustecka'), xlabel('sample period'), ylabel('meters'), xlim([period_meas period_time])
if sum(sum(QB))>0
    ylim([0 max(max(QB))])
end
subplot(2,2,4); plot(x,QB2(1,:),'r') 
hold on
subplot(2,2,4); plot(x,QB2(2,:),'g')
hold on
subplot(2,2,4); plot(x,QB2(3,:),'b')
title('Queue Podmokelska-Ustecka with traffic increased'), xlabel('sample period'), ylabel('meters'), xlim([period_meas period_time])
if sum(sum(QB2))>0
    ylim([0 max(max(QB2))])
end
legend('Cycle = 60s', 'Cycle = 70s', '60-70 with dynamic', 'Location','Best')
figure('Name','Travel times');
subplot(2,2,1); plot(x,TTA(1,:),'r') 
hold on
subplot(2,2,1); plot(x,TTA(2,:),'g')
hold on
subplot(2,2,1); plot(x,TTA(3,:),'b')
title('Travel time Ustecka-Podmokelska'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(TTA))>0
    ylim([0 max(max(TTA))])
end
subplot(2,2,2); plot(x,TTA2(1,:),'r') 
hold on
subplot(2,2,2); plot(x,TTA2(2,:),'g')
hold on
subplot(2,2,2); plot(x,TTA2(3,:),'b')
title('Travel time Ustecka-Podmokelska with traffic increased'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(TTA2))>0
    ylim([0 max(max(TTA2))])
end
subplot(2,2,3); plot(x,TTB(1,:),'r') 
hold on
subplot(2,2,3); plot(x,TTB(2,:),'g')
hold on
subplot(2,2,3); plot(x,TTB(3,:),'b')
title('Travel time Podmokelska-Ustecka'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(TTB))>0
    ylim([0 max(max(TTB))])
end
subplot(2,2,4); plot(x,TTB2(1,:),'r') 
hold on
subplot(2,2,4); plot(x,TTB2(2,:),'g')
hold on
subplot(2,2,4); plot(x,TTB2(3,:),'b')
title('Travel time Podmokelska-Ustecka with traffic increased'), xlabel('sample period'), ylabel('seconds'), xlim([period_meas period_time])
if sum(sum(TTB2))>0
    ylim([0 max(max(TTB2))])
end
legend('Cycle = 60s', 'Cycle = 70s', '60-70 with dynamic', 'Location','Best')
disp('All done! See results in figures and tables above:');
%Tables
TTust_podm = [avgTTpA(1),avgTTtA(1),avgTTbA(1),avgTTA(1),maxTTA(1);
              avgTTpA2(1),avgTTtA2(1),avgTTbA2(1),avgTTA2(1),maxTTA2(1);
              avgTTpA(2),avgTTtA(2),avgTTbA(2),avgTTA(2),maxTTA(2);
              avgTTpA2(2),avgTTtA2(2),avgTTbA2(2),avgTTA2(2),maxTTA2(2);
              avgTTpA(3),avgTTtA(3),avgTTbA(3),avgTTA(3),maxTTA(3);
              avgTTpA2(3),avgTTtA2(3),avgTTbA2(3),avgTTA2(3),maxTTA2(3);];         
TTpodm_ust = [avgTTpB(1),avgTTtB(1),avgTTbB(1),avgTTB(1),maxTTB(1);
              avgTTpB2(1),avgTTtB2(1),avgTTbB2(1),avgTTB2(1),maxTTB2(1);
              avgTTpB(2),avgTTtB(2),avgTTbB(2),avgTTB(2),maxTTB(2);
              avgTTpB2(2),avgTTtB2(2),avgTTbB2(2),avgTTB2(2),maxTTB2(2);
              avgTTpB(3),avgTTtB(3),avgTTbB(3),avgTTB(3),maxTTB(3);
              avgTTpB2(3),avgTTtB2(3),avgTTbB2(3),avgTTB2(3),maxTTB2(3);];          
Delust_podm = [avgDelaypA(1),avgDelaytA(1),avgDelaybA(1),avgDelayA(1),maxDelayA(1);
              avgDelaypA2(1),avgDelaytA2(1),avgDelaybA2(1),avgDelayA2(1),maxDelayA2(1);
              avgDelaypA(2),avgDelaytA(2),avgDelaybA(2),avgDelayA(2),maxDelayA(2);
              avgDelaypA2(2),avgDelaytA2(2),avgDelaybA2(2),avgDelayA2(2),maxDelayA2(2);
              avgDelaypA(3),avgDelaytA(3),avgDelaybA(3),avgDelayA(3),maxDelayA(3);
              avgDelaypA2(3),avgDelaytA2(3),avgDelaybA2(3),avgDelayA2(3),maxDelayA2(3);];          
Delpodm_ust = [avgDelaypB(1),avgDelaytB(1),avgDelaybB(1),avgDelayB(1),maxDelayB(1);
              avgDelayB2(1),avgDelaytB2(1),avgDelaybB2(1),avgDelayB2(1),maxDelayB2(1);
              avgDelaypB(2),avgDelaytB(2),avgDelaybB(2),avgDelayB(2),maxDelayB(2);
              avgDelaypB2(2),avgDelaytB2(2),avgDelaybB2(2),avgDelayB2(2),maxDelayB2(2);
              avgDelaypB(3),avgDelaytB(3),avgDelaybB(3),avgDelayB(3),maxDelayB(3);
              avgDelaypB2(3),avgDelaytB2(3),avgDelaybB2(3),avgDelayB2(3),maxDelayB2(3);];          
Qust_podm = [avgQA(1), maxQA(1);
             avgQA2(1), maxQA2(1);
             avgQA(2), maxQA(2);
             avgQA2(2), maxQA2(2);
             avgQA(3), maxQA(3);
             avgQA2(3), maxQA2(3);];         
Qpodm_ust = [avgQB(1), maxQB(1);
             avgQB2(1), maxQB2(1);
             avgQB(2), maxQB(2);
             avgQB2(2), maxQB2(2);
             avgQB(3), maxQB(3);
             avgQB2(3), maxQB2(3);];
Scen = {'60s', 'increase', '70s', 'increase', '60-70s', 'increase'};       
disp('Travel time Ustecka-Podmokelska [s]');
T1=table;
T1.Scenario = Scen';
T1.personal_veh = TTust_podm(:,1);
T1.trucks = TTust_podm(:,2);
T1.buses = TTust_podm(:,3);
T1.all = TTust_podm(:,4);
T1.max_all = TTust_podm(:,5)
disp('Travel time Podmokelska-Ustecka [s]:')
T2=table;
T2.Scenario = Scen';
T2.personal_veh = TTpodm_ust(:,1);
T2.trucks = TTpodm_ust(:,2);
T2.buses = TTpodm_ust(:,3);
T2.all = TTpodm_ust(:,4);
T2.max_all = TTpodm_ust(:,5)
disp('Delay Ustecka-Podmokelska [s]:')
T3=table;
T3.Scenario = Scen';
T3.personal_veh = Delust_podm(:,1);
T3.trucks = Delust_podm(:,2);
T3.buses = Delust_podm(:,3);
T3.all = Delust_podm(:,4);
T3.max_all = Delust_podm(:,5)
disp('Delay Podmokelska-Ustecka [s]:')
T4=table;
T4.Scenario = Scen';
T4.personal_veh = Delpodm_ust(:,1);
T4.trucks = Delpodm_ust(:,2);
T4.buses = Delpodm_ust(:,3);
T4.all = Delpodm_ust(:,4);
T4.max_all = Delpodm_ust(:,5)
disp('Queue Ustecka-Podmokelska [m]:')
T5=table;
T5.Scenario = Scen';
T5.all = Qust_podm(:,1);
T5.max_all = Qust_podm(:,2)
disp('Queue Podmokelska-Ustecka [m]:')
T6=table;
T6.Scenario = Scen';
T6.all = Qpodm_ust(:,1);
T6.max_all = Qpodm_ust(:,2)        
%Table printing for older versions of Matlab:
%printmat(TTust_podm, 'Travel time Ustecka-Podmokelska [s]','60s increase 70s increase 70s increase 60to70s increase','personal_veh trucks buses all max_all')
%printmat(TTpodm_ust, 'Travel time Podmokelska-Ustecka [s]','60s increase 70s increase 70s increase 60to70s increase','personal_veh trucks buses all max_all')
%printmat(Delust_podm, 'Delay Ustecka-Podmokelska [s]','60s increase 70s increase 70s increase 60to70s increase','personal_veh trucks buses all max_all')
%printmat(Delpodm_ust, 'Delay Podmokelska-Ustecka [s]','60s increase 70s increase 70s increase 60to70s increase','personal_veh trucks buses all max_all')
%printmat(Qust_podm, 'Queue Ustecka-Podmokelska [m]','60s increase 70s increase 70s increase 60to70s increase','all max_all')
%printmat(Qpodm_ust, 'Queue Podmokelska-Ustecka [m]','60s increase 70s increase 70s increase 60to70s increase','all max_all')


