⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 problem2_y.m

📁 平时练习时的一些仿真程序
💻 M
字号:
clc,clear
simday=30;             
wait_time=zeros(1,144);            %wt为每个油轮的等待时间
h=0.01;  					%时间步长0.01小时
simtime=0.01;               % 变量存储仿真时间
otc= zeros(1,144);          %事件油轮到达otc=1 表示油轮到达,otc=0 表示没有油轮到达,或者油轮卸货完毕
otchold= zeros(1,144);      %到达油轮的存储油量
dockship=0 ;                %dockship为表示码头忙闲的状态
tankoil=0;                  %tankoil为储油罐的储油量
unloadtemp=0 ;              %unloadtemp为表示卸货暂停的状态量
freetime=0;  %freetime变量表示码头空闲数,freetime=0表示工作,freetime=1表示空闲
night=0;     %night变量为是否为:0:0-6:0的标志
eatoil=0;    %eatoil变量为码头的进油量数 
outoil=0;    %outoil变量为码头的供油量数
ql=0;        %ql变量为队列长度
sum_of_tankoil=0;%仿真步长内油罐的储油量
unload_time= zeros(1,144);%

%两个月(60天)约144条油轮到达,首先产生服从均值为10的指数分布的油轮到达时间,结合油轮载油量的分布函数产生每个油轮 的载油量
x=rand(1,144);%产生144个均匀分布的随机数
y=log(x);
y=-10*y;%产生服从指数分布的时间间隔变量
cat(1)=0;   % %%%%cat(1)=5; 

for i=2:144
    for j=1:(i-1)  %%%%%%%%%
        cat(i)=cat(i-1)+y(i-1);%计算出144个油轮的到来时刻 ,存于eat数组中
    end
    hold(1)=50000;   %%%% hold(1)=60000;
    if x(i-1)<=(1/6)%利用随机数计算出每个油轮的载油量,存于hold数组中
        hold(i)=50000;
    elseif x(i-1)<=(1/6+1/3)
        hold(i)=60000;
    elseif x(i-1)<=(1/6+2/3)
        hold(i)=80000;
    else 
        hold(i)=100000;
    end
end

%以下以时间步长0.01小时进行仿真
for step=1:144000
    ql=0;
    simtime=simtime+h;
    nowtime=mod(simtime,24); % nowime变量存储仿真的每一天中的时间
   
    for i=1:144  %%%%%%%%%%%%判断是否有油轮到达,记录在otc数组中;并表示码头dockship置位
        cha=simtime-cat(i);
        if((cha>0)&(cha<=0.01))
            otc(i)=1;
            otchold(i)=hold(i);
            dockship=1;
            unload_time(i)=unload_time(i)+0.95*otchold(i)/15000;
        end
    end
    
    
    if nowtime>=6%判断油轮到达时间是否为凌晨0点到6点之间
        if dockship==1  %判断码头是否有船
            if tankoil<300000%判断是否为码头油满(设码头的储油量为300000桶)
                if unloadtemp==0%是否为卸货暂停
                    for j=1:144%查找先进来的且未服务完的油轮卸货
                        if otc(j)==1;%%%%%%%%%%%%%%%
                            break
                        end
                    end
                    otchold(j)=otchold(j)-150;%卸货
                    tankoil=tankoil+150;
                    eatoil=eatoil+1;
                end
            else
                unloadtemp=1;%码头油满,置位卸货暂停标志
            end
        else
            freeime=freetime+1;
        end
    else
        night=1;%如果是夜里,置夜标志位night
    end

%以下为统计一步长的状态,并改变相应的状态量
    for t=1:144 %%%%%%%%%
        if otc(t)==1
            wt(t)=wt(t)+0.01;
        end
        ql=ql+otc(t);
    end
    if otchold(j)<0.05*hold(j)%如果油轮的剩余油小于其容量的5%,则卸货完毕
        otc(j)=0;
    end
    if tankoil<(0.8*300000)%如果储油罐的储油量小于其容量的80%,则恢复卸货
        unloadtemp=0;
    end
    if ql==0
        dockship=0;
    end

%以下为给炼油厂供油的仿真 
    if tankoil<=5000
        outputoil=0;
    end
    if tankoil>=50000
        outputoil=1;
    end
    if outputoil==1
        tankoil=tankoil-130;
        outoil=outoil+1;
    end
    sum_of_tankoil=sum_of_tankoil+tankoil;
end


total_waittime=0;%所有144条船的总等待时间
wait_time_of_eachship=wt-unload_time;

for i=1:144
    total_waittime=total_waittime+wait_time_of_eachship(i);
end


average_tankoil_of_each_step=sum_of_tankoil/(60*24*100)
averge_inoil_of_shipside=eatoil*150/60
averge_outoil_of_shipside=outoil*130/60
working_efficiency=1-(freetime*0.01)/(24*60)

average_wait_time=total_waittime/144


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -