function Main(q,nd,j1,j2,b1,b2,qcap,VC);

global Demands;
global j01 j02 betta1 betta2 Num devicenum quant capacity
global NextOutTime NextInTime Devices finishednum inputnum refusednum Queue
global curtime time queuetime worktime TimeCount muA muS
global queueamount workamount sysamount
global sysusage avgwaittime avglivetime avgqueueamount avgsysamount
global pusnbutton2

Init(q,nd,j1,j2,b1,b2,qcap,VC);

Generate;

while finishednum<Num
    %pause(0.01);
    if min(NextOutTime)<NextInTime
        DemandOut;
    else 
        DemandIn;
    end;
end;

Analyzer;

disp(refusednum);