% This file uses the output of program lambda
% Open workspace of lambda before running this program


% Packet size in bits
packet_size = 1000;
mean_arrival_rate_pps = mean(pkts);
mean_arrival_rate_bitsps = (mean_arrival_rate_pps * packet_size);
j = 1;
mean_queue_delay_array = 0;
MMPP_mean_queue_delay_array = 0;
load_array = 0;
load_array = 0.1:0.03:0.9;
for loadj = 0.1:0.03:0.9
    pload = loadj;
    mean_service_rate_bps = mean_arrival_rate_bitsps / pload;
    mean_queue_size = 0;
    MMPP_mean_queue_size = 0;
    queue_size = 0;
    MMPP_queue_size = 0;
    for i = 1:datasize
        queue_size = queue_size + ((pkts(i) * packet_size) -  mean_service_rate_bps);
        if (queue_size < 0)
            queue_size = 0;
        end
        mean_queue_size = (((mean_queue_size * (i-1)) + queue_size)/i);
        MMPP_queue_size = MMPP_queue_size + ((MMPP_pkts(i) * packet_size) -  mean_service_rate_bps);
        if (MMPP_queue_size < 0)
            MMPP_queue_size = 0;
        end
        MMPP_mean_queue_size = (((MMPP_mean_queue_size * (i-1)) + MMPP_queue_size)/i);
    end
    
    mean_queue_delay_array (j) = (mean_queue_size / mean_service_rate_bps);
    MMPP_mean_queue_delay_array (j) = (MMPP_mean_queue_size / mean_service_rate_bps);
    j = j + 1;
end

mean_delay_combiner_array = 0;
mean_delay_combiner_array = [mean_queue_delay_array' MMPP_mean_queue_delay_array'];
figure (1);
plot (load_array, mean_delay_combiner_array, '-*');
grid on;
hold on;



% plot (load_array, MMPP_mean_queue_delay_array, '-o');
% legend('Data Trace','New algorithm','Algorithm 1');