實(shí)驗(yàn)三-利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案_第1頁
實(shí)驗(yàn)三-利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案_第2頁
實(shí)驗(yàn)三-利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案_第3頁
實(shí)驗(yàn)三-利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案_第4頁
實(shí)驗(yàn)三-利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

實(shí)驗(yàn)三利用預(yù)約表編程計(jì)算非線性流水線的任務(wù)調(diào)度方案一、實(shí)驗(yàn)?zāi)康耐ㄟ^本實(shí)驗(yàn)幫助學(xué)生理解單功能非線性流水線基本任務(wù)調(diào)度方法.二、實(shí)驗(yàn)環(huán)境開發(fā)工具使用windows平臺(tái)下的vc++6.0.三、實(shí)驗(yàn)內(nèi)容給定某單功能非線性流水線的預(yù)約表,通過編程求出所有不沖突的任務(wù)調(diào)度方案并輸出.流水線功能段數(shù)隨機(jī)。四、實(shí)驗(yàn)結(jié)果#include<stdiooh〉include〈iostream。h〉includeviomanip。h〉#include〈string.h〉constintMAXJOB=50;〃定義數(shù)據(jù)結(jié)構(gòu)體typedefstructnode{intnumber;intreach_time;intreach_hour;intreach_minite;intneed_time;intprivilege;floatexcellent;intstart_time;intwait_time;intvisited;}job;jobjobs[MAXJOB];intquantity;//初始化函數(shù)voidinitial(){inti;for(i=0;i〈MAXJOB;i++){jobs[i]。number=0;jobs[i].reach_time=0;jobs[i].reach_hour=0;jobs[i].reach_minite=0;jobs[i].privilege=0;jobs[i]。excellent=0;jobs[i].start_time=0;jobs[i].wait_time=0;jobs[i].visited=0;}quantity=0;}voidreset()//重置作業(yè)數(shù)據(jù)函數(shù){inti;for(i=0;i〈MAXJOB;i++)(jobs[i].start_time=0;jobs[i]。wait_time=0;jobs[i]。visited=0;}}voidreadData()〃讀入作業(yè)數(shù)據(jù)函數(shù){FILE*fp;charfname[20];inti;cout〈〈”請(qǐng)輸入作業(yè)數(shù)據(jù)文件名:”;strcpy(fname,”8job.txt”);cin>>fname;if((fp=fopen(fname,"r"))==NULL){cout〈〈”錯(cuò)誤,文件打不開,請(qǐng)檢查文件名:)"<<endl;}else{while(!feof(fp)){fscanf(fp,”%d%d%d%d”,&jobs[quantity]onumber,&jobs[quantity]。reach_time,&jobs[quantity].need_time,&jobs[quantity].privilege);jobs[quantity]oreach_hour=jobs[quantity].reach_time/100;jobs[quantity].reach_minite=jobs[quantity]oreach_time%100;quantity++;}〃輸出初始作業(yè)數(shù)據(jù)cout<<"輸出初始作業(yè)數(shù)據(jù)"<〈endl;cout<<"-——-——-—-—-—--■—”<<endl;cout.setf(2);cout〈<setw(10)〈<”作業(yè)號(hào)”〈<setw(12)<<”到達(dá)時(shí)間"<<setw(14)〈〈”所需時(shí)間(分)”<<setw(14)<〈”優(yōu)先級(jí)(0〉1)”〈<endl;for(i=0;i〈quantity;i++)(cout〈〈setw(10)〈vjobs[i]。number<<setw(12)〈vjobs[i].reach_timevvsetw(14)vvjobs[i]。need_time<〈setw(14)<〈jobs[i].privilege<〈endl;}}}//FIFO算法voidFIFO(){inti;intcurrent_hour;intcurrent_minute;inttotal_time=0;coutv〈endl;〃輸出作業(yè)流coutv〈endlv〈"FIFO算法作業(yè)流”<vendl;coutv〈”-——------—————---————--------——----”vvendl;cout。setf(2);coutv〈setw(10)〈<"作業(yè)號(hào)”〈〈setw(12)〈〈”到達(dá)時(shí)間”〈vsetw(12)vv”開始時(shí)間”<〈setw(14)<〈”周轉(zhuǎn)時(shí)間(分)”〈〈endl;current_hour=jobs[0].reach_hour;current_minute=jobs[0]。reach_minite;for(i=0;i(quantity;i++)(jobs[i]。start_time=current_hour*100+current_minute;jobs[i].wait_time=(current_hour-jobs[i]。reach_hour)*60+(current_minute—jobs[i].reach_minite)+jobs[i].need_time;cout〈vsetw(10)〈vjobs[i]。number〈〈setw(12)<〈jobs[i].reach_time〈〈setw(12)〈vjobs[i].start_time〈〈setw(14)〈vjobs[i]。wait_time<〈endl;current_hour=current_hour+(jobs[i]。need_time+current_minute)/60;current_minute=(jobs[i]。need_time+current_minute)%60;total_time+=jobs[i].wait_time;}cout(<endl<<”總周轉(zhuǎn)時(shí)間:”vvtotal_time〈〈”平均周轉(zhuǎn)時(shí)間:”vvtotal_time/quantity〈<endl;}voidshorter()〃運(yùn)算時(shí)間短的作業(yè)優(yōu)先算法{inti,j,p;intcurrent_hour;intcurrent_minute;intcurrent_need_time;inttotal_time=0;〃輸出作業(yè)流cout<〈endl;cout〈〈endl<〈”時(shí)間短作業(yè)優(yōu)先算法作業(yè)流(開始調(diào)度時(shí)刻為最后一個(gè)作業(yè)到達(dá)系統(tǒng)的時(shí)間)”<〈endl;cout<〈"——————-——-——--——--——--——-----——"<<endl;cout.setf(2);cout〈〈setw(10)〈<”作業(yè)號(hào)”<<setw(12)〈<”到達(dá)時(shí)間"〈〈setw(14)<〈"所需時(shí)間(分)”〈<setw(12)<<"開始時(shí)間”〈〈setw(14)〈<"周轉(zhuǎn)時(shí)間(分)"〈<endl;current_hour=jobs[quantity-1].reach_hour;current_minute=jobs[quantity—1].reach_minite;for(i=0;i〈quantity;i++){current_need_time=30000;for(j=0;j(quantity;j++)(if((jobs[j]。visited==0)&&(jobs[j]。need_time<current_need_time))(P=j;current_need_time=jobs[j]。need_time;}}jobs[p].start_time=current_hour*100+current_minute;jobs[p].wait_time=(current_hour-jobs[p].reach_hour)大60+(current_minute-jobs[p]。reach_minite)+jobs[p]。need_time;cout〈<setw(10)〈〈jobs[p].number〈〈setw(12)〈<jobs[p].reach_time〈〈setw(14)〈〈jobs[p]。need_time<<setw(12)<<jobs[p]。start_time(<setw(14)〈〈jobs[p].wait_time<〈endl;current_hour=current_hour+(jobs[p]。need_time+current_minute)/60;current_minute=(jobs[p].need_time+current_minute)%60;jobs[p]。visited=1;total_time+=jobs[p].wait_time;}cout〈<endl〈<"總周轉(zhuǎn)時(shí)間:"<<total_time〈〈”平均周轉(zhuǎn)時(shí)間:"(<total_time/quantity〈〈endl;}voidprivilege?!▋?yōu)先數(shù)調(diào)度算法{inti,j,p;intcurrent_hour;intcurrent_minute;intcurrent_privilege;inttotal_time=0;//輸出作業(yè)流cout<<endl;cout〈〈endl<<”優(yōu)先數(shù)調(diào)度算法作業(yè)流(開始調(diào)度時(shí)刻為最后一個(gè)作業(yè)到達(dá)系統(tǒng)的時(shí)間)”<〈endl;cout<<"---——-----——--——---——-——------——--——-——--——--——--——-”<<endl;coutosetf(2);cout<<setw(10)<〈"作業(yè)號(hào)”〈〈setw(12)<<”到達(dá)時(shí)間”〈〈setw(14)〈〈”優(yōu)先級(jí)(0〉1)”〈<setw(12)<〈"開始時(shí)間”〈〈setw(14)<<”周轉(zhuǎn)時(shí)間(分)”<〈endl;current_hour=jobs[quantity-1].reach_hour;current_minute=jobs[quantity—1]。reach_minite;for(i=0;i<quantity;i++)(current_privilege=30000;for(j=0;j<quantity;j++){if((jobs[j].visited==0)&&(jobs[j]。privilege<current_privilege)){P=j;current_privilege=jobs[j]。privilege;}}jobs[p]ostart_time=current_hour*100+current_minute;jobs[p]。wait_time=(current_hour——jobs[p]。reach_hour)*60+(current_minute—jobs[p]。reach_minite)+jobs[p]oneed_time;cout〈〈setw(10)<<jobs[p].number<〈setw(12)<〈jobs[p]。reach_time〈〈setw(14)〈〈jobs[p].privilege〈<setw(12)<<jobs[p]。start_time〈〈setw(14)<<jobs[p].wait_time<<endl;current_hour=current_hour+(jobs[p]。need_time+current_minute)/60;current_minute=(jobs[p]。need_time+current_minute)%60;jobs[p]ovisited=1;total_time+=jobs[p]。wait_time;}cout<<endl<<”總周轉(zhuǎn)時(shí)間:”<〈total_time<〈”平均周轉(zhuǎn)時(shí)間:"〈<total_time/quantity<〈endl;}〃響應(yīng)比最高者優(yōu)先調(diào)度算法voidexcellent(){inti,j,p;intcurrent_hour;intcurrent_minute;floatcurrent_excellent;inttotal_time=0;〃輸出作業(yè)流cout<<endl;cout〈〈endl〈<”響應(yīng)比高者優(yōu)先調(diào)度算法作業(yè)流(開始調(diào)度時(shí)刻為最后一個(gè)作業(yè)到達(dá)系統(tǒng)的時(shí)間)"<<endl;cout〈〈”——-——-————--——--————-———-----—-——”<<endl;cout。setf(2);cout〈〈setw(10)<〈”作業(yè)號(hào)”〈<setw(12)<<”到達(dá)時(shí)間"<<setw(12)〈〈”開始時(shí)間”〈<setw(14)<<”周轉(zhuǎn)時(shí)間(分)”<〈endl;current_hour=jobs[quantity—1]。reach_hour;current_minute=jobs[quantity—1].reach_minite;for(i=0;i<quantity;i++)(current_excellent=—1;for(j=0;j<quantity;j++){if(jobs[j]。visited==0){jobs[j]。wait_time=(current_hour-jobs[j].reach_hour)大60+(current_minute-jobs[j]。reach_minite);jobs[j].excellent=(float)(jobs[j].wait_time/jobs[j]。need_time);}}for(j=0;j<quantity;j++){if((jobs[j].visited==0)&&(jobs[j]。excellent>current_excellent)){P=j;current_excellent=jobs[j]。excellent;}}jobs[p]。start_time=current_hour大100+current_minute;jobs[p]。wait_time=(current_hour-jobs[p]。reach_hour)大60+(current_minute-jobs[p]。reach_minite)+jobs[p]。need_time;cout<<setw(10)〈〈jobs[p].number<<setw(12)<〈jobs[p].reach_time〈<setw(12)<<jobs[p]。start_time〈<setw(14)<〈jobs[p]。wait_time<<endl;current_hour=current_hour+(jobs[p].need_time+current_minute)/60;current_minute=(jobs[p].need_time+current_minute)%60;jobs[p]。visited=1;total_time+=jobs[p]。wait_time;}cout〈〈endl〈<”總周轉(zhuǎn)時(shí)間:"〈〈total_time〈〈”平均周轉(zhuǎn)時(shí)間:"〈<total_time/quantity〈〈endl;}Voidmain(){initial();readData();FIFO();shorter();reset();privilege();reset(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論