数学建模社区-数学中国

标题: 经典任务调度算法的模拟程序 [打印本页]

作者: 杨利霞    时间: 2021-4-9 15:15
标题: 经典任务调度算法的模拟程序

1 C" e8 N/ x( @; h' ?经典任务调度算法的模拟程序
' `8 m: e$ f1 \8 a  }8 Z. N7 e9 {本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
& Z6 P  X+ I. c, r! O! R( ~% `. e; D: K% |0 _0 I
编程平台:VC6.0+EasyX图形库环境。9 a* ?; d4 m( V; ]* l( {
2 m' D/ v# |, k$ f8 Q7 p
以下截取部分程序运行图::
# X9 ~3 F1 j# J5 x5 D2 q9 F; G# I3 B8 ~, P3 V
源代码:
) C) Q6 I& N) L! _( S
) u# q  k" C' G0 l( U' c2 N1 a#include<stdio.h>$ G4 h% E) W6 e" K' v# b4 J  d- Z
#include<stdlib.h>
$ \$ t/ x& `& A2 r8 v( w4 f: B#include<easyx.h>7 s: c/ ~3 _) B6 p! ^
#include<time.h>+ f0 A! }. I% o! j$ z5 M+ a7 f3 U
#include<conio.h>. n5 |6 R9 \% K
#include<graphics.h>
, e5 w7 ^. G+ w; Z3 o#define initProcessNum 106 `" C0 V/ q9 X/ L. K7 {1 l
#define initProcessID 1000
' Z) \; @( V7 V9 r  j#define MAXProcessRunTime 100008 A$ X. g. y6 |, F. H0 r. b& j
#define MAX_MEMORY  4000
* x8 L$ R3 t5 r0 N#define exchange_IO_Compute 10
* a) m8 ]# ~% M0 U  U" \* _#define exchange_process 25
  G7 H% y) q; ~: \' A! k3 ?#define task_completed 1
' Y% \7 {; e- u, n. z#define task_not_completed 0
& w. O# |$ ?3 V#define initclocknum 100
; z) M% q: n! j- senum condition
: u! S, H: m& J7 R2 y& M* F{
$ ^) p8 F4 z( L# u) h9 O- {6 {dead,computing,IO_waiting,ready
0 l: d) C. j6 I- k5 [0 x: ]# v};
# }  J  i/ T* k, dstruct process
3 L& L, _& i. V5 p1 W+ ]- W{: {4 c, \6 q# V0 o
int processID;& w8 ], P4 C" h; L) x
int comeingTime;
/ ?% ?/ r1 }+ g0 G9 [) O9 Z& eint ioNum;' D+ X$ `: l: x( z
int computeNum;
% |( ?. C. m3 N6 X& v1 Oint * ioClock;' [$ Y9 B7 }: D1 ]. `& {
int * computeClock;
5 F3 j* i# h" `! C: X! W6 y* zint ioTime;# h: ]; R6 V& d. ^2 S5 M
int computeTime;* K7 v# f) A' m& @! G, i
int askMemory;% E. J) }+ \0 t; F: L* L+ q
condition flag;0 a$ Y# I, X& _0 t- E1 Z* t. C1 c) |6 t
int produceTime;  //生成时间,以下三个数据成员用以计算相关性能& T9 e0 Y  e4 t5 |5 P+ k: ~5 M
int runningTime;  //第一次占用CPU的时间
% b9 ]0 A! q1 U. E5 A4 U5 A7 rint completedTime; //进程完成时的时间
( Z& v* f  g# x1 J5 ^};2 P& f& ]4 ?! J8 S
typedef struct processCmpletedInfo  //保存完成一个作业的相关信息
8 N: `4 F+ I; Y# @5 Y8 w+ `% }{& a- ]0 E+ m- e( p, L/ N
int processID,comeingTime,askMemory;
0 Q; A: w4 n. bint compute,waitio,exchange,completedTime,runningTime;
7 j4 |, G% U$ G" ?6 f. e. \processCmpletedInfo * next;0 T& E) I# G; \7 c4 H6 t( T
}PCI;& }4 R; A$ }/ [, P
struct processPool
/ B* h4 f0 n. C0 U{
. o6 R- ^- ~8 e7 Xprocess * p;
: _( g! N& k2 r1 Yint proNum;
3 G3 r7 g7 k* T0 A};
  A- {! \6 A( |; L# ]int MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;% Z% C" y* A- I( I
int InitPool(processPool * p);8 A  e0 c- v: _1 y
int produce_one_task(processPool * p,int i,int id);. N" t. t: Q- e2 i5 O/ ?$ P
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
" L/ g. F& T5 {int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
. u0 e! K1 w' ?, m! g% b4 D1 N4 Kint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
1 g" x1 k+ p! Iint FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
" [+ j' {' R* R8 K* G& Wint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);, J% ?$ [8 R7 O" o4 A
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
5 I+ u+ d' `/ K! c# \int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
7 R: L5 y. c* e* t3 _7 p! B: Q8 Qint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
$ m- R$ ~, w# ?8 J* n8 a" x: W) dint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);* i( T1 W9 c+ K3 f! a% M6 @5 r
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
3 j# |* E7 Z$ B0 K" U4 x+ N) V8 L' K

& ~3 d/ [) {% Rint sort_by_comingtime(processPool * p,int pos);$ A( |: T6 I. I
int showProcessInf(processPool p);
1 l7 `/ k# m# U6 a2 ?; W+ g: iint drawPerformance_FIFO(int x,int y,int memorry);4 W- M& \- \# A  E" ]: n4 u
int drawPerformance_HR(int x,int y,int memorry);
3 b+ m3 Z) s* x9 hint drawPerformance_PF(int x,int y,int memorry);2 j5 t( v) L, m' A  n
int drawPerformance_TT(int x,int y,int memorry);
/ L- A5 @/ w' A+ n$ Oint drawPerformance_SJF(int x,int y,int memorry);
$ q7 k9 p, H9 G* e+ f2 b, I& s% z: Lint MouseListening();9 a7 [# q$ X; ]& m; \/ M
int MouseListening2(int *flagShow,int * showTime);, }1 t5 E: H4 }6 M
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
: Y5 q) r& P$ D% a
$ q( e9 G1 x7 |2 M6 H. w
; j: O0 h9 b% i( F( j) i" {- Pvoid main()
  S3 j; Z+ x& a/ f$ x) ^; U& u8 x{
$ v4 G, S$ h8 j& E/ LPCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,+ A, |) \, r& W  I% {* V
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
5 J! J6 [* C! s& b; d6 Kint i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,4 D& e* c) L5 I; s  ^
flagDraw=0,showTime=100000;
# m3 P! x9 F" ?9 eprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;7 `( }  ^9 a" z- P
FILE *fp=NULL;
) J" {! k6 m: a3 o5 x//processPool HR_p,HR_mmy;
5 R2 L0 b% \' |& c9 {
! {$ B% N! u; E- m7 [% R; n3 U$ v) @5 I0 I& D
srand((unsigned)time(0));/ P, s' T4 f; Y7 v* A; p
systemClock=0;1 h7 a3 I/ i) l' _" L1 i
initgraph( 1200,650,SHOWCONSOLE );: M- ]  Z% a# i; d1 R' C0 \+ B
settextcolor(GREEN);
2 l& \. @! V% Vsetlinecolor(GREEN);
- W- N# }1 K- ^' c$ e' q  bsetfillcolor(GREEN);
" o" A7 E% N% U0 L% e+ bInitPool(&FIFO_p);
1 O3 E" [4 o) C- A3 Qsort_by_comingtime(&FIFO_p,-1);
  O, R9 |& u) X' Q% }0 [InitPool(&Timeturn_p);
: ^, {3 A. U: ]7 cInitPool(&SJF_p);+ U9 Q1 y" Z8 X# ~+ u
InitPool(&Priority_p);
1 C; h4 _: Q9 S% a8 Q  BInitPool(&HR_p);
5 H2 u7 t7 D0 \& g9 g' K//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
3 Y! ?" ~) X4 t//Sleep(10000);% h( {0 m# v' I
7 a% g9 H9 J4 L7 T  j( D4 x$ I; H4 J
' i) ]6 h  p) x) H
Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));# Z3 K2 h  b7 c4 ~' S
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
7 \. J- T4 L- J9 L! l* DPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));- ~4 S. g* N# u
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
# [: S( g$ {0 k; G$ ^+ d3 w' n( n$ _for(i=0; i<initProcessNum ;i++)5 R$ h6 W6 A" `0 G6 ?2 b
{
" t7 [, e- a& ]0 cTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
. x% b5 L% {" e& Q  bTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
" Q' a/ g3 A! j- }& dSJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
9 a( K& U  O, J# z  y6 R- `. nSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
, d3 C3 U' s; E; W" Z4 Q4 QPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
3 h; Z/ S% l' p9 q9 lPriority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));6 G9 \% D( R# z& U# r
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
- r* M6 R" _( S2 D; q* y/ y7 HHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));+ B# n! O2 b4 ?0 x5 N
}
( w7 j/ r& |/ g/ _Timeturn_mmy.proNum = 0;
* }  y" x$ f' jTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);5 T& e" m2 O3 I2 f2 W/ X
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);! C- ]# N8 c* c$ B0 u# v0 i) t4 T
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
# r* V5 e9 U4 T# b5 ~* [High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
. t( ~& ?2 ~7 s, P//showProcessInf(Timeturn_mmy);
6 N- S/ l( F) j' V% wFIFO_pri = &FIFO_save_head;
; r5 p' B4 j. |+ T. i7 ~/ p5 ^6 `) wTimet_pri = &Timet_save_head;) F+ Y+ ?) g9 z9 Y& Z0 Z
SJF_pri = &SJF_save_head;6 @% o& k  A: o9 {6 n
Priority_pri = &Priority_save_head;  M7 u  p4 v3 R! L
    HR_pri = &HR_save_head;+ a6 _. b9 J6 K1 ^3 a; a) z, O
setbkcolor(WHITE);
$ X, D) a0 x/ h% u9 ?7 X3 G) Lwhile(1)5 W2 a3 e" ?& |, W- ]6 V
{: g1 N* P1 d1 l
if(MouseListening()==1)9 g. Z" \, a& e) Z
flagDraw=1;5 N6 U& k9 _3 _. Z
if(count==100)
6 a5 C6 D( Q) K# @; T  r0 z{
( c) a: s9 m1 b' K8 ]+ Hif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
) F4 f; u; R2 o1 r{
. H9 e' F; Q% X9 K6 Z3 xFIFO_pri = &((*FIFO_pri)->next);4 u: y: s* E# Y) f! r* `

- T! V% }3 r7 n$ z8 ]2 L, N//printf("hello");9 V5 o0 V7 {2 x6 i- I
}
# M) G/ J/ d* k6 e" D: P2 S( M  T$ n4 rif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)& W2 T: z' @' V3 X+ H1 _
{. R9 I. ]2 h6 L: Y- a. k
    Timet_pri = &((*Timet_pri)->next);
4 A5 i* \0 s" D+ _+ P3 H* {//printf("hello");
' P2 B' X9 ^4 e2 K( ~! O' p2 W}
1 x: ?: b- A3 ~; _8 S- B* Fif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)$ }  h1 V, r& T, D, n9 m
{2 X( d, E8 ]/ x$ O  \
SJF_pri = &((*SJF_pri)->next);
. r  h3 C9 c3 n1 V9 L//printf("hello\n");
$ g3 k4 ~8 R! u}6 d, {" ^1 P9 ?% E# ?
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)+ {. X6 T" [6 Z" p4 f& F
{
, n, ]) z$ y7 g4 ?. ]8 ^$ lPriority_pri = &((*Priority_pri)->next);& q: L* b! q8 I- e9 M0 j- _
//printf("hello\n");
/ q+ M8 G- d$ x# t}
3 y/ ?4 u; S( t- \if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)" G0 k5 ]) O( U" }. @% n
{6 @$ c, E' i- ^$ q. d  a  p
HR_pri = &((*HR_pri)->next);
# U8 F( P$ K+ S. G7 ^( h7 C//printf("hello");
$ s. e/ \# w/ z; Z+ L+ a}
7 k" i4 l9 H* x6 n) |count=0;6 J8 k" ~3 |/ |/ `  x
}
$ f5 g2 h$ t3 R5 lelse# k+ S! b9 Q$ D$ i( J& z& a
{
! U& y" g8 U% H4 aif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)' `$ i2 D1 _1 H- G: C5 \5 \
{% k: z* X9 K! i2 ]7 @5 e8 _
FIFO_pri = &((*FIFO_pri)->next);4 H$ r( B; u3 n) s4 n& @
// printf("hello");2 \' V. X3 }: S+ ^& {% ?
}
& R& V* r7 J- ~/ e$ o' |$ ^# Aif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)/ i8 k4 o6 O9 \2 {1 c
{8 O; J0 R9 T0 {
Timet_pri = &((*Timet_pri)->next);& `6 ~& n1 x! k7 S/ _" a  ]: j
// printf("hello");+ C9 M4 K: p; E2 l! a5 N" l8 w
}) H3 S% i7 Y& b/ v' \$ [+ A  G$ N8 z3 E9 c
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)0 Z) F' c9 e* [, H2 x, g+ j
{( X1 {% a5 _  Z: s
   SJF_pri = &((*SJF_pri)->next);( E) ^! w3 r0 F3 R. P0 S- w
// printf("hello\n");6 Z& F. u. d# c) a" K* i' f$ y" a% L
}3 U* }9 C6 ]' i+ j. n; z
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)" S3 N  T" [& E) J6 s' n
{
7 N# H2 U% {; b. ?Priority_pri = &((*Priority_pri)->next);4 r  b% U0 K$ i9 y7 z9 U/ s) ]
//printf("hello\n");% T& ?4 M$ M6 m5 G
}
$ U/ ~# T0 e3 a% |5 m  C% A- Dif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
7 G, z) r& N9 d{
& `9 g0 ]' y+ |4 n4 u$ Y' {6 J, GHR_pri = &((*HR_pri)->next);
6 h4 G% @+ I' F; v2 q; z& G//printf("hello");
7 U# j) H: }9 e' t& l% i, N, |//Sleep(1000);
6 h$ ]$ U& g8 @5 C* n}/ }- z, X; N8 S/ i3 b) T
count++;# U" w( \$ q; o* F; [3 s3 n! ?
}. X8 q& U  o, s
if(systemClock==showTime)0 J" y( r, ], Y7 d3 n
{
* Q# a7 ]$ z" g& V# t/*PCI * p=FIFO_save_head;
" Y. B  v) ^, [int i=0;
# Z, C/ {  I. P1 p; Kfor( ;p!=NULL;p=p->next)
- I) F# x! k+ {" G4 S+ |- K- s{. a' F& n4 J8 S( u. _3 ]( q
printf("Id %d\n",p->processID);
2 @1 p2 d/ [3 P9 eprintf("comeingtime %d\n",p->comeingTime);
1 s8 }$ r" w8 G' _2 M- |2 u, xprintf("runningtime %d\n",p->runningTime);( \! W% j, u2 ~8 T, f2 ^
printf("asdmemory %d\n",p->askMemory);# D! i1 ~/ ?. Q* v' w( p3 r# t: i
printf("completedtime %d\n",p->completedTime);9 N3 L7 h# K" y
printf("compute %d\n",p->compute);
, L1 ?# F6 ]4 |0 G! K5 \+ Hprintf("exchange %d\n",p->exchange);* Z+ w& l: A5 _, B) V. K) V! J
printf("waitio %d\n",p->waitio);
: c% M& H9 ^7 }$ I/ R  V* yi++;8 [: {6 L2 h8 W$ ^+ w

0 r% o; s/ o$ O, @$ x8 j7 U2 |" B9 r, W! \* y' Q
}# s" q: }. W3 g0 A
printf("%d\n",i);*/8 Q8 f4 m$ R  |' {
if( (fp  = fopen( "data.txt", "a" )) == NULL )
" N$ T( u2 A7 j" T  r" j5 A{0 y* e5 D- R5 _* p8 g) b  A- R6 ^1 K
printf( "The file 'data.txt' was not opened\n" );* ]% U) V4 p% u$ Y" ?
//return 1;
7 ?+ q) A- u8 F" _" G3 J' b0 H}6 [4 a: V4 \- v& g
else6 T, s3 ~2 r$ ?0 N2 D
{
, D! B) ^" {" o& r( x/ _fprintf(fp,"FCFS \n");
. U) W" \, |: G2 P- L- @1 Jfor(p=FIFO_save_head;p!=NULL;p=p->next)
6 y) t' {& q/ J6 S" h# D2 rfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
1 m4 `- W# M& P8 f8 ]/ qp->exchange,p->waitio,p->runningTime);' Y8 a- T% m$ q* ^1 W, Y
fprintf(fp,"\nTime turn \n");
- S( W1 A. R( `3 k) Nfor(p=Timet_save_head;p!=NULL;p=p->next)1 X' _+ L' u/ A* B' w0 Z2 u. e
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
( h- @2 _4 v3 e! p: y) up->exchange,p->waitio,p->runningTime);  m# A9 Y% n1 g, c& g
fprintf(fp,"\nShort Job First \n");3 V2 ~- a  o- R
for(p=SJF_save_head;p!=NULL;p=p->next)
* Y; \  X* E/ c8 |+ cfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,- n  T  M7 Z& C" G, G+ ]- Q
p->exchange,p->waitio,p->runningTime);
7 ]4 }4 E6 L& |7 r7 X4 Bfprintf(fp,"\nPriority  \n");2 N$ ?4 O0 D1 i
for(p=Priority_save_head;p!=NULL;p=p->next)
. E6 ?. t& a# S' F$ P( Z2 E5 Ffprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,8 I4 ]/ N; B" h0 B( a. W
p->exchange,p->waitio,p->runningTime);
; n8 ~* b# T) T% n# m: Xfprintf(fp,"\nHigh response \n");
, ]0 ^0 V* `# I2 jfor(p=HR_save_head;p!=NULL;p=p->next)' z: U% g# B1 m3 ?+ t! c; }
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,- l5 p1 W; }( B( _
p->exchange,p->waitio,p->runningTime);
% w% Y4 W0 \, M! Ufclose(fp);6 |% }% u8 t6 Z
}
- h% S/ D1 y. t# K9 Z, AshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
8 \3 O0 E6 [# [$ GMouseListening2(&flagDraw,&showTime);! |/ `( G  I7 N# x
}$ J/ n; R4 c- {# |5 o( d
systemClock++;
% z8 M' d9 ~' O" ^+ B) D  _1 O" hif(flagDraw==0). z" _4 _( `0 \4 T: a' p6 f
  Sleep(10);
8 }* k( c& g3 H+ f& W1 s}
  }" e) i; e# l/ g- i; {! |% [6 k

) q) X) X4 L) e' G& z}7 {, d8 t+ A9 {0 C
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
7 n/ W) B* e" }{
: w* F8 D) C5 n# F1 l& Q- J& NPCI * p=NULL,* name[5];
( q5 Y* B4 W. t9 ^5 E! a  hint count=0,i=0;/ k4 ]+ v- N' q2 r
char ch[5][10]={"FCFS","timet","SJF","PR","HR"};, @" ]% p- d! D$ Y* m3 L9 k
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};9 |: p! s7 R' Z: Y' Z' y' T7 L
struct info
+ ?# \1 r$ v! g/ M9 v{5 x; ]9 \/ p: f+ a" Z
char name[10];1 u* x9 L& t" X8 r2 }  T
double throughput,turnover,wait,CPU_rate;# ?- w$ v$ l( F" V7 j
}inf[5];4 q& A# B- ?' o) w/ I
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
! p. `2 \  n: H+ Y7 S5 a# bprintf("调度算法..........A\n");+ i$ E# S2 `: A
printf("吞吐量............B\n");
5 ^5 U* M6 k6 v$ }' Hprintf("平均周转时间......C\n");
& o: E1 k) Q* M: i( n. \printf("等待时间..........D\n");
& ~8 m# q& X% [; W# Hprintf("CPU利用率.........E\n");
0 Y$ ^5 W, Y: q8 e5 Zprintf("A\tB\tC\t\tD\t\tE\n");1 P% [  ]$ H5 l4 `0 v
for(i=0;i<5;i++)1 J6 \# J( D8 e6 c: C+ g% b' W! h
{' K2 A3 G0 M: g2 K
count=0,turnover=0,wait=0,c=0,w=0,change=0;
% R# U4 }! Q- ?! K% ~: I5 m) rfor(p=name; p!=NULL; p=p->next)
  t2 {& G' O- G{
- J3 }3 H  t, @  C9 r+ j1 Dcount++;
; H# A. W! `/ sturnover += p->completedTime - p->comeingTime;9 N8 D& G7 P- r9 ]* [9 B
wait += p->runningTime - p->comeingTime;
$ D* S( [3 R. u* u3 ]c += p->compute;
$ R/ b$ l; m$ b8 G; F, c* Xw += p->waitio;4 U8 o& ]  [9 Z, S
change += p->exchange;" R, w8 A  J- E( s- ?8 v. R" K) |
}2 [: A% ?( D. s' V2 h* u+ `
turnover = turnover/count;4 Y! z+ Z4 m1 s' W
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));* Q7 B2 N* f. \; O
strcpy(inf.name,ch);, m5 Q, \0 v9 k; |
inf.throughput=count;8 C3 T* Y/ G! X/ u% Y6 K
inf.turnover=turnover;3 R5 w% ]8 J: d' @# @' E% k
inf.wait=wait;
  y! G7 r# Z! y5 @. h2 Hinf.CPU_rate=c/(c+w+change);
9 y5 a$ f3 [$ }6 ^3 i}( Q+ T4 }' ?* T0 [- n: k
//画图# _+ G) Q' D, H$ O. f
//cleardevice();
2 q* j* n( L- k( h  ]line(0,600,1200,600);3 t( V  R9 ]/ v7 A' x( T! X
line(10,600,10,200);
: m; C) A& g9 e& T/ K* Uline(10,200,5,205);: ^0 M! _5 M# z# `
line(10,200,15,205);
% A) z  Q0 s0 E  m, m2 i' }line(310,600,310,200);
% R/ u  s# q' u2 T# U/ |2 vline(310,200,305,205);
. W2 d( o* H# aline(310,200,315,205);
. ~+ @  N" F3 C3 x3 vline(610,600,610,200);6 n5 y8 m5 S: M
line(610,200,605,205);
7 t; K$ {6 u9 [: Nline(610,200,615,205);
9 d4 f* ~$ Q6 g! _8 {; nline(910,600,910,200);7 @7 N7 s  [/ K
line(910,200,905,205);
& T# {) O. x; }line(910,200,915,205);//最高的长度400,宽度均为407 l# e" @9 ]* D" i
for(i=0;i<5;i++)2 v5 l4 H2 W% ~" V2 R2 |1 P/ Z
{
; b& z( p* S0 ?; K+ x5 j4 zif(inf.throughput>pos[0])' C% M! P/ w7 }6 S
pos[0]=inf.throughput;# [, L0 C3 i, W1 a2 L( {
if(inf.turnover>pos[1])* ?" R0 G8 c( m
pos[1]=inf.turnover;
( m' C/ g0 H6 \if(inf.wait>pos[2])
* \1 @: S5 T5 K0 f; ypos[2]=inf.wait;
9 X" F5 A* g. O2 K! S8 {- |& }if(inf.CPU_rate>pos[3])6 U# x$ r  [+ ^2 l5 y3 |
pos[3]=inf.CPU_rate;% x, j6 S. i7 C5 a! }# }  v
}! Y) o) G: k5 u2 t
settextstyle(30, 15, _T("楷体"));
1 r# Y2 _, E4 k1 z1 d0 {for(i=0;i<5;i++)
. ~% T" Z! Y) X" G{
( i6 P% c6 P( k+ _5 j' nswitch (i)
& M, N( y3 o+ F/ F$ [$ }5 V{
( W; ?5 w# s3 z0 ]) Pcase 0:3 R1 r, ~$ F! R: @4 f1 }
setfillcolor(BLUE);5 U; r' K! o0 F/ t6 x7 \  ^
fillrectangle(100,50,150,100);3 W" u$ X& j% k3 L4 R7 b
outtextxy(160,50,"FCFS");) {9 }- q8 m8 S8 Q, u  ~5 ^& p" N% I, A
break;
8 g" `0 a5 }9 ~case 1:5 d+ q; m5 H) I  }6 ]% ~' ~
setfillcolor(RED);
) \" L; S! n4 S& Afillrectangle(250,50,300,100);  Z1 p/ A+ J5 T6 v, M) l
outtextxy(310,50,"timeTurn");# R: Q! Z1 y" j3 Z- F7 ]) A
break;3 O# o1 b6 X; r. c1 ~, a
case 2:9 ^6 B1 O2 o/ Y6 h$ h+ a
setfillcolor(YELLOW);& i8 K# k! R+ N% _
fillrectangle(450,50,500,100);4 p* L( O$ D. z% B4 b
outtextxy(510,50,"SJf");
+ o3 ^* B3 C8 Bbreak;# p$ x6 X5 f# g* k* A2 @7 z
case 3:
* L4 w4 _6 A+ n1 p9 L+ A! lsetfillcolor(BROWN);
. `8 A, F* w# T9 F% |+ Ufillrectangle(580,50,630,100);' u, ~8 M1 c( l: p
outtextxy(640,50,"PR");5 T, e8 g  r( d
break;, V) n# z2 M5 ?
case 4:& k/ N) ]+ E4 \
setfillcolor(GREEN);* u* ^6 e. I5 u6 f5 o7 g( M
fillrectangle(690,50,740,100);
9 C! C2 |6 n9 c0 J( C. H0 Y$ M5 k' ?outtextxy(750,50,"HR");+ y# c4 U, r: U0 m
break;
+ r% Z) I; R* b8 g) ^3 u8 R, w}
% Q  m4 d$ j* V) H0 @5 Q' Zfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
# `( J+ M& N' J- yfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);( ^: U2 E+ @( M) D2 k+ N
fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
+ c3 V! c9 [2 A2 q, h  _1 y0 E; Ofillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
2 d9 w0 F( o  r) q9 G( T1 p5 s$ W
+ l; |, p  ]# i& L% ]* p1 s% i# l8 }" ^
}
2 M( C: B2 z( g" g6 g; I    outtextxy(100,150,"吞吐量");& m: `- k. q# C
outtextxy(350,150,"平均周转时间");2 A$ y: s& c5 E2 x
outtextxy(650,150,"平均等待时间");
2 q" n) J& H) b. b; Touttextxy(950,150,"CPU利用率");& H. U$ x3 }) d" n# D0 H, _
return 0;1 \1 F) i# U2 f* _
}
* M* S  p+ ^: ?! ~& cint MouseListening()2 n( G  N. F: F; ^1 K2 \) l; f
{
! d4 h9 g, F- N# [- D( @MOUSEMSG p;
4 X& V! k4 ?  a; V7 Y" Cif(MouseHit())% L+ o" D' I3 T; f/ o' C0 S
{
2 R- J( D8 v9 g1 Y' @p=GetMouseMsg();
( D3 k3 I1 W4 v8 T3 }( z% X5 {' lif(p.mkLButton==true)9 A: }- Y8 @6 B6 z% ]" w+ N
{
; Y$ {: v6 S+ d, C; q' c2 t% U: T7 wif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)& H2 f  n, G1 ^6 ]" t- f
FLAG_FIFO = 1;0 m$ w/ \5 \* ]( D% S
else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0): g  [0 j& z, y2 }" Z( j
FLAG_TT = 1;
& x! E- a  P. Z. R3 {; helse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
/ U* L% A0 t  M( J& QFLAG_PF = 1;
# O& ~  t; w+ K+ G: r% Jelse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0). Y  L/ ^! A) k
FLAG_SJF = 1;0 r: R  G& Y4 ?
else if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
3 P' E9 s+ O+ A. YFLAG_HR=1;9 C  ^' e3 a+ c: q$ x$ X
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)+ V' p, o' w# ]7 f; |
{' h; e' y, B& v
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
+ D. \% W! G* {: {5 ?8 eclearrectangle(800,325,1200,650);
% L8 q( D$ e/ K* G( S" ]}! q( }! W+ r" S) X
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
$ Y. X- V3 I$ j" ^' k' Y6 m{
# \0 _" w6 d% F$ D9 [( oFLAG_show=0;4 n# s$ u" a1 k8 \% s7 u
cleardevice();
4 q; ]- Y4 p5 E+ Mreturn 1;7 A" e8 x& @8 J8 Q2 N
}
7 B. v- Z9 ]/ h, z}% n% u; Z. H* c) a  O* I
}
3 Y# Y# I7 K( K/ u+ u- vreturn 0;9 u& k2 J  Y% [
}0 j) X5 _: f) w% `& @
int MouseListening2(int *flagShow,int * showTime)* k1 E. E4 x. h
{0 }7 Z& }, G# a7 ]& B
MOUSEMSG p;: h7 n0 S8 W8 Z3 Y
rectangle(1150,0,1200,50);* d2 B- J/ i; n( m5 h! C' H; L
outtextxy(1160,10,"X");
/ Y3 H7 U0 B' ]; ]+ y) M+ h1 Uwhile(1)
) H1 m! p/ S+ e{
6 b4 B: \& O- C5 \' N2 aif(MouseHit())
1 K: o5 ]& y4 t  G. h, v4 ^, i% e{
6 I. Y( [# |# Z, v  {( Bp=GetMouseMsg();
+ ]6 ?+ o4 N. n7 c; Vif(p.mkLButton==true)
4 c; P( a5 [/ G0 R{
6 t9 Q- L, ?$ v' F% s2 f9 l9 Nif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )1 V# G3 [$ n  D6 ^- s* _( P: b1 w/ f
{
+ L+ T8 v, d) J0 W5 X: u+ Q(*flagShow) = 0;
& B4 Y( B# J" u/ f8 O! O(*showTime) += (*showTime);
+ X6 _( ?: S8 D% E/ |FLAG_show=1;
3 N* n- ~1 s/ t5 T* l/ Kbreak;
, W6 v1 y2 w& C, P$ _% B}
$ H. F. H# m# W; t" P$ u9 x: n9 {- O5 O  f$ ]
}
" m9 B+ [) `8 w* r6 C# {# X}
7 \5 ]4 J5 y7 k1 h7 Z1 VSleep(20);" g9 O  D# Y- G+ m
}
- A/ \; c$ S) icleardevice();
0 L5 N# y5 T* s8 E8 Oreturn 0;
) U% A9 g  m5 c. |# m7 A- ^}) E1 p3 x+ L* j( e. r* r
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)' c( L& }, E) E
{
' D$ r; J0 ?" A2 c. |% Xstatic int info[11][3],num=0;
6 l" n+ c7 z( R; A* bint i=0,j=0,pos[10][3][2];/ q) t# k/ |5 k. \' r- d
float temp,t;0 E% g& O3 C" X3 x9 Y7 W3 e  q% ]8 {
//画按钮,不属于FIFO图的范围  h- j9 k% s3 y; j' ?! v$ F
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
4 \& j; X. w( i2 d{8 V  r/ r5 I/ t* F
settextstyle(30, 15, _T("楷体"));
  X) U0 N; W% L, Drectangle(890,455,1110,510);0 x; ?$ @# E" Z! P" L
rectangle(900,465,1100,500);3 K" N+ B' `2 }0 t
outtextxy(910,468,"查看运行结果");
  N0 M) T5 m" ?- g}
+ p3 t. X( m* M2 e% v. O5 B//结束画按钮
' ]# P0 m9 @+ B5 C2 p' E9 |info[num][0] = com;" J4 l/ W2 b; E0 e
info[num][1] = wai;
1 ^5 W' M5 O+ z# y( m. V  winfo[num++][2] = cha;* X& Y& h4 N: Y2 h6 a4 C# I  o3 U) G
if(num>10)  //存储10个点$ n3 e1 y  [/ j2 {, s
{3 C/ O$ D2 y4 c: B/ M$ Q
for(i=0 ;i<10;i++)) a0 Z, E7 l! w
{$ J2 |2 X, d7 R+ s! G5 n
info[0] = info[i+1][0];2 y4 |, u) g( ]; A2 k4 O, k. a
info[1] = info[i+1][1];( I6 [7 a) D0 J9 \
info[2] = info[i+1][2];1 T2 Q% W; z) Y. P5 c
}2 i% x/ }4 _3 J  W
num--;
: W/ p/ c8 [; V( R' O}
/ b" V5 Q' g: t1 T& Eif(FLAG_show==0)/ a1 m/ z( U- y+ N+ {$ d: M. W0 |- J0 O5 M
return 0;, Q5 ?* S( q) W% h* W
for(i=0; i<num; i++)
' Q/ x3 i$ s' {  F( x5 A# e{
6 Z# f* d9 N7 n; N9 p  D6 W5 c" mt = (float)info[0];2 P& B3 \* o; C& B1 `$ h1 w) j
temp = (t/101)*90;
4 b) K; G& X$ G  N( O' E- u5 Kpos[0][0] = (10-num+i)*25+x+100;
1 P: p, h2 m( a4 K9 y: Jpos[0][1] = y+110-(int)temp;
, [/ [  f0 W* st = (float)info[1];+ y6 i1 |. n% J% k" \# i# J
temp = (t/101)*90;# [! j9 ?, S3 G/ F5 v
pos[1][0] = (10-num+i)*25+x+100;- G* r. P" |1 ~; }  q
pos[1][1] = y+210-(int)temp;( S, J% n% Y: Z
t = (float)info[2];7 e' Y4 r4 x/ M
temp = (t/101)*90;
) W- i6 b/ z% Jpos[2][0] = (10-num+i)*25+x+100;
/ `4 Y9 z5 |1 ?3 ]2 b. Bpos[2][1] = y+310-(int)temp;
  w1 u! H5 j1 _4 U# h- Z; U) `}
4 I( z* I8 z0 E# e1 ?! l2 W* Tif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
' \* ]8 e, W; H4 t* `{5 ]+ X! K2 @$ j2 G' Q- U: q
clearrectangle(x,y,x+400,y+315);6 K& Y3 Y. X. N. d6 \: p) K
settextstyle(20, 10, _T("楷体"));
& T& H# f) b% wrectangle(x,y,x+400,y+325);9 N' \& }5 ~8 B; j, F5 V4 f
outtextxy(x+40,y+10,"CPU");       //画柱状图8 ~+ S. \& {3 o6 d. l: O: T, E) ~
outtextxy(x+45,y+10+100,"IO");! B3 f$ b6 t: j
outtextxy(x+40-15,y+10+200,"change");
# ]. D1 j% y) U. \8 U; q# Y0 [rectangle(x+35,y+30,x+75,y+110);% T; \4 `: }* M5 Y
rectangle(x+35,y+130,x+75,y+210);
& X) ^1 B2 S, u, U( erectangle(x+35,y+230,x+75,y+310);4 H  @6 L. v. r, _
outtextxy(x+180,y+310,"FCFS");" {. ]/ C% D4 H4 l; o' q5 {
t = (float)com;4 u+ b  i' k1 l( n
temp=(t/101)*80;
% I: E* o# d5 G& ]fillrectangle(x+35,y+110-(int)temp,x+75,y+110);3 L& v" I% [6 s0 e& M: |3 h! T
t = (float)wai;
" Y% x- V' E% r6 [9 v' mtemp=(t/101)*80;
, X" R3 q3 I6 K0 ]# mfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
$ c" N# v) p" l/ }% c, B  At = (float)cha;1 u9 C' f0 p" t+ R. l
temp=(t/101)*80;! p# C. n" v- q8 X5 ^1 \
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);- A  X/ x0 |+ j- y3 _$ P
for(i=0; i<3; i++)   //画坐标   high=90,length=250
, m: }& g8 `- ~% h. e5 h1 k3 t{' T6 T! M- S! T( c% A9 s
line(x+100,y+110+100*i,x+350,y+110+100*i);
0 F, R2 W6 Q0 R- t+ E+ J& tline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
1 o/ n0 e2 h+ W0 g. pline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
+ U& m+ X7 Q" l) u6 ?, e- O7 N5 y# |$ P0 Z& c
line(x+100,y+110+100*i,x+100,y+20+100*i);
7 a& L  U- ?( n9 t, Mline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
3 L6 n2 s# G1 [1 a( ?; dline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
6 f: e+ _: z7 A* z( L1 A, E, |for(j=0;j<num-1;j++)
& S4 v! ~5 |9 o! U# R! G+ p{0 x; p4 d7 U+ w! Y# `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ {9 @' \1 e% \6 M9 j
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
: _" ^% ~0 n8 ~; g- ]8 _9 b+ e) dline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 s. D1 M& x) X* P; E}5 N# R' W7 q& |5 u1 C7 |2 @
}) ]3 J0 h2 J7 B* T
}0 F4 B, G6 H8 R6 N$ ?
else if(FLAG_FIFO==1)$ O2 i4 A# |/ K" K
{
( V' |. T1 C2 x1 t. zx=0,y=0;" @% t9 i' k! o" N. M9 ^
for(i=0; i<num; i++)
4 u$ f/ C0 d4 _. @{- x7 |( s0 t7 j' Z. n2 G/ R$ ?/ x
t = (float)info[0];8 _3 z* l( Z$ @5 o
temp = (t/101)*180;
. ]1 P1 j, b6 I5 m& t7 |2 @pos[0][0] = (10-num+i)*50+x+650;' a) @% r  f8 f; `9 \/ i, L( S
pos[0][1] = y+210-(int)temp;
9 [& B; W- t/ ?$ a/ Lt = (float)info[1];  C1 [- ^7 o0 p, @5 E! U; G9 I
temp = (t/101)*180;" x- A2 l! t( D  Q
pos[1][0] = (10-num+i)*50+x+650;' f- @$ V! _- r, }- p) `* ~
pos[1][1] = y+420-(int)temp;
/ O+ u% z! g: E2 Y- zt = (float)info[2];
7 V- M% Y: m8 Y  E  L) P2 n: s% Ttemp = (float)(t/101)*180;
6 l& z5 ^) C9 {+ `- j+ X. qpos[2][0] = (10-num+i)*50+x+650;7 N' v8 A% L* b. P4 k8 {
pos[2][1] = y+630-(int)temp;2 a. j- c/ v) n: f2 E5 g. H* I( F8 G8 ?
}* O5 L6 w6 K+ D7 y, y( {: s
clearrectangle(x,y,x+1200,y+650);
' g0 ]7 O- J, ^4 H5 U+ u6 Ssettextstyle(40, 20, _T("楷体"));
+ Z! l8 e& E9 T8 E% Vouttextxy(x+50,y+50,"FCFS");. b# V: }1 D( _& _: L
outtextxy(x+280,y+20,"CPU");       //画柱状图1 c4 N/ W: O! h
outtextxy(x+285,y+20+200,"IO");
9 K0 V; q2 v( l$ wouttextxy(x+250,y+20+400,"change");
) T4 r, g2 d7 n' W5 `6 V" j, Wrectangle(x+270,y+65,x+330,y+215);' Y6 {; Y" }! O/ H. C
rectangle(x+270,y+265,x+330,y+415);9 i" Z- |; @$ z
rectangle(x+270,y+465,x+330,y+615);
3 m% g" G- ]' N6 B4 a$ I$ z3 f# g0 R+ Zouttextxy(x+290,y+620,"TT");
) u: c. v" N1 Y( W7 f! rt = (float)com;
8 z2 [2 \& ~: R! ?3 K! ^. u, W/ Rtemp=(t/101)*150;; w7 j0 a# v: Z4 t  S
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
; E- O. x4 K9 b. g3 ~& Jt = (float)wai;
8 @& P( H# V4 T2 j2 l# S- Ytemp=(t/101)*150;; S. S. J9 I3 }' `1 b
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
# D5 `2 _4 V$ bt = (float)cha;- m% M$ x( S8 n1 F  m2 Z: r+ G
temp=(t/101)*150;& c0 \( \& k' `. t" @0 n6 r/ p3 [
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);& q/ C1 K! J% T$ G" C! z
for(i=0; i<3; i++)   //画坐标   high=90,length=2504 C4 i( ]& J8 _  _9 \# }9 ~0 ~
{
6 n5 q: s( ]6 i" _( p1 \7 uline(x+650,y+210+210*i,x+1150,y+210+210*i);
$ {3 L! f' T- ~line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);! h; }  d& i* R, ]9 u
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);* h* d5 S; U$ h8 Z" d0 q

3 R0 Z! q0 P9 e, Cline(x+650,y+210+210*i,x+650,y+20+210*i);
" A$ ]9 c) f+ m4 |, cline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
# t3 u! h3 b) Q7 Eline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);  w* U1 S; A# k
for(j=0;j<num-1;j++)3 f- H5 q/ J; X' ?; z, s, a
{
: J* H3 T+ x! i! c0 t/ E5 h6 iline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# ^/ R4 }, E9 b) ?line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);( A8 V) b" M. N( o3 ~+ U) P
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 8 w8 o9 g1 k1 K
}
2 d! z) H1 Q* O. J" |}$ z  i+ _8 l3 ]2 p3 l/ K
}
+ H, `1 z8 x& r+ q9 g, s6 L/ A
% E  A3 \0 l) l$ Q6 g8 f0 ]1 `) x/ c) \- X; w
return 0;
3 Z4 \7 o% T; I7 ^- R, b}) `/ p$ D% x. w8 d8 H$ s
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
+ U/ @6 x% P7 ~/ J" U{
; j; d4 k: E. ~4 V9 {' N/ Z8 M" B4 Qstatic int info[11][3],num=0;
' ^# B5 }/ e5 @  V0 f, N" @9 Qint i=0,j=0,pos[10][3][2];* E) }( U% T3 N* J8 J
float temp,t;( F; V, ]; e3 G
info[num][0] = com;: Z. P9 f3 }0 y7 s5 s3 B1 k/ E
info[num][1] = wai;' Z3 X) C, \# n, R; O7 A) D2 {
info[num++][2] = cha;$ e3 u1 S# h) o) s! R( {3 o- T) ~
if(num>10)  //存储10个点5 j1 I* U2 i( g
{
* q, v) o9 `! g2 N1 l$ kfor(i=0 ;i<10;i++)8 q5 T1 E* m0 M/ q3 {; j5 T
{
) E6 u9 R# @3 d6 j; rinfo[0] = info[i+1][0];. _5 `5 w: J$ C( w( D2 P1 M
info[1] = info[i+1][1];! J2 {( b! o  o& Y1 K
info[2] = info[i+1][2];7 t) X# w' q, l  u. W
}
4 |! }/ t3 b5 p/ J! J3 W' N0 N% N) V- onum--;
0 m3 j1 G3 I# J* a0 i3 @}5 B9 p" e  U( ~$ H; x
if(FLAG_show==0)3 M  a( N& o: |4 H5 C- p& i# o
return 0;
5 l/ l/ h$ v& ]7 r. qfor(i=0; i<num; i++)! k# b6 A, E( a6 r
{
: w6 a; C& X* \1 ct = (float)info[0];9 r/ N8 q4 V# n2 P# ]# z8 P. i
temp = (t/101)*90;
2 v3 O! \. U+ w6 D8 _5 k* @pos[0][0] = (10-num+i)*25+x+100;
2 Z; O4 m' I3 c% c, ~7 B3 d. o, Z% ?pos[0][1] = y+110-(int)temp;
4 x. @1 _7 o+ K6 Z' B9 rt = (float)info[1];3 Y' N% s6 ]  c5 G5 F3 @
temp = (t/101)*90;
: S. j  i5 w( H& w4 |+ h0 E! }# Bpos[1][0] = (10-num+i)*25+x+100;
- J7 Z. Q2 Z9 M) spos[1][1] = y+210-(int)temp;8 a" W4 T1 D5 ~
t = (float)info[2];: j7 R: G2 }3 }
temp = (float)(t/101)*90;3 c; n2 K! y! |6 W$ O
pos[2][0] = (10-num+i)*25+x+100;
, l1 Y& `$ A6 Y6 V% o. ^pos[2][1] = y+310-(int)temp;: v' m3 q/ f' G, P" |& ~
}
& p# ]* k* h) u6 ^4 O3 I$ bif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)9 f, ?) Y2 L% S' A
{
2 A) H& \' `: R0 b) c- G+ Cclearrectangle(x,y,x+400,y+315);2 |7 d% V0 q( w% ?) Y
settextstyle(20, 10, _T("楷体"));
" G( y' @2 J! g$ u0 \rectangle(x,y,x+400,y+325);1 a/ Z- t8 ?4 a' z
outtextxy(x+40,y+10,"CPU");       //画柱状图- w* ^7 }! b' c7 W* X* L: r
outtextxy(x+45,y+10+100,"IO");
3 c* w5 B% ^4 xouttextxy(x+40-15,y+10+200,"change");( o/ h- t2 d& j$ \3 |8 A2 v
rectangle(x+35,y+30,x+75,y+110);5 z, Q6 d: i3 A6 _8 ?/ B$ A
rectangle(x+35,y+130,x+75,y+210);
$ i( Z/ e4 V0 b2 z2 K; y( hrectangle(x+35,y+230,x+75,y+310);! W0 g; }- {( U& q6 s: x
outtextxy(x+180,y+310,"HR");
, @) d+ v- F3 f) w; ot = (float)com;
  Y  Z6 F1 ]6 F! s  @& O* w1 Jtemp=(t/101)*80;1 Y. f. S: x) \' `$ u8 [% J: G
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);4 l) j$ E4 X1 w9 z0 Q# V6 }
t = (float)wai;
8 i: Y( z' q2 X+ [6 Q# O, |" |temp=(t/101)*80;
' F- e  r( f2 b# i1 q& A# `fillrectangle(x+35,y+210-(int)temp,x+75,y+210);5 L0 O: B* ^8 u2 t5 k5 b# ]
t = (float)cha;
2 t! P3 I& ^7 [  P$ {7 _/ Atemp=(t/101)*80;: F9 Q6 {: W. M
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
; q0 P/ x* G. S5 G6 jfor(i=0; i<3; i++)   //画坐标   high=90,length=250" B* U6 a0 d1 z7 E9 V
{
" @: |. ~8 j9 M" bline(x+100,y+110+100*i,x+350,y+110+100*i);* ?* o  f6 C- n% H9 |/ [
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);) B7 N) @6 L$ Z" f4 b; k
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);* s7 X+ @" P2 [( ]* Z! i
- l7 N1 E  z3 p- w# l
line(x+100,y+110+100*i,x+100,y+20+100*i);' _5 P2 H3 J+ `, }
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
0 N' B0 }$ w5 t/ Q7 q- p& z+ G4 k" p2 ~line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);7 p& ^- p9 \4 I- Z! l) ~
for(j=0;j<num-1;j++)* R. z% |& s6 G+ s1 e
{
/ a  y) Y/ x7 t" }3 V, `line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
: b/ X" G5 ?. `3 aline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
. t5 C3 X( V  ?, x7 z5 ^7 xline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
: ?' a0 t: L/ J: s8 J}" R) D! i4 t( S  }% {* B
}( {2 D% F6 S0 ^! l. X0 V
}
6 f" f" G# D: x- |6 ]5 `else if(FLAG_HR==1)
5 W6 c8 ?( ?' z9 \5 U+ A- G4 q# d{
* F) j  J4 J5 a, ~% M* A9 xx=0,y=0;! A: B( H# A$ C' ?+ C% q4 X
for(i=0; i<num; i++)
* Z: i. h4 H- _: v{0 \2 P# B8 ^( X/ W
t = (float)info[0];$ z# V) o* ~, b6 l6 P
temp = (t/101)*180;
7 R8 q4 `5 p& {( R" E- z2 ypos[0][0] = (10-num+i)*50+x+650;
: W$ _: f. z& g; o! Qpos[0][1] = y+210-(int)temp;
! v1 Y; i/ v2 ^( M7 o$ Rt = (float)info[1];
7 }) K8 c) b* _4 rtemp = (t/101)*180;
! i9 R, l9 R9 p3 Rpos[1][0] = (10-num+i)*50+x+650;' c6 D+ V8 C0 ^
pos[1][1] = y+420-(int)temp;' t+ |- b8 n( ~; F3 G2 X
t = (float)info[2];
: w- E( T3 T/ n8 qtemp = (float)(t/101)*180;" @  i- [  M' H
pos[2][0] = (10-num+i)*50+x+650;5 J' M8 J3 B# _3 g3 p
pos[2][1] = y+630-(int)temp;
5 X% h9 s7 b: _( K; h7 G0 S  c- [}! v% Q! X0 A# `
clearrectangle(x,y,x+1200,y+650);
- ~2 Y' s" X# ~$ O" }1 B' qsettextstyle(40, 20, _T("楷体"));
3 X/ Q% x& i9 z  H9 L2 n$ p  Gouttextxy(x+50,y+50,"HR");# c0 U8 ?9 L3 {) V! N
outtextxy(x+280,y+20,"CPU");       //画柱状图% h. X  J$ ]7 a& Z6 C; M2 b
outtextxy(x+285,y+20+200,"IO");! {& ~. \# `: p, S
outtextxy(x+250,y+20+400,"change");
& @  T4 S+ o" Arectangle(x+270,y+65,x+330,y+215);
! Q7 L/ Q' w& W! R$ wrectangle(x+270,y+265,x+330,y+415);
8 j0 ^5 f2 Y7 X* W/ G; E$ i* [rectangle(x+270,y+465,x+330,y+615);
" s" L* N, O. p/ \outtextxy(x+290,y+620,"TT");1 D" v; n( j4 r# c" n
t = (float)com;  J2 ~6 R5 C$ U2 `( Y" h7 L
temp=(t/101)*150;6 I6 w1 m0 `# w8 Y* |/ T% q
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
. q# y  |+ E- \& Y0 ht = (float)wai;9 G/ D1 I! Y5 O8 D
temp=(t/101)*150;/ H, w4 q$ Z# c9 a
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
: h) }( _7 d6 e2 Wt = (float)cha;/ t! x* b/ h* L& _) o/ m
temp=(t/101)*150;
2 e  e9 o% u5 U) ifillrectangle(x+270,y+615-(int)temp,x+330,y+615);
+ W  k( ^4 I8 G4 r. D! Wfor(i=0; i<3; i++)   //画坐标   high=90,length=250
2 E+ X: [# c8 g  @. U7 ?( q) V$ P{
/ {# |6 h$ N4 a) qline(x+650,y+210+210*i,x+1150,y+210+210*i);
- ]. F; s; Q8 Uline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
1 G/ i1 ~6 a. X, i! e$ a! ^line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);+ X" t3 W5 O& F0 R& _9 r
' Y9 ^7 x% R! [% Y- q
line(x+650,y+210+210*i,x+650,y+20+210*i);
. Y1 {' u0 l/ e$ C7 C3 yline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);7 f; n% L% L3 |$ `* v3 S8 a
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);* H3 j  [) l% U  e" M
for(j=0;j<num-1;j++)! P' l/ Q. a, z/ l9 U0 Y" `1 V6 D
{5 |0 t6 Q) J! u' }
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);9 v1 ?! ], s( X' L  y+ J; C3 X
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);+ ~0 |5 d0 T9 a1 \* Z
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
5 ~$ s( s+ Q$ }2 A& B/ Q: s}
' u' p& }5 n8 [6 u/ T}
0 H: j& g7 W7 d8 d) J6 d}& E0 j6 N) Y6 `" r9 }
+ i6 S" `" w  i" B6 P
$ i' }1 G  e2 L4 Q/ x+ c- D6 {
return 0;
' B9 S& C; r; {}
- R+ B9 R4 d  F# Lint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
0 k* w! \  u- y. n7 O9 n  n3 J2 {& s{
6 [- M! }3 P; R; \. S+ F5 Zstatic int info[11][3],num=0;
1 i9 D: W$ y+ b. Y/ {int i=0,j=0,pos[10][3][2];
* j( m6 ?6 Q0 P3 y0 Z+ Gfloat temp,t;; }( Y8 [, r/ }; x
info[num][0] = com;
' d; z: o) ]3 W, B9 q" {  m" d# f$ Vinfo[num][1] = wai;
3 m! \$ V  }% t/ z) T. e0 n1 ainfo[num++][2] = cha;" C& y; a+ J( Y& v$ j/ Q0 H4 H
if(num>10)  //存储10个点
) q2 F: d: a, P{
( {/ i$ C& f6 i8 q8 hfor(i=0 ;i<10;i++); m9 O) j2 L+ S) m* y: H
{
3 |/ V4 k8 D- Cinfo[0] = info[i+1][0];
3 b+ j% Z+ n! p1 x% a- j( _info[1] = info[i+1][1];5 \) D0 g( H" I' D9 I! z2 l2 t
info[2] = info[i+1][2];
8 R* m6 t$ n4 E0 X4 o}6 r: O/ F: \2 f
num--;) w" }6 J4 q$ o% [
}! J* [2 r6 R& _) V4 f) a
if(FLAG_show==0)4 n& b3 `. i- s8 N/ Z& F
return 0;
6 G  }5 b/ H  e+ ^! Hfor(i=0; i<num; i++)
# {' {. ^) y# t{9 |: h1 e$ v. e2 x' o- ^
t = (float)info[0];
* H$ r, M2 ?/ L& ]- htemp = (t/101)*90;% s! y" `, u+ v% K5 t
pos[0][0] = (10-num+i)*25+x+100;
. y! ]( o9 P# `/ _pos[0][1] = y+110-(int)temp;& D8 `' D! h& h4 X2 S4 S
t = (float)info[1];" k; w9 n' E$ z; H$ f/ O
temp = (t/101)*90;
5 K! `4 F5 G: Cpos[1][0] = (10-num+i)*25+x+100;
: S) A1 X$ C9 v* Z8 ]7 W0 W( Zpos[1][1] = y+210-(int)temp;5 {! g, H: J1 v/ t# {: I, q8 d9 s/ m9 ~4 g
t = (float)info[2];
+ F1 ^+ @8 w3 U( ^* k8 s* wtemp = (float)(t/101)*90;; h% q+ B$ @9 n1 s# E4 ?
pos[2][0] = (10-num+i)*25+x+100;
9 x; P5 K1 V) h+ tpos[2][1] = y+310-(int)temp;
3 N. _  g+ l7 ]5 c0 W1 u" y4 j9 s}
- T( w, |/ ^3 O2 C* aif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
) V5 M. e7 L+ a! N{# k1 U; n" D8 A8 b* c/ O$ O. N
clearrectangle(x,y,x+400,y+315);2 R3 f6 E- p, b' D7 G
settextstyle(20, 10, _T("楷体"));3 t  y) Y# c; a3 q' c
rectangle(x,y,x+400,y+325);
6 ^, H# F6 k3 k- T6 A, H. K1 k. Mouttextxy(x+40,y+10,"CPU");       //画柱状图
; [) p5 C6 x* `* c8 f$ y2 ~5 u) N# couttextxy(x+45,y+10+100,"IO");
2 k6 h# R0 w" p  U4 t5 J* Souttextxy(x+40-15,y+10+200,"change");0 @; V3 p) u; o7 z7 u) i! L
rectangle(x+35,y+30,x+75,y+110);
: i* W; J3 S- ^, H6 v9 Q* T' ]5 Yrectangle(x+35,y+130,x+75,y+210);" f; R9 J3 e! ^& H$ r
rectangle(x+35,y+230,x+75,y+310);+ Z- c7 ?' C! F$ X
outtextxy(x+180,y+310,"TT");
! X# z2 ~5 |: `6 ?/ \, P4 }t = (float)com;4 l7 m! W+ e" A% b4 Z& A
temp=(t/101)*80;
9 ~5 f5 F6 B% E- W% e6 ^1 q* Efillrectangle(x+35,y+110-(int)temp,x+75,y+110);
( _; Z3 C; v, _, ft = (float)wai;
1 i8 p2 U, x3 M& P3 I4 u/ b) Ntemp=(t/101)*80;
- r; v8 }+ [% M: [/ Jfillrectangle(x+35,y+210-(int)temp,x+75,y+210);! z4 M% d' q: G/ V
t = (float)cha;. s. Z' E9 V9 X" A
temp=(t/101)*80;
0 g* x; S7 i8 b+ [fillrectangle(x+35,y+310-(int)temp,x+75,y+310);3 Y6 x5 T2 w6 A( b7 k# W' `( |
for(i=0; i<3; i++)   //画坐标   high=90,length=2507 S( D" f$ g* x, g2 E9 k
{
8 R6 k( J2 K& J+ Y- wline(x+100,y+110+100*i,x+350,y+110+100*i);2 i; F! |  a$ G9 x& s
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);2 @# d- g7 S( l! Q1 q
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);% _6 o+ ~: m+ j
$ ]2 L6 M- |: n5 c7 e
line(x+100,y+110+100*i,x+100,y+20+100*i);
( c# a, s6 H1 W$ t& Oline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);2 J( t# j2 ^9 j  T9 b" _/ @
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
- g( P4 q3 I3 nfor(j=0;j<num-1;j++)$ a  J* R1 b  b! F& r; d
{
1 Q& C: u* T! ?# Pline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);: ]0 f$ g; {4 ]+ {+ A. ]7 d
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
+ v) A, V- g& i! Z* `' r7 g( e/ Yline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ' P5 c3 }+ \8 G4 @$ ~
}
" I5 c" E' Y* [+ d% r: m4 X}
) f# u. ]! o4 _6 q7 S) B}* ^+ k2 l% ]2 o' G- p1 o; U' C3 G
else if(FLAG_TT==1)
' ^# @' V$ [8 K* ?0 `{% U) W/ ?: S, r- x0 w( O' x, w
x=0,y=0;
; p( R3 ]! N2 K" w) Zfor(i=0; i<num; i++)
# R5 c5 X0 h  J' K4 E{
, W  G. v7 H% v) d$ c! Ht = (float)info[0];# j9 p) \( W: F* }3 l3 ^6 g
temp = (t/101)*180;) c4 y! z. M; _- R4 F1 v: a
pos[0][0] = (10-num+i)*50+x+650;- i- ?  x1 J# V. H# g6 I. X4 L
pos[0][1] = y+210-(int)temp;
2 _' ]1 ^' ?5 D% n1 \+ }  ot = (float)info[1];
; m0 [8 C  B* H3 ntemp = (t/101)*180;/ f: ?& X  ]: F3 H$ O6 Z7 \; z. e
pos[1][0] = (10-num+i)*50+x+650;* \& Y* e- w  D
pos[1][1] = y+420-(int)temp;: p$ M8 x6 l9 n4 ~' E
t = (float)info[2];8 q; Z! y$ r# X6 `& T
temp = (float)(t/101)*180;
1 v( e$ X& M- y6 ]5 `% gpos[2][0] = (10-num+i)*50+x+650;
7 ?: v4 m' S9 ]pos[2][1] = y+630-(int)temp;/ P( W  N" Z# ]6 K8 i% D: V
}7 E1 x* d+ L7 \" L) e7 G
clearrectangle(x,y,x+1200,y+650);5 u, c) [2 |% k1 T3 {  E
settextstyle(40, 20, _T("楷体"));* v2 f5 ]6 P  L5 A2 s3 p* k
outtextxy(x+50,y+50,"TT");+ U: Q+ N2 v8 u9 L+ u( V4 Q# P
outtextxy(x+280,y+20,"CPU");       //画柱状图
2 U% \7 z0 Y9 oouttextxy(x+285,y+20+200,"IO");3 [- G% @0 B; _* T) s
outtextxy(x+250,y+20+400,"change");
) F/ r5 n% S/ i# M" G4 v/ yrectangle(x+270,y+65,x+330,y+215);
2 s9 v0 r6 ^9 X6 Y! f" A2 krectangle(x+270,y+265,x+330,y+415);
& g) A0 Y% A' \# a5 V8 Krectangle(x+270,y+465,x+330,y+615);
, ~  @. M- A* J! u" G4 }1 y4 Kouttextxy(x+290,y+620,"TT");/ i0 J; u' o( h% ^! C
t = (float)com;! A2 u6 I9 O( X2 t" D
temp=(t/101)*150;
$ w( L8 `  L- \& o" y, K( C& Ofillrectangle(x+270,y+215-(int)temp,x+330,y+215);+ Q- G% E- T+ _. d8 q
t = (float)wai;
- w- {" ]* c3 q# Atemp=(t/101)*150;
6 ?# e* b1 E6 s8 l$ Cfillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 W5 E9 `: j- r- l- t9 j/ ?
t = (float)cha;- g* K/ a8 Z. `" Y% Y7 w
temp=(t/101)*150;
1 K1 z* X, F5 bfillrectangle(x+270,y+615-(int)temp,x+330,y+615);, K8 s, H3 R9 j. w
for(i=0; i<3; i++)   //画坐标   high=90,length=250
" A  a$ L+ Q8 f' G& d9 P' {& c" D9 I{' I, h3 O$ Y- ^
line(x+650,y+210+210*i,x+1150,y+210+210*i);
  z, z& ^* E1 q4 b" p9 z0 ?line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
; M: y' S( s5 X- |3 z3 xline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
, k) d/ ~8 v5 ]3 k6 C3 I" B" z/ m+ P4 ^8 [9 p! V% h9 V
line(x+650,y+210+210*i,x+650,y+20+210*i);
8 i8 f8 M+ ?; q0 _0 b) \) J+ m8 i$ zline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);% {- |( `5 e) ?) T5 C: M/ V
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);% n( B. S  m1 v9 y+ Y7 x) a- i( F
for(j=0;j<num-1;j++)8 H) p( @% z& ^# A, d
{( X9 W. O1 Z2 b4 U9 ]
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);9 M4 [: h& e& I1 u5 I9 U% X  P
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);* F' ^! {8 }, p: D0 @' k2 L
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% H- ^/ {$ ^$ A) ~}
8 n! }! w: h, O1 R7 i$ V}; z: }- j* e5 D4 t: n! p+ |
}
5 D4 o. H" J6 T7 @7 k1 F2 R: G9 E& V# s0 s) l

, _1 X9 A' {8 j8 t' n4 \return 0;
' Y/ O5 o9 A: a& a9 ^, X- i}( i9 u0 @8 k, |% V! J' q% f5 c4 L) B
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)7 Z# \* T0 v, a* B
{
; V6 e& I/ U! o6 ^static int info[11][3],num=0;
3 w. e( X- p1 R: j4 Cint i=0,j=0,pos[10][3][2];
3 c7 ~/ `" Y# P) i4 x- z" }- [! Cfloat temp,t;
* l% j6 ^8 r; e2 l$ t7 o2 @8 pinfo[num][0] = com;
% f0 c/ N0 o+ S1 h+ C( iinfo[num][1] = wai;; h1 t: N( F  u
info[num++][2] = cha;
1 \5 d8 m* z  P8 `$ Xif(num>10)  //存储10个点
8 Q/ F$ y* `6 m6 S% k* R{
# i: u0 v3 n8 P2 R8 hfor(i=0 ;i<10;i++)
  {; E$ e. H7 O) B- Z4 m0 d$ g* z{  V& Q8 P8 |5 V
info[0] = info[i+1][0];
0 [. g5 o8 ]. i! linfo[1] = info[i+1][1];
/ ^6 D# _6 H7 p/ D" j7 u- d  q  Kinfo[2] = info[i+1][2];/ u4 ~8 o5 b4 M$ H! P8 x
}3 d: X+ ]7 _3 o- j  A# l+ q
num--;4 `9 e8 J! d3 L% R' J% Y4 q
}6 ?2 ^3 g4 M2 j; ]% K
if(FLAG_show==0)
4 i! @) n1 @6 D  }return 0;# S$ ^+ n) I; V% s2 ]: I
for(i=0; i<num; i++)
8 l$ o5 D( W% Z/ r4 [- |{
2 @' ^8 V; @3 C. b% Wt = (float)info[0];. e" Y" }& ~) Q
temp = (t/101)*90;
& R8 M9 n" Q( u9 ppos[0][0] = (10-num+i)*25+x+100;
8 ^1 P1 H( E+ Xpos[0][1] = y+110-(int)temp;( t  ]4 Q- \  D" W( U  R- Q  @
t = (float)info[1];- B0 q; G9 a$ j" s0 O: I
temp = (t/101)*90;
% h# u* r8 Y4 hpos[1][0] = (10-num+i)*25+x+100;' J  |' v0 g) I. V: N" j$ D3 J
pos[1][1] = y+210-(int)temp;
' U: y# h7 L4 _, t2 {+ i+ e9 ht = (float)info[2];
5 x1 ~- D# u. v" Ftemp = (float)(t/101)*90;
. B2 O6 S# w% s& ^6 G, h# N! ^pos[2][0] = (10-num+i)*25+x+100;! J+ ]' }4 w" f! D# i3 b
pos[2][1] = y+310-(int)temp;: V2 P. Y; h9 l$ Y2 O  C
}
2 E: E! d9 v6 r9 H% Aif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
# `/ {) e, {3 ?' J4 f+ _$ ^+ |{
8 A0 a/ v: `& K- T% ?clearrectangle(x,y,x+400,y+315);
; g9 k- h+ t3 }2 {9 ]4 nsettextstyle(20, 10, _T("楷体"));
. c! t" I3 Y* J4 U, f- trectangle(x,y,x+400,y+325);7 ?" F7 d) ^3 v( T
outtextxy(x+40,y+10,"CPU");       //画柱状图
2 K, p4 I" I4 u; Youttextxy(x+45,y+10+100,"IO");
$ U$ i1 u+ _6 {! n8 routtextxy(x+40-15,y+10+200,"change");
% h7 \) r, O) _1 x2 }. Prectangle(x+35,y+30,x+75,y+110);
0 L- r& m* y: e, P# c( ]! o8 ~- trectangle(x+35,y+130,x+75,y+210);# _6 U" U. U, f
rectangle(x+35,y+230,x+75,y+310);+ W6 _4 V8 ^7 L% {. U
outtextxy(x+180,y+310,"PF");" _& G: K7 O. f  M
t = (float)com;( z  \) o- {8 z/ X
temp=(t/101)*80;
  x+ d' g) F: y. F0 @3 Kfillrectangle(x+35,y+110-(int)temp,x+75,y+110);* w# F+ W5 Z3 t! U2 D
t = (float)wai;1 a9 n" v5 D. l: ]) j; ]
temp=(t/101)*80;
7 z0 S4 x4 c/ t3 U- Cfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
- \4 L9 G! v! {t = (float)cha;
' c3 G6 C5 B  a# \  |temp=(t/101)*80;
7 j# a7 l, }! h8 n$ h6 Ufillrectangle(x+35,y+310-(int)temp,x+75,y+310);/ }: ^/ D5 G  \% c/ Y! ~7 m
for(i=0; i<3; i++)   //画坐标   high=90,length=250% A% q2 ]& W. j1 h7 U
{6 C. ~0 A! j! |' m) e" [1 z0 A
line(x+100,y+110+100*i,x+350,y+110+100*i);4 t, c3 a5 R9 P5 N" D6 N
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
8 c4 b7 D6 `" H0 N! s) a" U+ j7 ~% Xline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
% C4 ]: T. v6 w
9 |% Q9 F' o& ?# }# q# w3 @line(x+100,y+110+100*i,x+100,y+20+100*i);
7 K1 y0 U/ r+ l3 l) \line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
6 z  A7 t0 B, ~( }1 }, i9 Pline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
, Y8 D, w7 V' ?* F; t- sfor(j=0;j<num-1;j++)
! M3 E, m/ t- n+ _' V{2 i* g7 ^! q; p1 X# K) n3 R, z
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
/ l" g* U, i0 I2 ^4 |5 o& |line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);# M7 o* n( ~8 y$ w9 m
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 J) R0 Z; ]' @6 \6 |( Y( C3 L: w}
- G8 A# R( Q4 S, B* s9 |}
& g! f) {0 V2 i4 O+ L$ H  m}- b0 X, w7 g& P  r/ B+ n
else if(FLAG_PF==1)6 k) [+ u6 [. f3 U0 `+ R
{
, e  P  q- ]4 y- y% Y% t# {/ jx=0,y=0;% m& u8 k7 o, N
for(i=0; i<num; i++)
# G; ~! p' q9 N. e* i3 k5 a{
8 ]7 |( j1 u& E1 }t = (float)info[0];
/ Y' b0 |4 P' y2 etemp = (t/101)*180;
2 y' _& w& Q; D- upos[0][0] = (10-num+i)*50+x+650;; ^8 k* e" e$ |# g  V
pos[0][1] = y+210-(int)temp;+ T* \3 w  b. h$ E! n
t = (float)info[1];4 X* c8 I8 v' ~2 Y1 P- \6 Y
temp = (t/101)*180;0 I" g5 t- I4 U+ h9 f3 ]9 |
pos[1][0] = (10-num+i)*50+x+650;
, S, N6 p. Z. `. @pos[1][1] = y+420-(int)temp;
% B, |* P' i2 st = (float)info[2];
4 V4 _' E( N; i1 ]temp = (float)(t/101)*180;/ c! G# u3 c- P/ k: S2 ]- N
pos[2][0] = (10-num+i)*50+x+650;3 Z0 X5 y8 K5 F/ w8 v* v% g
pos[2][1] = y+630-(int)temp;
. z# Y  I- D2 t( ]}9 C$ s# c4 x1 e0 H6 Y& K
clearrectangle(x,y,x+1200,y+650);
; ~" X$ w- r7 z' O1 r2 ]- Psettextstyle(40, 20, _T("楷体"));
3 b; X/ F" g$ ?1 y, Y7 I: ~outtextxy(x+50,y+50,"PF");2 M5 g% w. ~- D0 U; ^0 h" M
outtextxy(x+280,y+20,"CPU");       //画柱状图) u/ _3 s  g; [( x: r5 R4 f
outtextxy(x+285,y+20+200,"IO");
; @$ @+ N3 p1 v% g8 L3 ]* |* ?outtextxy(x+250,y+20+400,"change");
' X+ u& E: X  Prectangle(x+270,y+65,x+330,y+215);
% ]$ T+ L, H) W& I. Hrectangle(x+270,y+265,x+330,y+415);
# D/ p: k1 l5 _! ~- arectangle(x+270,y+465,x+330,y+615);8 }4 `: G. v/ v: j
outtextxy(x+290,y+620,"TT");2 R1 v3 N* S5 j/ G  G
t = (float)com;
9 T9 f1 w9 K& j: Q( htemp=(t/101)*150;; d5 X' \( L' |- s( P
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);3 |4 W" \- N6 F/ m( S0 I7 B4 ~
t = (float)wai;
, M7 y, B3 k0 u' G! ftemp=(t/101)*150;2 [, o$ B: f' h* J) q0 U  v! H
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 I- z& F- C6 I0 o7 Q3 i* N
t = (float)cha;
6 `0 b; |; i; y( r' {# @temp=(t/101)*150;+ H4 Y& r' Z& x6 C- I( S
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
8 }: M, Y3 g! ?2 i3 I7 ofor(i=0; i<3; i++)   //画坐标   high=90,length=250" }9 }4 u% E! k! ?0 m+ O. p
{
! I! A% a( a) |, p/ yline(x+650,y+210+210*i,x+1150,y+210+210*i);! }- ?3 S1 n5 Y' p" h
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);4 }" d$ {( ]' b, ]) X
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);/ x( X0 M" d% ]( r! `2 v6 w

+ P  G* t$ Q/ ~8 y# k: o8 z: Pline(x+650,y+210+210*i,x+650,y+20+210*i);
0 ?2 }0 o7 q6 Zline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
( O8 V4 I# h7 h: S* y8 s8 Mline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
2 Y0 y% T, x3 K; |for(j=0;j<num-1;j++)
: @& e  K4 J" S{! d  E7 E3 q0 q- w# g/ i! k2 `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% ~0 W- P/ [% r4 f
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! I2 ?* ?) W8 F: Jline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 8 J+ g9 r' V9 @! g% [3 m4 z& T
}3 d) F7 j4 m, v# `" h
}
) X" A, [8 [  v1 n* {}
- i, H  R6 K7 I1 F+ Creturn 0;. Q- o. q" U4 ^( w1 X- u
}! Y7 N# n# X1 s9 ?% G8 L3 z6 d
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
. }( P& n; A1 m( i{! ^: C9 \* }& E$ k5 F! G, v/ V
static int info[11][3],num=0;
8 c" g% Q( h. ?2 B4 g1 u8 `) o, Xint i=0,j=0,pos[10][3][2];4 Q# a3 i) z/ h
float temp,t;
. J2 j. y1 D- x  T7 {7 Vinfo[num][0] = com;
: o8 Z# r8 ~) r) iinfo[num][1] = wai;
/ m# _; L2 i" `4 j8 T3 n" dinfo[num++][2] = cha;* [! }4 P& d6 k) E  @+ `
if(num>10)  //存储10个点
* \, x5 W/ Y" {( h{
' s& R- X5 s: B7 yfor(i=0 ;i<10;i++)
" u8 O1 _' ~! Q6 V' _) L{" Z9 Y4 s$ q9 ~
info[0] = info[i+1][0];+ x4 A6 r1 p, S2 ?
info[1] = info[i+1][1];& H) h$ {; n/ b  u/ C, ~! g
info[2] = info[i+1][2];! b( o- ]' M7 j
}6 t, L5 _: s5 _$ D7 g9 {/ }* }
num--;' G$ L3 u& C( e- m, y
}
* A$ W2 a( N2 t# Oif(FLAG_show==0)
1 z" [6 ^1 E1 o# d; g2 W  Oreturn 0;" c/ |2 m$ `; {- d1 N$ E
for(i=0; i<num; i++)
' v' W- X- J( O  y{
/ ^" y0 Z, x5 Z; \t = (float)info[0];" O& c5 A5 M5 S. ]- B
temp = (t/101)*90;
0 L& m; e$ _0 e, g1 Z1 Z/ F) Gpos[0][0] = (10-num+i)*25+x+100;3 F) Y3 v6 _* i) k
pos[0][1] = y+110-(int)temp;5 ^+ \7 U  e( `$ h* S) ~
t = (float)info[1];
& \8 k6 W! c$ _/ |7 atemp = (t/101)*90;) _+ E7 ]2 O3 ~4 H
pos[1][0] = (10-num+i)*25+x+100;
4 Y. d9 {3 M2 j8 Epos[1][1] = y+210-(int)temp;
1 C, x3 W2 |+ ]! Ot = (float)info[2];9 z* f7 j6 w! i. N
temp = (float)(t/101)*90;% V9 ]: J( F# x5 A
pos[2][0] = (10-num+i)*25+x+100;
$ @# p' V  e. H  |pos[2][1] = y+310-(int)temp;
0 ]# C) r+ C! K; R3 C, J6 k}, ~$ j7 ?- z0 |' p  N7 S
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
6 D# R) z+ l# X& L- O8 T{ 2 d" y1 l( I4 p2 f7 J0 A8 H% v
clearrectangle(x,y,x+400,y+315);
+ t! F/ X/ u# a* s9 wsettextstyle(20, 10, _T("楷体"));9 t6 \% [" N3 _; q( K3 k6 P
rectangle(x,y,x+400,y+325);
1 n' @* \; u( n7 R( ]- T% V3 c9 h, Bouttextxy(x+40,y+10,"CPU");       //画柱状图
* P) m! @3 b; v+ Bouttextxy(x+45,y+10+100,"IO");
5 w, ?" F& ]! r6 P+ jouttextxy(x+40-15,y+10+200,"change");, Y- {3 Z& s  M8 s8 y
rectangle(x+35,y+30,x+75,y+110);
: D& g2 i: C' L6 m% i% Xrectangle(x+35,y+130,x+75,y+210);
( m$ u7 ]- t# z* l& r6 E' Vrectangle(x+35,y+230,x+75,y+310);. g- k$ f  }8 V8 i
outtextxy(x+180,y+310,"SJF");& u; I& o9 K, ?
t = (float)com;9 A0 K; p4 D3 b1 M- R: b0 n
temp=(t/101)*80;
; |9 |! l* R5 t, `. l# m4 N' ~$ kfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
2 j; s4 q6 v) I# R$ W: r% [3 Pt = (float)wai;$ y" F, y3 ^6 E: E" F" `
temp=(t/101)*80;) i2 j/ f- }: C9 n1 M0 S
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);+ L" ^" n7 c( g1 q
t = (float)cha;
$ ^6 m3 {! m+ p6 ^& _temp=(t/101)*80;
. W. D- X( r4 h6 r5 G& Jfillrectangle(x+35,y+310-(int)temp,x+75,y+310);* b* o# z- m1 s
for(i=0; i<3; i++)   //画坐标   high=90,length=250  J5 h1 g" y! a3 B) f# c
{0 I2 |1 v% w& j7 r+ p0 e
line(x+100,y+110+100*i,x+350,y+110+100*i);
4 z7 v) D+ \& h. z7 x; @% Rline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);# Q5 i+ W# r" y9 U8 P  s
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);3 V  q6 w' o8 t7 C$ D+ b; z

( s4 U- Z3 v: U& Dline(x+100,y+110+100*i,x+100,y+20+100*i);* }* m" O$ T, C5 D5 _$ \% i
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);& n8 `. y) S% @5 P$ {
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);8 q1 J8 P" _3 L5 `0 w# l
for(j=0;j<num-1;j++)! Z  p* p" _' w5 D: H
{4 U3 X* d8 ~) B/ O7 D
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);5 O6 l6 c  @( s7 p$ l
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' c  }0 X& B+ K1 j# c" s9 mline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
; X, W# q! K5 }  C5 f}
0 ~- g- U1 q$ l9 b}
5 s: R+ C3 Q; n$ L8 w, o}( ?1 z2 }- n+ C* k, W/ N4 E% z( o- B
else if(FLAG_SJF==1)
$ j/ w- U/ ^4 F! I! ^$ `{
+ }! u" K0 Z2 S# K4 P) bx=0,y=0;
  @9 A7 b3 j$ F$ Ifor(i=0; i<num; i++)
$ }) D* |' k( U" G7 _{
; w2 l0 O/ U1 E6 Xt = (float)info[0];
- e) H) ]9 {0 F, N$ x( F! Ztemp = (t/101)*180;
1 |. D% p, d' m6 _2 B0 r9 L! C- L" Hpos[0][0] = (10-num+i)*50+x+650;) x/ J. X/ F+ d% q5 f, ]
pos[0][1] = y+210-(int)temp;: \+ p! k; I7 _8 z5 n1 C
t = (float)info[1];
3 p6 W2 E" x& Ctemp = (t/101)*180;  ?# X! ~, @  \* R  ^' c
pos[1][0] = (10-num+i)*50+x+650;
9 V3 Y( U5 V1 [* `6 h) }; jpos[1][1] = y+420-(int)temp;
0 n( r' F/ v4 ^0 l$ d1 V! Mt = (float)info[2];
" [8 J$ P% r, u( ]temp = (float)(t/101)*180;- z; g) {1 ]/ m/ I
pos[2][0] = (10-num+i)*50+x+650;$ @! s% w3 B" Y3 Q: p
pos[2][1] = y+630-(int)temp;
2 y4 {6 K' D3 {/ i; a6 w6 o}
8 h/ w9 z/ N% V" u. @, c$ r4 xclearrectangle(x,y,x+1200,y+650);6 j) Q& v1 {: ^
settextstyle(40, 20, _T("楷体"));, n0 n% d: f4 Q, t4 L; V" X6 }
outtextxy(x+50,y+50,"SJF");
. O2 ^0 O2 p4 D4 z! E: zouttextxy(x+280,y+20,"CPU");       //画柱状图
4 u8 n) p9 o( ?outtextxy(x+285,y+20+200,"IO");1 w+ N* \& t& q8 Z3 x
outtextxy(x+250,y+20+400,"change");9 A& H! D+ Q/ F8 Q) E- P2 F
rectangle(x+270,y+65,x+330,y+215);$ {6 n) `4 X9 o* W2 r/ S
rectangle(x+270,y+265,x+330,y+415);
# @  N0 j+ R1 jrectangle(x+270,y+465,x+330,y+615);
7 J, z& }8 B; m  T3 n# }outtextxy(x+290,y+620,"TT");$ y2 t3 p( G; s6 ~8 l
t = (float)com;0 F/ O# j9 k7 }7 e6 Z2 @# T4 O
temp=(t/101)*150;
' N6 }8 D8 U/ b7 ?fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
) A  @! n$ [% It = (float)wai;9 y: q+ y% y9 O0 e$ d8 Y
temp=(t/101)*150;' u" ]1 f8 k+ f0 L! ]* i4 _4 ?; K( B
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);% \8 r6 e5 t$ ]- p
t = (float)cha;! ]: B( l4 l* ^, f
temp=(t/101)*150;
5 e; L5 `4 t  U0 g( Ufillrectangle(x+270,y+615-(int)temp,x+330,y+615);2 K: B& m2 C' ~7 w5 K; a
for(i=0; i<3; i++)   //画坐标   high=90,length=2503 y: q6 b" p. t
{3 k' r% _$ V% c% P) H
line(x+650,y+210+210*i,x+1150,y+210+210*i);
4 M; U/ Z) k+ z+ C; s( Xline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);, ^8 Q! g0 j0 L' N
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);- `: \1 d/ y. Q; x

9 v* Y1 e" }% C3 [line(x+650,y+210+210*i,x+650,y+20+210*i);9 y9 _( d  M7 l! K0 ?7 d
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);4 t0 ]" k" h5 u1 W
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);$ R( N, ?3 Q, L$ \
for(j=0;j<num-1;j++)" ^: G4 U9 [0 Y1 _9 U
{
- F  h. u- E) q0 jline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
9 V- s+ K) O( ]7 i/ Q& z4 ]line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
% T8 x; a" {1 \  ^) @, _line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
# p/ U* X4 A6 B( b* @" d! `( f. e1 F}: s$ J9 Q3 f2 a7 c
}
# I2 k( j0 b4 ^; b* F5 ?+ z5 w' T}
( w3 a- E, o- y2 U; e$ Sreturn 0;& A# o7 U+ u  f/ ~6 c
}
$ G6 z% B: G: {% [% Zint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw). W( m8 b) y$ N( W1 e5 u2 }
{
4 L7 B" ]3 s0 w6 B3 {5 e2 r# \static int compute=0,waitio=0,change=0;
0 w1 c& }3 }/ A) ?static int computeLast=0,waitioLast=0,changeLast=0;
  K% m: o: n& u) @' V8 X5 Lint i=0;8 ^8 k2 Y9 y( T; p: [" U: G
if(draw==1): Q: m, Z1 X+ d
{* ^8 \  m- V8 x7 r# I
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);6 m* _# e# ]0 }1 V. @8 _. K7 w
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
, g3 D2 L" S+ X6 C: n! W- x- P. ucomputeLast=compute;
9 @) B+ A7 F- Z  j1 @waitioLast=waitio;
) P$ |. ^3 S3 A, w1 Z+ p5 o$ ~6 uchangeLast=change;) f; b* ~/ A4 M: y/ O: A# x7 s7 F5 {
}
6 s4 S) U7 |8 \* @8 T2 jif((* memory).p[0].flag==ready)1 H1 [  x( o7 }7 o
(* memory).p[0].flag=computing;7 P4 |8 _9 V, g# I0 q* T
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)1 B$ l! I. E: ~5 |
{
% D$ J5 `* S# ~$ Li=(*memory).p[0].computeNum;9 y# _+ m: t. r
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed3 P9 e7 C* c  z' B
{
% S; n. B+ k, F6 j" u; r# `(*memory).p[0].flag=IO_waiting;
) @0 p- ]9 S6 s! L/ Z: y2 P(*memory).p[0].computeNum--;
9 V  a/ B: c/ h1 q6 x# p& Q- M; P# Lchange += exchange_IO_Compute;3 u! K' Z% b  X7 K9 {& ^
compute++;8 e; P, q' d3 `4 ~
}
5 k4 I8 X) F% P+ D1 H- ~) e% uelse2 E( C1 |. g4 M' d
{
! u" Y' h+ i8 U/ O* Ecompute++;9 `9 n% U) \. z
}" j1 x1 Z' {2 Q0 B) {$ [
}5 s/ i9 _* ~' @& G4 f7 ?5 P
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)' B/ o$ ~" \1 M* c
{0 U9 F; I9 s( V7 e& b4 ~; ~  J  v) }

( p* O1 A# [6 M1 C: s+ I7 \i=(*memory).p[0].ioNum;
# A" x5 A3 @  |( S* P% o* C! l* Uif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
& J! \( T8 b$ N1 h1 s" I1 z, i{
4 K; Q+ _: Y/ Y$ G% L7 l8 c) n0 F(*memory).p[0].flag=computing;
- _+ i- \/ a& R) D  P' L(*memory).p[0].ioNum--;
+ c. B' F! \5 |# R2 k# M/ hchange += exchange_IO_Compute;. T) p4 ]$ W4 ?
waitio++;% g' b8 ^& I1 f6 n) w
}! |/ @* ?% m- s
else" \1 s" s$ y% `; E0 ]5 R9 K
{8 M. i. h' ~2 N, t3 ^
waitio++;
8 L$ O" A, P8 \9 j1 d. f}
8 \6 C8 D* t5 @# W}
+ a* w$ I) ?0 v/ `0 N& F% a6 Pelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)7 f+ T4 Y& g/ \8 a
{
5 Z- g+ k# z) ^, e9 f9 _5 h* o(* memory).p[0].flag=IO_waiting;
6 j+ V# z) a. U/ P" r" qchange += exchange_IO_Compute;5 v; V% j; J; j' q, m$ c! X5 d/ x
}
1 l( y& M( e1 Telse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)& T" E1 ~/ R% o5 |6 i4 O
{9 R9 q" N+ I. b: o; ?5 N) g: M/ _9 M/ P: i
(* memory).p[0].flag=computing;! k( d$ g- U$ m2 |0 q+ e$ W
change += exchange_IO_Compute;2 l+ I" h% _1 L
}
% c% a( f# H* b4 C& [3 x# pif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成
! R2 y+ {/ K& g: F2 L$ I0 R. H{! k( w4 q4 w) P" E$ K+ S+ H' d
(*save) = (PCI*)malloc(sizeof(PCI));
% u& N2 u# H8 a4 h- X(*save)->next = NULL;
  ~, t% c& G8 J% p(*save)->processID = (*memory).p[0].processID;" B7 X1 v1 V" Y1 M" L
(*save)->comeingTime = (*memory).p[0].produceTime;
2 t% f" f2 U5 ]- y* x3 L. N/ }7 ^+ X(*save)->askMemory = (*memory).p[0].askMemory;- K% H- x% f/ _2 r# U
(*save)->compute = compute;' a7 Q9 B) b9 v/ S8 E& C. Y
(*save)->waitio = waitio;! R% I" z8 l8 w# r) l' \
(*save)->exchange = change;
6 U  H) Q7 r* E1 g+ g(*save)->completedTime = systemClock;5 V" ~# o3 i6 `1 H/ y
(*save)->runningTime = (*memory).p[0].runningTime;* k( m7 Q2 S) b5 i, I0 F0 _
*spareMemory = MAX_MEMORY;         //*spareMemory + (*memory).p[0].askMemory;* v% u8 M) \( A# T6 d, `
compute=waitio=change=0;
2 s/ K1 M% I+ f$ RcomputeLast=waitioLast=changeLast=0;
6 i: X3 N, T- D, iHigh_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
8 k2 O+ P  x& w2 [change += exchange_process;
" s8 t$ }  L1 J. p. b( treturn task_completed;
. X5 E$ f; [6 L1 `$ D2 M/ p9 X8 @}
. F8 ]) q0 p6 ~3 B* R2 f" welse: N6 a: b* s( m. y! M2 V  |) G
return task_not_completed;: {+ ?+ c/ F6 ^5 T. H7 c( a
}
8 }/ a4 u& _5 g2 M- u1 {int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
( R9 V) o) J/ L. v/ I: A- q{
4 w1 F% U  _1 wstatic int waitTime[initProcessNum],i=0,j=0;( s6 [8 q/ q6 s
static double HR_ratio[initProcessNum];+ `9 B1 E6 j! \) z2 Z' j+ ?% g; m
if(flag==0)                    //初始化数组. f( y8 y4 k; m
{
% L% S: a; q/ X" n4 `9 E6 k! \for(i=0; i<initProcessNum; i++)' @3 d8 Y% F; @3 H6 H2 t8 ?( b
{  g1 j+ u4 n) s1 g
waitTime=0;
3 }# g  T) K0 D  [& THR_ratio=1;/ d, F. I! o% q; G5 ~( f; U
}- {* G, n/ C0 B$ g! [
}
4 t2 W9 \* Y: N" L4 Ofor(i=0; i<(*storage).proNum; i++)  //等待时间增加,重置响应比* J; S8 T* [  d1 [& S: Z* P9 }. `4 d
{( D0 M; e# a( A( _/ _( O, e
waitTime++;2 S& E! d! W- R9 B( t
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);0 A, U* |) R2 `' e# Y
if(HR_ratio > HR_ratio[j])! G6 F' g0 u) I7 N9 Q1 J
j = i;) c  n* n( C/ G; k% G2 D9 j
}
& b9 z! V9 m% Z  Pif(dispatch==1)                    //需要调度一个进程到内存中执行5 N$ h% W3 h8 G! v
{
) {$ y" I$ X0 G3 W% e) ]- P$ h" Pif((*storage).p[j].askMemory < *spareMemory)
2 D3 W9 y! R+ f; @. ~' u) G3 Y{
. u! ~) X. ]- d0 Y9 w# {(*memory).p[0].askMemory = (*storage).p[j].askMemory;  n  r4 F& H: l9 b: N
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;+ c9 ]6 \2 B( O( ]  a0 p8 s
(*memory).p[0].computeNum = (*storage).p[j].computeNum;' k: |: ~$ A  T: p
(*memory).p[0].ioNum = (*storage).p[j].ioNum;$ ~+ E$ m4 r# \/ j4 G% z
(*memory).p[0].processID = (*storage).p[j].processID;+ Q3 h4 B" P- U' e
(*memory).p[0].flag = (*storage).p[j].flag;
$ o6 r) J! }1 \3 j& D(*memory).p[0].ioTime = (*storage).p[j].ioTime;
  h) q& F2 i# S, q& E* i(*memory).p[0].computeTime = (*storage).p[j].computeTime;) X, k6 h' F! ]! J- d! j: k
(*memory).p[0].runningTime = systemClock;6 J% p9 N% F: R) E
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
, f+ i( c6 D! V. C  z0 Qfor(i=0; i<(*memory).p[0].ioNum; i++)8 B# X. @# h( y0 S
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
9 G- e0 B1 V2 Ifor(i=0; i<(*memory).p[0].computeNum; i++)
; Q$ e9 E, [8 D3 n( H/ a/ a(*memory).p[0].computeClock = (*storage).p[j].computeClock;7 X' y; m& ]9 ~  }: J8 m9 P* c
(*memory).proNum=1;( p0 @2 T: u- X9 l" W' \
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
% _+ K9 `7 s  g; ?produce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程; m* w) S' w5 k3 |. t
(*storage).p[j].produceTime = systemClock;
' a& V1 n4 t0 M" O, T( _MAX_COMING_TIME = (*storage).p[j].comeingTime;) G* B% W3 h8 H* q5 v
waitTime[j] = 0;
+ g9 w/ Z  c" r  DHR_ratio[j] = 1;
  p, x1 q4 ^, g7 G- R7 ?: J}9 u0 q# l. H0 A5 \" A/ B; \4 \0 M
else
+ @3 i' V1 K8 k- V; Y+ L9 {4 K{
' Z+ i1 d0 ?( B* L3 y- K4 Qprintf("A process ask for a memory overed the system capacity\n ");
: C  U3 C3 c0 t$ L8 S" d$ s( x0 iexit(1);$ z1 @1 |" A1 l  w# [
}! g- M7 k5 u& S9 b* ~6 S
}% R$ e$ t" s% D! H! i! B
return 0;
1 h/ R. A2 S' r5 G+ r$ B' k9 t}
7 f( C3 L! h+ P$ r2 c; Eint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
2 P& x! W3 D) J7 V' s$ f& l& `{7 r8 w( h0 D  }+ Y
static int compute=0,waitio=0,change=0;& _9 @, `! {2 R- {
static int computeLast=0,waitioLast=0,changeLast=0;* @2 {( D' J) R8 I
int i=0;" w# l: r& A3 \* U' C* Q$ |
if(draw==1)
6 P3 M8 e6 X( M7 Y/ d{7 L0 B2 F4 [* l! j% r
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
1 V1 Z, z, W8 V2 P  [5 ?& MdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);: _4 S# E8 y( T, K

. c9 P* D, H8 M4 z6 f; u
; [7 J2 s0 h5 ~8 B# rcomputeLast=compute;
( E4 v, b4 K& d2 j4 j1 [8 zwaitioLast=waitio;1 P! u& _4 Z* s! \) L) a' Y
changeLast=change;! v% O6 H+ s9 g' L* r3 Z$ C4 r
}
1 k. e2 X8 c6 g9 F# \$ a& ], Gif((* memory).p[0].flag==ready)
4 a) ?0 r- D1 Z1 _' s9 k(* memory).p[0].flag=computing;4 I4 j$ Q3 Y3 }4 A. Q. f
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)! \& M& ?6 T: |0 j
{" r- |) |0 c( R0 G% _
i=(*memory).p[0].computeNum;' A( f/ s) u* L! ^0 ]  N( P  j
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
8 z0 F( Y' U7 M/ \{- A# {( m4 |; M1 A
(*memory).p[0].flag=IO_waiting;" ]" _5 i0 s& j$ T( q2 @
(*memory).p[0].computeNum--;# ?* X0 j2 V) \( W, g! k& g5 C9 B
change += exchange_IO_Compute;
6 j! ]. v0 _+ U7 U& gcompute++;9 V/ @9 X  S5 h
}
) ~; i; @; T4 f8 F" a, \& felse
6 j" R+ |0 u, a9 ~- E$ E{
4 G+ G2 O& Q5 O# Kcompute++;
4 o7 v2 p; T# h* x8 O. q}
1 I3 F9 V3 x+ o! w6 [. S6 t}
& a& ]1 q8 U- C$ L* z# welse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)6 }$ {) |* C" m
{
% j1 i8 Y$ s* e  [  O8 [5 C9 R+ Z
0 n1 {( h% d. S$ S- G  Ri=(*memory).p[0].ioNum;% b( F! X& @$ @7 g9 |2 H: P# _
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed  Z+ C2 x& b  M4 u+ v
{
& H( }+ d+ {, q: p: b& b; B: d(*memory).p[0].flag=computing;
. z/ ~# r8 W/ J  g/ V  ~! U) w(*memory).p[0].ioNum--;
& ]5 x! N6 A8 C6 x2 w# l0 B% Hchange += exchange_IO_Compute;+ N) g- v4 Z/ y2 F# Q% @2 a
waitio++;* p# I/ t" L+ f- {6 N$ y" Z
}) q0 u) p) G7 ^& @
else, {1 r! O; _6 b  g  z- y% k
{
5 |. I- A3 Q) {, O! k8 K3 D5 qwaitio++;
- X0 ~, d' W& m) s) N' S9 g}
+ i% g$ p  n! B. C, W}
" r/ e+ P5 `% |9 a$ q, }+ i+ z# Xelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
/ ?! d  V2 B4 F6 F- }+ }0 ]& R$ s{- ]: n1 i3 k  J2 o, X8 y
(* memory).p[0].flag=IO_waiting;
( S% t$ [3 l5 I. wchange += exchange_IO_Compute;
7 c8 O3 q8 `/ c, x& g7 |}7 ^* C- ~) B- k" K9 }" h( |3 r
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)$ v, A% m" b& g, R+ J
{8 ?0 v7 t; _& s( B
(* memory).p[0].flag=computing;' k& R4 b$ q' b- K: m" b
change += exchange_IO_Compute;* }- w0 Y5 \% m7 Q" T, z
}. H8 o" h7 A- X
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成
5 f6 k" {: n9 ^( v; n7 i{5 _6 y# N" J' x9 z, `
(*save) = (PCI*)malloc(sizeof(PCI));& I' t% C! _4 X- i
(*save)->next = NULL;
$ z% z# O7 E/ F" z/ z(*save)->processID = (*memory).p[0].processID;; h  {2 _2 e6 N* i; a8 Q$ ^' j  R
(*save)->comeingTime = (*memory).p[0].produceTime;  a. H- i- l& b
(*save)->askMemory = (*memory).p[0].askMemory;
! {3 a1 o' a+ O, T; }. Y5 @(*save)->compute = compute;. o+ e1 ?! W3 N* E3 F/ q
(*save)->waitio = waitio;! ]& m, _7 a2 g) t, x3 f2 ?
(*save)->exchange = change;' |1 @; n/ Q+ ?4 j- {- `
(*save)->completedTime = systemClock;7 X* L; [* _* g7 N/ b8 [
(*save)->runningTime = (*memory).p[0].runningTime;2 p) M6 t  @& U0 C: B- w
*spareMemory = MAX_MEMORY;      //*spareMemory + (*memory).p[0].askMemory;" {/ Z' k! s( R/ h/ A
compute=waitio=change=0;. b& ?8 p/ y2 x9 w% q
computeLast=waitioLast=changeLast=0;
; _% d/ @# m% s) APriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));! N/ c9 q+ N  d
change += exchange_process;( g% P. Z. h: T( I
return task_completed;
3 T- m! s0 P; i: A  d}  W' A( Q- a1 I% p- ^
else: }) @9 x' F* ~" C) V
return task_not_completed;. S( r" i1 N1 a4 J; M) ]4 a
}, n- O1 z+ G, X8 B5 p
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
7 t" o( \, `$ l2 _- J, r( W% o{  U6 I; A- g5 c: I( R
int priorityNum[initProcessNum],i=0,j=0;
; g: A5 Z; `$ N: J, Tdouble temp=0;/ e. D& j: j7 g; n
for(i=0; i<(*storage).proNum; i++)    // setting priority to each process
. b' z& G; H5 {& i& U' J9 N{1 w% G4 M4 R' Q2 x- O' D
temp = (*storage).p.computeTime/(*storage).p.ioTime;! n: e* n) Y7 F8 o1 I
if(temp > 0.8)- y/ l7 Y4 L% n9 `6 {& x2 e
priorityNum = 6;
& R: e4 r7 f9 |8 _else if(temp > 0.7)* ^% ]* j  c' [% N) P# N* H
priorityNum = 5;* b0 _9 [- A1 ~' b# _: i( \
else if(temp > 0.6)+ h1 ^& |( C) I' G4 M
priorityNum = 4;! e4 M6 ?7 i5 _. \. `* M& M: c0 M! r
else if(temp > 0.5)
! M4 L& c+ p( [  Q* \priorityNum = 3;* P; k5 y& u) B
else if(temp > 0.4)1 Q5 A& K' |4 j  }( G
priorityNum = 2;
+ f$ V( r% f5 o5 Delse; h2 k. ?: w" B+ R
priorityNum = 1;; g6 G) M$ @0 ]8 w7 V/ k
if(priorityNum[j] < priorityNum)$ d0 V/ g7 P) s5 X2 r$ |6 _, q1 x. s
j = i;+ s. S- p! z4 m4 S
}! n$ }  }  Y) F; G
if((*storage).p[j].askMemory < *spareMemory)$ J$ b* z, q% r0 F4 T; c& \
{
. \; u* T% g0 a' N, M/ d* c(*memory).p[0].askMemory = (*storage).p[j].askMemory;6 b7 B/ ?( o6 j, }1 x8 u
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;+ Y" p8 Q0 ~" v0 z2 u' h
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
2 V! E4 s$ S% a(*memory).p[0].ioNum = (*storage).p[j].ioNum;/ {% x  d, X; e  l
(*memory).p[0].processID = (*storage).p[j].processID;
  W( e# i3 }* I  z* u+ D5 U' z' G(*memory).p[0].flag = (*storage).p[j].flag;1 @( d  D/ @% p7 {4 i( J6 c, G9 F+ G
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
: n* a& Q6 C1 Y( E5 g; ]2 q* G: ^(*memory).p[0].computeTime = (*storage).p[j].computeTime;2 S! o9 ]! ]& c7 V/ ^" s4 L9 h' F
(*memory).p[0].runningTime = systemClock;
: ~' r4 s7 P' E; E(*memory).p[0].produceTime = (*storage).p[j].produceTime;$ S  @  D4 N9 s8 n
for(i=0; i<(*memory).p[0].ioNum; i++)
+ i4 P/ z6 k; S) Y5 ]. E(*memory).p[0].ioClock = (*storage).p[j].ioClock;
4 l# R/ `' Y% `; R: Sfor(i=0; i<(*memory).p[0].computeNum; i++)
) X5 q6 V  `2 U3 l4 @$ Z(*memory).p[0].computeClock = (*storage).p[j].computeClock;
+ E- D, j- g# k0 f6 ~7 k  |(*memory).proNum=1;
7 y* }" u+ p6 C! |4 G( k& F+ q*spareMemory = *spareMemory - (*memory).p[j].askMemory;
- C4 Q9 H  l4 ^' o7 I) z* L# d" d+ Qproduce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程9 g, D9 m2 Z7 U- e) ^; @
MAX_COMING_TIME = (*storage).p[j].comeingTime;! ~! Y+ ~. {+ _( c; E
}
' Z+ l# O+ h% k# {8 w2 u. Eelse/ W" A+ x# X# v* ~, {
{
# P4 t; ?* C- v) r- p& V( `, Dprintf("A process ask for a memory overed the system capacity\n ");$ g* @9 |8 P: a  A
exit(1);
+ V4 s+ O0 @1 W5 v& o/ H0 n}; v1 f& k4 o* i& w
return 0;
# e% l# V) q9 r5 [}3 z9 v; y8 m/ V
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)# x! k) D1 s; H* o% B$ }* e$ Z
{4 [- g8 i2 _+ ~! {
static int compute=0,waitio=0,change=0;
6 u5 R, `2 _; k, z3 T5 fstatic int computeLast=0,waitioLast=0,changeLast=0;1 f3 J+ `/ H, X: g7 J1 p
int i=0;
" |3 z, k" g5 K$ t' Q1 @$ U; s" Zif(draw==1)
2 z4 V. v2 w  |1 q$ \* T{  T/ t( r! r5 i# C% q; F
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
; o' x) ^& T5 N. C: D0 w7 C; n( VdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
, J4 S9 v! a. o. V6 U; {- _6 F, @/ @* @# \2 r- Q. f$ Q
% o) ?- w9 N  P4 W
computeLast=compute;7 N3 O$ r" {' @) d
waitioLast=waitio;
) ^+ L; n1 J6 rchangeLast=change;0 `' N/ b5 u* f2 v$ Z
}/ z! O( K" d5 _! [+ O
if((* memory).p[0].flag==ready)* Z2 [: I! U+ ~
(* memory).p[0].flag=computing;
- w9 [# T" y/ X3 Q7 a4 W9 {/ V& }2 Vif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)+ a! F3 H- D* P1 q4 w! ]" y) r
{
" Y  G- b% W" _- t8 oi=(*memory).p[0].computeNum;0 P: C5 g5 D% a2 Q8 K. q
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed7 @6 h# {, H2 c. N  W4 m# E
{( I! z6 k2 ?* ?& X. x8 r3 e9 x
(*memory).p[0].flag=IO_waiting;
$ e' W% J$ I- ?; M+ d$ h# ?(*memory).p[0].computeNum--;! V$ Q- _% l/ b; E4 J5 w4 L: t( T
change += exchange_IO_Compute;
; u. G  x7 i  r$ H: ccompute++;, A6 g' E  h4 Q& R6 t
}+ Q, ?; R) w/ F# ~
else
. a9 n) F4 i- @7 F$ m. L0 T{
0 I5 r6 {& h+ M- V8 U" d$ hcompute++;
+ e9 e+ `: E" d' g9 |# E}, B- o+ g3 y" ?! O4 {4 e' O
}
- }# U: k8 d- F+ aelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)- I& a: F. l' `' A- v1 L
{; S  o, t& g- E/ E( R) R

' H, K( i5 c. B$ S& Oi=(*memory).p[0].ioNum;9 j( F9 R% i, k3 K, ^3 ]
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed# S4 P, t" ?; O/ y
{
1 x2 C1 D+ t2 s6 n2 Z! V" O(*memory).p[0].flag=computing;
: t9 l3 U( t' I3 z! h8 g. |8 i(*memory).p[0].ioNum--;
5 O! z6 V2 d) Z2 v9 vchange += exchange_IO_Compute;
7 ^6 Q( N6 {: s% W8 F# E% `- ~waitio++;
2 J1 W: g8 @. W0 A}
' }  p7 Q" j' @, `else
2 p& p' N/ U$ B{
& D  u# I6 f. S% }5 u  K" [waitio++;
7 Y7 Z' f/ }/ D8 ]3 i}
( l; e, y4 I9 p* e/ q}" }" |2 m1 K2 x" U4 x4 ?/ i; c
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
3 K$ d) e" Y) R" ]+ P& J  z3 u9 l{6 R; d/ V' L: l# I! c8 I# f
(* memory).p[0].flag=IO_waiting;, V% W' h( _  w( d" E5 t) m
change += exchange_IO_Compute;
/ h9 Y. Q" T) P  R2 N6 v* F$ ]}
. B" S% ~7 M6 r' c" s; Ielse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)9 y4 K% O* W( l$ ]7 X9 a
{( H# B4 i7 y- v
(* memory).p[0].flag=computing;2 G6 P# u1 P( f. V& B2 U
change += exchange_IO_Compute;
+ x( v! d# @0 `$ Z}9 w, `  ?, m% ]* q
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成# g$ Q; \$ D+ D3 d2 }2 m$ Y
{
+ F7 x$ t, L; o9 B(*save) = (PCI*)malloc(sizeof(PCI));
% R$ Y3 R% f  R(*save)->next = NULL;
6 z0 l1 P/ z3 b3 m- G( L(*save)->processID = (*memory).p[0].processID;
! ?3 Q* y0 K* E0 u2 Z8 m(*save)->comeingTime = (*memory).p[0].produceTime;
8 U8 g$ U8 T6 c(*save)->askMemory = (*memory).p[0].askMemory;3 y  @6 n& o0 {0 l0 ^2 p$ y
(*save)->compute = compute;/ z/ p+ N0 h- w' y
(*save)->waitio = waitio;8 s1 g4 g% m3 J$ A  K& @# p
(*save)->exchange = change;/ L: j+ n* G5 l6 f2 r$ I! @7 u' h
(*save)->completedTime = systemClock;, U. |: m3 D, x9 h3 b% d0 A
(*save)->runningTime = (*memory).p[0].runningTime;, }' b# U0 L& H2 j) i! P
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
# ?* I8 O4 z# h7 {compute=waitio=change=0;
4 @- S8 `% L1 z& `; `: RcomputeLast=waitioLast=changeLast=0;" }& Y+ H' N6 _
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
) ]$ v, G' i8 |. E: fchange += exchange_process;1 S% W- e, A: J' z# N3 ~, a7 ]
return task_completed;* {, L0 R8 U& ]' ?7 I: ?  k% E
}
$ I" p" H( X8 N9 x! ?( `: c3 l4 F: lelse
# C1 `3 D8 U1 Areturn task_not_completed;
: A% \, ~1 I7 |! t5 }- Y4 @/ g- n}: h1 W  S9 e3 C9 h
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)1 d8 ]( u0 f6 z: K" N8 a
{
$ L( Y2 ?5 R8 H4 ^int i=0,j=0;3 @/ m# v3 p/ @: [0 v- [
for(i=1; i<(*storage).proNum; i++)
8 R: u/ H- z* Y1 Y{
! [% x, G! \+ y5 f8 wif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime)); r$ n! K/ P, R# ^0 W
j=i;7 P+ D, Z' w; F* z4 w
}
3 x' g, o! p5 E  [5 k3 Y/ Xif((*storage).p[j].askMemory > *spareMemory)! I( o6 H1 Q4 I( j
{
! c1 L" f) I$ G9 Rprintf("The memory asked is overflowed than the system memory.\n");- @2 y' ?4 M+ X0 s
exit(0);! r3 f  S2 F6 R; U2 l
}
3 d7 M6 H& z5 S1 q5 yelse
9 l; Q, R% f9 E) [' ?4 {{
0 R8 s$ P) |( l: y5 v(*memory).p[0].askMemory = (*storage).p[j].askMemory;& a  o& P  P9 y9 ]% \
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
" H  s# N% h8 P  Z' q$ j4 a8 s(*memory).p[0].computeNum = (*storage).p[j].computeNum;
# }% K: B% {# T5 o# J* u(*memory).p[0].ioNum = (*storage).p[j].ioNum;
& q2 r0 h7 q! {& t$ I(*memory).p[0].processID = (*storage).p[j].processID;
) l- F+ f4 |: i/ p7 l(*memory).p[0].flag = (*storage).p[j].flag;
6 L% {# i! @; H. u(*memory).p[0].ioTime = (*storage).p[j].ioTime;3 ]& Y8 d, f2 @! i9 U
(*memory).p[0].computeTime = (*storage).p[j].computeTime;' A+ X8 C( A& [9 R
(*memory).p[0].runningTime = systemClock;
3 H- [. U: h8 D4 O+ R+ w8 ]. o% b(*memory).p[0].produceTime = (*storage).p[j].produceTime;  I3 t: D" l, j9 s. H& q& ^. k) S
for(i=0; i<(*memory).p[0].ioNum; i++); k9 C2 l- h2 q3 G2 s8 X3 C
(*memory).p[0].ioClock = (*storage).p[j].ioClock;1 I# t3 z9 x! n9 X! C
for(i=0; i<(*memory).p[0].computeNum; i++)+ \$ N# n# j2 u! Q
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
! ^) h/ p9 J# \% U% q(*memory).proNum=1;/ O7 o; k% U% n3 Q, |  B5 U4 j
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
1 e6 m& B1 Q$ a) H: a, v  N$ Zproduce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
5 V- f- f6 ^# nMAX_COMING_TIME = (*storage).p[j].comeingTime;; |1 @! ]6 w" y" F+ _9 V4 D: y. i
}" n+ ^- w/ L9 D
return 0;7 G4 `  X6 ~" c- i6 k& G3 e3 V# M( X
}! s3 i7 J; H/ J* ?
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)9 ~; q* b; A  G4 E0 k9 z; n3 w
{6 B1 \! {  j/ Q  x4 P' w
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;0 d0 Z8 I6 F) x: ^/ I0 z
static int computeLast=0,waitioLast=0,changeLast=0;+ O+ _5 J9 G3 W. T8 S) R
int i=0,j=0,k=0;
. C0 H6 K6 h6 cif((*memory).proNum<=0)+ U& M) @( n8 V4 S2 g
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
" i! n; o% f( s# g/ W& }9 Jif(draw==1)9 d7 p+ |  Y: O0 D
{* r3 ?% L% ]- b, l$ ^5 }6 h
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);: d! ], j: @! e  c, m1 j
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);: F+ M$ u, W* B: I

( E' n$ j4 @5 N# D0 n4 e. h: R  v' {. R0 D) Q' O2 _% i
computeLast=compute;
( Y8 s) l% X8 ?- ^7 t( k7 PwaitioLast=waitio;
! U$ a# @! F& v! l( s1 dchangeLast=change;
& e2 o1 H. Y7 u% Z}0 ~; P6 l1 S, b. U1 u
if(poi>=(* memory).proNum)
/ i5 O5 }) i- J# w$ ipoi = 0;
4 ?2 k, R; {6 l# mif((* memory).p[poi].flag==ready)
" A4 ^: L2 |9 n( l; b/ y# M(* memory).p[poi].flag=computing;
9 \$ ?8 `# ^9 |3 o# cif((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
/ ]) Z; O5 P! s  v& `; e+ k{. N# I  D  I: d
i=(*memory).p[poi].computeNum;
8 v' i7 Z, ?# S6 j' jif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
: p1 N8 i, A7 |{
2 p% }1 c! ?1 F9 @$ u' h8 ]2 K(*memory).p[poi].flag=IO_waiting;
& ]1 d* d: v: W; @+ }(*memory).p[poi].computeNum--;
. k- [1 {6 q: _; [; Tchange += exchange_IO_Compute;
& [2 k1 N$ ]! Y2 E" Q! }: t# Ecompute++;- g# t. X* k$ J/ K/ f
}9 m& L' I- o; \/ `  \* l
else
6 {; z& x3 H/ @- p* E' P* o0 u{
1 O3 L5 U4 b& ^2 s  vcompute++;9 ^) }2 k. P/ q
}9 l8 M4 u) ?2 A
}8 B9 c& q6 u1 l" P( ~4 U/ ~  d& u
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)) z& }3 A6 G& K1 K: \: C$ @
{
. T8 m4 I9 R2 q; d- @
6 Y- B4 m& D+ I- e& \$ _9 p3 ?' `i=(*memory).p[poi].ioNum;
+ g3 ]1 f1 `9 z' Q7 Eif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
; r" ?. R5 O8 L- Y7 v/ z{
5 ^" r% [3 h* t4 G. o(*memory).p[poi].flag=computing;
! V- Z1 F! n4 i5 m' n(*memory).p[poi].ioNum--;
' \, v: F& l1 d+ c' `. }+ G) pchange += exchange_IO_Compute;
8 _1 Y2 q& W2 w1 b; u5 M$ v$ bwaitio++;4 T* _% a* b7 v6 y+ N/ ?* D
}
3 ?* @9 O  r5 N% n  {! xelse% I* d# B0 o. s
{
; `% m2 z$ Z: m% i* G+ Zwaitio++;+ y# @9 T: c8 X$ C  H4 Y. l5 |
}9 o: ^) b, q2 e! i5 N/ [% T8 @0 S4 ]
}/ d- A) l3 |6 [, y8 f% T. |9 y
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
) f  h1 e  \0 j2 Q{  M4 ^* m/ X4 x/ e4 d$ Y
(* memory).p[poi].flag=IO_waiting;
8 a/ Q3 b- C  R/ }change += exchange_IO_Compute;+ k/ [# x! n6 G$ J. e: f
}
8 X. i$ s" g4 V1 @6 _; X; Celse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting). o9 c1 X- `3 c: ~0 N' |! U% u
{) @& q+ g7 j9 c0 [2 q( P
(* memory).p[poi].flag=computing;' V/ y' L: k# u
change += exchange_IO_Compute;3 ]1 d7 L% M  S" ~. e& u1 g; C
}
# v: a+ E5 ?" S7 E% l6 z# Ufor(i=0; i<(*memory).proNum; i++)  //其他等待io的进程可以并行推进
" O4 U. g6 R' B4 [: R. o& V4 t{
6 O/ O) `0 R- `3 `0 l& n/ Wif(i!=poi && (*memory).p.flag==IO_waiting)6 i# B6 b: w- X: R. v
{
9 }. f; @: b7 X0 Oj=(*memory).p.ioNum;3 U- u5 t( p- @: k& O0 J: {  Z* G, U' x
if(j>0)
" {* q) h6 p/ ^9 G$ Z% h{
, e4 v) l# ~! o' E+ _if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed% X9 `3 L; M2 B+ r9 M- w: F
{* j2 F0 ~. r, t- Z
(*memory).p.flag=computing;
, L6 v) u# O6 H7 }(*memory).p.ioNum--;# ^; ^" A9 j+ t  |2 g
change += exchange_IO_Compute;( P5 [  }+ x" P& ^8 e  U; s- G
}# X2 W8 R! p: l2 \9 }8 C
}' z. M0 m9 H2 `  {% K
}# H- v) ~: l6 N
}
9 Y4 \( A: s; z3 V8 r; Tfor(i=0; i<(*memory).proNum; i++)  //处理已经运行完毕的进程) W6 t  G# B* ~* y0 h
{2 w, @( M  E) e4 |& f* K
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed3 S0 L  e  T2 k7 B, b# \: h$ @
{, w4 p; r9 m4 L# c; \( f
(*save) = (PCI*)malloc(sizeof(PCI));
2 M$ q0 Z& Q# C4 s# Z: i* |. `  F' v(*save)->next = NULL;% u0 `3 W6 z1 @: a! n* a) ]
       (*save)->processID = (*memory).p.processID;
. A& i" A9 K- v) Q! D0 x3 G(*save)->comeingTime = (*memory).p.produceTime;
1 O3 [2 m* E% P9 w5 ]9 {(*save)->askMemory = (*memory).p.askMemory;4 y/ n* z: P: E7 r# l7 i" Q
(*save)->compute = compute;
2 R( w3 b2 B8 z# H3 H(*save)->waitio = waitio;0 `6 i0 a. A) T; ^/ E
(*save)->exchange = change;
9 M8 R: w5 a: ](*save)->completedTime = systemClock-(*save)->comeingTime;9 _9 `4 [! W$ Y- s5 u  S4 R
(*save)->runningTime = (*memory).p.runningTime;: s/ R+ [5 Y; D2 n
(*save)->completedTime = systemClock;% `& t7 y* B; w0 f" j3 P
*spareMemory = *spareMemory + (*memory).p.askMemory;
2 z2 H) p6 Q: Y  Ocompute=waitio=change=0;" U0 N& p7 ]' h
computeLast=waitioLast=changeLast=0;" _9 r5 e- g) c- i
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入) F  K4 q/ B3 A
{
3 N  i$ W- u: K' x6 y, D% r! P$ M: nif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
( A5 ?- `5 C/ _% p  h% _$ Z  }7 y{
* w4 i: R* Y/ V$ _  a8 M/ qpoi++;5 F! k0 d7 T5 G, E* K. Z
   clockSegment=2000;
5 ~& D8 O+ Y/ `}! Z$ P9 y% ]" m  c* ~# j
}9 z( Z& v5 J7 [9 |. n+ @
else  //没有足够内存调入新进程
6 U$ b4 {$ z, m1 z( F5 [{0 v7 b( H. l( J1 |
if(i < (*memory).proNum-1); G0 x1 Z# N+ d9 L% m
{
7 ?, l2 l! A  |) s1 v# }' j$ i6 Pfor(j=i; j+1<(*memory).proNum; j++)+ i% a% |' Z- ^% p; r: m2 W$ e( X- ~
{8 [% O) H( y. E3 C8 l( i
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
) A! O8 k7 }7 ^. B3 p(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;1 l. \& A* M0 u" X
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
9 G5 y4 W6 s1 O2 M+ p(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;- _/ J" x( @" M
(*memory).p[j].processID = (*memory).p[j+1].processID;6 r. E- Z9 w& f. H% q. B3 q6 {
(*memory).p[j].flag = (*memory).p[j+1].flag;5 O! C4 ?# {. v3 r/ M
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
- H8 l$ g4 \; I- S' N* A6 }& g8 }(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;: o' s; p1 ], Q+ m4 W5 l9 L
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
9 k/ o- c( X- T(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;- x6 U/ ~3 v# U
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
4 k% _/ j! j( x% v  C+ j6 Qfor(k=0; k<(*memory).p[j].computeNum; k++), ~1 W% R; s6 x4 v7 I
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
  I  e: H" _( I  k' Hfor(k=0; k<(*memory).p[j].ioNum; k++)1 L; w( o4 ^6 ?
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
: V0 P' ^1 I5 M( ^( h8 ^, s}
1 r/ w* w' F8 h+ K7 Tif(i<poi)4 n; x3 k$ R( G+ P# I
poi--;
; |0 S5 `3 {- |else if(i==poi)
7 X8 l8 q$ I+ b8 g9 T: Z. `clockSegment=2000;
) s) Q! S, R. ]$ \6 h}
/ ^6 Y' f- [1 |3 l' ui--;! c( A; z" \" N) n# M
(*memory).proNum--;
2 r1 P; `9 U& y" f}3 _9 y$ S( y7 t, U3 x+ k
return task_completed;3 V2 b: {" G8 A8 w
}
5 z& U6 J0 ]3 ]" c. P& Z9 {}- u# c/ c- w, |) z+ X. _0 a4 Y
--clockSegment;/ z  N$ }' O6 L. \0 t+ w+ P9 M
if(clockSegment<=0)
( C# C+ {0 ~+ ~* h+ z- R, t  o( t{& J: F7 r% {) D/ {8 b
poi=poi+1;
# p" ~9 B, d* v3 a  o2 Sif(poi>=(*memory).proNum)
: o. x. o" |8 rpoi=0;5 K, @  Y  ?- n* I% D0 N5 o
clockSegment=100;
( k7 r. C: m, Y1 k/ \}- Q! ?; p& A$ v
return task_not_completed;' v2 S' ]; l- F( ?" r2 P
}
0 c% _6 Y5 Z) v) F* K6 B: X, P* k& \int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
& h1 U0 b! w/ n1 Q, y{
; l9 k* q0 }( a, M( f& e/ B8 n$ @int i=0,j=0,k=0,flag=0,translation=0;
3 G% {2 y' J# x+ Kfor(i=0; i<(*storage).proNum; i++)
; y9 C' O% H: B& y, m% S  N6 }{
8 _+ ?! p! ~& N" f6 eif((*storage).p.comeingTime>MAX_COMING_TIME)
6 e( r( s0 R8 GMAX_COMING_TIME = (*storage).p.comeingTime;4 s9 a7 h$ l/ W" z( R
}
  Q, B9 ]! r  b: J' g/ Z0 ~0 fif(pos>=0)
  A8 A# d1 e+ {; b4 K6 j{& d- x$ Z; |* e; J% _6 C' p
for(i=0; i<(*storage).proNum; i++)
+ h" |$ g! ^8 l* t# k{
9 Q; _2 K. Y2 I( A4 rif((*storage).p.askMemory <= *spareMemory)6 m: c! j" b' `$ x" g" c( x
{5 j: ?0 v4 F3 m5 V# F, m; Q- B( A; E
j=pos;+ N3 U: i4 N/ f1 _! P
(*memory).p[j].askMemory = (*storage).p.askMemory;
7 b% R% V" T) q7 |(*memory).p[j].comeingTime = (*storage).p.comeingTime;
* s8 P2 T1 @) M; W0 u* z$ L5 |(*memory).p[j].computeNum = (*storage).p.computeNum;4 D# U! L+ }8 L, T: v3 j
(*memory).p[j].ioNum = (*storage).p.ioNum;7 Q* x, Z% l- m
(*memory).p[j].processID = (*storage).p.processID;2 i0 Z  W  g' ^0 }( m
(*memory).p[j].flag = (*storage).p.flag;
; i. ]% d8 G- a$ c! N* ~(*memory).p[j].ioTime = (*storage).p.ioTime;% t+ X  i, ^* i; t2 j% Z$ |
(*memory).p[j].computeTime = (*storage).p.computeTime;
+ Q5 j8 o  R. K$ f7 G/ e2 D% u2 C/ L(*memory).p[j].runningTime = systemClock;
8 p& n. Y/ D7 A! ~6 h; n(*memory).p[j].produceTime = (*storage).p.produceTime;
' l9 w6 \* x7 J/ K" @for(k=0; k<(*memory).p[j].ioNum; k++)$ j, `) w( }' r- Y7 `, S
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];- q) L' B; e% a# v/ p
for(k=0; k<(*memory).p[j].computeNum; k++)
2 G1 y* a# A% G: H8 d( ^(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
% N. a- p# x6 T" G' Q- v*spareMemory = *spareMemory - (*memory).p[j].askMemory;
' t; u7 M4 L5 P6 G% Z0 l4 `# ?produce_one_task(storage,i,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
8 `0 }3 _4 ~/ z, U! {MAX_COMING_TIME = (*storage).p.comeingTime;+ Z4 i  N1 d2 ^
translation=1;
+ F( S' I, F- \4 r5 \break;
' l/ I- Y0 i8 S}4 R. H9 s+ r7 K6 D
}. U( r7 a3 P" |1 S
}
: y1 I. N) J9 T' o: J( Q$ Z; B' D( ?else" q5 z+ z% a- b
{* ?+ {) Y. I- N' C9 r
while(1)/ d4 b. n# a* Q9 ]+ g7 Q% t
{
, E+ ^6 o0 t' r+ v3 [$ Sflag=0;1 H! Q2 E+ f  B! \1 C
for(i=0; i<(*storage).proNum; i++)8 B1 j& e3 j( Y+ R
{: z5 C. A7 {8 `  l$ v% e. Y: w6 h; S
if((*storage).p.askMemory <= *spareMemory)# C% }) u- ?& `1 d. ?
{
) B8 {9 }' F1 P* qj=(*memory).proNum;' N$ q/ V3 H! F5 E4 l& A2 k% i
(*memory).p[j].askMemory = (*storage).p.askMemory;9 F  O  N6 l4 z5 `( l& g% Q/ g' S
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
4 x- R, S5 _  z6 V+ O& {(*memory).p[j].computeNum = (*storage).p.computeNum;3 q% f6 w( R1 [' o" c- r
(*memory).p[j].ioNum = (*storage).p.ioNum;; x+ B0 Q4 m  F' _. \0 X
(*memory).p[j].processID = (*storage).p.processID;7 F- G& p! \! w% O+ g; r+ j! r& k
(*memory).p[j].flag = (*storage).p.flag;5 P' c# o! w) F) m' a- p
(*memory).p[j].ioTime = (*storage).p.ioTime;- z& P3 i% O8 v; j: s: R
(*memory).p[j].computeTime = (*storage).p.computeTime;# E' l: Z& M& j" ]" L9 r6 I
(*memory).p[j].runningTime = systemClock;
' g! k& l2 b% I& E6 B8 p. |(*memory).p[j].produceTime = (*storage).p.produceTime;
9 m. a) J2 z2 E3 [6 Q, L( cfor(k=0; k<(*memory).p[j].ioNum; k++)* U# Y  f/ ]" A1 H. j8 p  s
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
2 O4 O2 ]) ~2 s- ?& }4 Lfor(k=0; k<(*memory).p[j].computeNum; k++)- v+ O: [3 E& X4 R# d! O
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];" p5 t8 g  Q2 `% t  R8 M$ z1 _
(*memory).proNum++;
: U( l( c* R5 o9 y0 {*spareMemory = *spareMemory - (*memory).p[j].askMemory;
# r# f; `+ N, @/ w8 @. j( gproduce_one_task(&(*storage),i,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
5 }3 `) F$ _+ S1 ]MAX_COMING_TIME = (*storage).p.comeingTime;
0 d0 o) ^" z; y: dflag=1;
6 @  P# w; c, H" a0 G3 Ctranslation=1;* T$ _* f$ |5 H) r
}" Z, p. g$ {9 }4 q1 }1 m- G
}
, ?" G1 n( q# v) R& I% A0 Nif(flag == 0)
( Q( l; H+ _7 C( ^# K3 r6 @break;
' t% ~3 W+ q+ t' L6 A+ @: B}
0 @! A( a* P: i! P, m( Q) p}
. B5 J, k# y& ?3 O9 wreturn translation;& z) y" j3 E) M' s- a+ Q
}
+ j3 _! \; a/ m' Dint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)2 |- }2 |2 b: h3 x5 T
{
$ q( z+ y2 B" Y8 t# Cstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
' [# h) ?; j% I+ }0 dstatic int computeLast=0,waitioLast=0,changeLast=0;
; w! {/ f8 x3 ^, mint i=0;
1 i+ a" a2 W/ ^if(draw==1)* ?' [$ u. X0 x1 B2 J6 w
{' \- ^2 ^6 R  C# R) P* n
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);. m3 J6 p5 y: A' _( m7 o% F
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
6 A  H0 o, B' ~+ Y! x
$ L% |' p: \& d& A2 ~
' R) _. j0 D* C9 a  |* W8 L& K  @. PcomputeLast=compute;/ o9 f/ E2 A1 C* W, q7 f
waitioLast=waitio;6 E) s. h" c8 V- Z8 _# g7 {6 E! Z& ^
changeLast=change;) ^4 Q! Y( o6 |. B
}
; I* k  d; R* ]* M1 kif(flag==1)  . k3 a) I7 |/ Q0 @- M. R) C' H
{: e/ g4 M0 e. B& [
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0)  //task is not completed, d$ t) o* Q7 c/ U7 Z% x4 e$ b
{
! u. x5 v, `- D" a; G) X  \4 jif(flagiocpt==0)   // implement compute
  ~/ t3 e6 D7 m3 B$ k1 q{+ a# C0 T6 `" r$ G( v& h
i=(*memory).p[0].computeNum;
' m6 ?/ |2 i- H+ zif(i>0 && (*memory).p[0].computeClock[i-1]>0)
% Z6 s( T6 O: ?+ h. b{0 E( n! e/ _, [
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed' S# j4 s3 v1 e+ R4 s! c
{
7 @1 a: z+ S" g" Yflagiocpt = 1;  ], k) r: H. t# j- C7 U
(*memory).p[0].computeNum--;
7 q9 n1 |( X: Q6 u# V9 M2 Echange += exchange_IO_Compute;$ G+ a( R! n8 Y* f
compute++;
7 R5 S8 q/ x9 i7 o}2 p/ }0 k' ~0 M( x3 i% r
else2 p5 x" D3 s2 T+ f; D
compute++;
' M8 O1 @7 ~! |& y1 b9 q2 N% w* {2 t  \7 T9 y
}
2 {, Y/ v! m# g4 S5 Velse# W7 F4 r" N3 [5 E
flagiocpt = 1;' b# ?9 f4 U: R+ ^. {8 x" j
}
# L0 {; X7 [: f% x: b% g8 ielse  //wait io/ n: D2 A- z9 R
{3 U7 R) T* a; |
i=(*memory).p[0].ioNum;
# V/ t; Z" V+ A3 U' sif(i>0 && (*memory).p[0].ioClock[i-1]>0)
" H# @9 f# ]  ?3 e) p3 l{
9 z; w, \2 V5 h/ B- a6 A* bif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed% }- L- a. L. ^, [9 `' ~) L
{
3 y4 h6 o8 E: I* zflagiocpt = 0;& p9 K9 w4 G/ H5 W7 _0 G1 }
(*memory).p[0].ioNum--;) v' l3 j8 t1 M- T4 |# B3 z: m
change += exchange_IO_Compute;
6 ~, m2 o$ R  K) Zwaitio++;# }. @* @# x& P4 s
}) ]3 B3 o0 p, M0 b$ e
else  S, z+ Q' D1 s& f9 {
waitio++;2 x7 K, P7 ?6 G% t, w" @% a

1 k! V. Z1 n8 k5 b5 B3 L0 [  M}
- F2 N/ p- c! z1 ?& p9 K0 o8 uelse7 X& O" C# m. q( I$ l
flagiocpt = 0;& R* i! K$ s' W9 S5 w
}3 G* f( B$ r, b) u3 F7 r
}
) N% |( G6 o, Y& {, ?/ ^else  //task is completed: K- ~% X8 e. z6 u' K3 o* n( R. H! H
{
* i0 a" }/ x; W  Q" s(*save) = (PCI*)malloc(sizeof(PCI));" a1 L# o% q" x6 N! R- Y3 B# ]
(*save)->next = NULL;
. Z. b: [) w0 c6 Z       (*save)->processID = (*memory).p[0].processID;
9 x" e( A% n+ A$ [1 I  h; J(*save)->comeingTime = (*memory).p[0].produceTime;
6 O& W/ R4 V0 O/ v6 p3 p' p(*save)->askMemory = (*memory).p[0].askMemory;
) A; i  T" h* }4 g$ t" a(*save)->compute = compute;
+ {$ E3 j! u1 H7 [- b(*save)->waitio = waitio;
# [1 }8 F4 P$ X1 N( V4 t(*save)->exchange = change;
. s2 ^, m# q; O3 Q7 z(*save)->completedTime = systemClock-(*save)->comeingTime;
5 x1 E' K3 [/ f) j, O5 z: A(*save)->runningTime = (*memory).p[0].runningTime;
& A3 f1 j/ S: I0 C0 `2 v' Q  a(*save)->completedTime = systemClock;( v3 g7 l/ X) q/ Q7 p  B
//*spareMemory = MAX_MEMORY;! ^3 W- B- d7 f8 O
free((*memory).p[0].ioClock);
6 y. ?- z  x. U8 Mfree((*memory).p[0].computeClock);# R9 r$ @7 M6 A3 J2 @, m+ p
free((*memory).p);6 B/ d+ ]" G: x2 s) z6 |5 L
flag=0;: v  q8 b( w* t2 ?
compute=waitio=change=0;
  P4 `2 r- W  F0 N) t/ h* OcomputeLast=waitioLast=changeLast=0;, t7 s5 W6 Z, p% E( ?+ U
return task_completed;
6 y* m" f& J) R$ e8 W}
4 Z9 K6 `$ z& J4 o% _4 o" h9 |, I}
* l* x8 {& b) a) Delse         
+ H3 @+ N9 E; ]8 f% I4 _, R{
3 N$ V$ g% Y- N5 Q# e" y' ~* \" dFIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));. P  w" C1 o1 F* v; s) t
change += exchange_process;
- |9 L* f  |' W//*spareMemory -= (*memory).p[0].askMemory;
2 e5 P  E4 @  fflag=1;
3 \; p; b/ f9 P: X; Y//showProcessInf(*memory);
" h/ k; G3 M0 A8 v! D# ~) kreturn task_not_completed;9 k5 H  {+ R3 `, q! _
}
! H5 v5 M6 k* z8 |  s; A, rreturn task_not_completed;0 r$ u- j% P# t/ S. l
}
0 p+ Z4 U! I8 @( c7 @: Y/ Gint FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)
0 N* f8 k2 [1 V. t  E{
. ]% h" M- k) p% |/ p$ Vint i=0,j=0,k=0;
2 h2 f/ s! L* L# g7 cMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;- L$ A8 T1 @4 B
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
) y- P( |) Q/ `! d) v  c* t! r8 a! R" n4 Umemory->proNum = 1;" T' r" L! _6 R' o+ q8 f) j7 Y8 j
for(i=0; i<initProcessNum; i++)
7 o, [+ L  O; m# f0 T{6 d; \7 L4 j0 V7 `# O
if((*storage).p.askMemory <= *spareMemory)
( m' P0 a9 }* r" O* ^{
7 F4 R2 C$ j: E# F* y, v(*memory).p[0].askMemory = (*storage).p.askMemory;+ u" h7 e- L. e; p  c/ l
(*memory).p[0].comeingTime = (*storage).p.comeingTime;1 v9 R6 }4 `% O2 c0 w
(*memory).p[0].computeNum = (*storage).p.computeNum;( [9 y" \" ^6 v$ l  p
(*memory).p[0].ioNum = (*storage).p.ioNum;" F) g, W1 Y* k" Z% Q3 v) B
(*memory).p[0].processID = (*storage).p.processID;
  i2 u, o& A! W2 p6 t0 k. @(*memory).p[0].flag = (*storage).p.flag;0 `7 b4 f  C' y: v% \: Q/ K
(*memory).p[0].ioTime = (*storage).p.ioTime;" W2 M& N, A8 g' x$ C
(*memory).p[0].computeTime = (*storage).p.computeTime;
5 J. Q' R9 ?; _(*memory).p[0].produceTime = (*storage).p.produceTime;  S; p: N( A" ]  c4 ?
(*memory).p[0].runningTime = systemClock;# z8 G4 N- Q, L& t. n% `
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));7 n. f$ h3 C- H9 ?
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
1 r  d9 i, P: u6 bfor(k=0; k<(*memory).p[0].ioNum; k++)9 F1 k5 ^: T. R
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
; x5 l4 y" x9 X7 B2 Z% h4 H" sfor(k=0; k<(*memory).p[0].computeNum; k++)
# o# p( I1 n6 ?7 J7 a$ @: ^( X0 z(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];/ [* t: E5 U  Q9 _+ z
break;
  ?$ C* n4 Y  x6 |7 ]}
8 ]) m2 D% b/ M3 A; N5 o}# }$ g3 R0 v. {
if(i<initProcessNum)  //调用一个作业进入内存后,并再生成一个作业等待调入1 C; R" _" U  {1 N2 j; W
{$ B. a) W8 a: y7 Q" v5 V/ ?9 S; ]
produce_one_task(storage,i,ID_FIFO++);; Y& {" v1 K" h: Z: x& j6 h" R4 _
MAX_COMING_TIME = (*storage).p.comeingTime;% y8 ~1 r. a9 \9 `
sort_by_comingtime(storage,i);
) X' A$ y7 T- }" B+ @; V8 K) V7 Y}
) Z* \" |" M# J% d5 F& N7 L/ Areturn 0;
$ e1 T' b- T: B# [6 k}
5 I  v+ a1 E6 i# L# u/ Yint sort_by_comingtime(processPool * p,int pos)7 p/ {4 X+ y& v( Q  V
{! D0 H" x0 @; `  m, B7 L
int i=0,j=0;
0 z# ^; E* |* a8 p/ h) |7 Oprocess temp;
, j+ A. A+ n- Y) eif(pos<0)1 W& a; d2 ~5 i& \
{
& D9 Y! k" I8 q* M8 Y( K3 F' L- ifor(i=0; i<initProcessNum; i++)
) g; ]1 W" ]3 W8 v/ |for(j=0; j+1<initProcessNum-i; j++)
1 Y( i+ j# ?; B* v, p; H{- ?: T1 }7 y+ s9 R. @& R% W
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
, i5 g& i% N. f% V, ?, W, Y{
+ V, x9 Q* a& x( htemp = (*p).p[j];% E2 t* P4 M& e2 o3 O
(*p).p[j] = (*p).p[j+1];
+ l* Q0 V9 c6 Q0 I6 w(*p).p[j+1] = temp;8 T3 B( Z9 @9 u5 \
}
/ i5 R6 i) {' t+ ?$ L! G' [}
7 w) F% P: i6 D1 B}
2 I; H8 D$ J/ c- C1 belse if(pos<initProcessNum)
& B4 R. s) b) Z& o{
2 W, C# x% D! u7 z* Qfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)1 M% ]/ s* Z9 i' x- M$ ~6 F& Q6 h; s' P; [
{/ h) l, L6 Q' o* N6 }# u
temp = (*p).p;! U+ C# T5 u: f  X4 c. g
(*p).p = (*p).p[i+1];
" m" U) ?! w) x) L$ ~$ i/ |* Q(*p).p[i+1] = temp;7 y9 f3 z5 O9 |8 v& n. C/ Y
}
  W, H+ ]1 Y0 M3 P& l" Rfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
. `0 Q$ l8 |8 r3 n6 f2 C, u# J{( K# q. d# x( i7 i$ |
temp = (*p).p[i-1];$ _7 R7 `7 o2 T" k
(*p).p[i-1] = (*p).p;& r3 Y3 A' m$ a+ s; u/ H6 q3 q
(*p).p = temp;
4 M% E4 h: n( B# C: d5 ]}
4 n5 n& \! f' B' Z9 s/ {/ k}
# d% J! T* f2 W& B0 X5 _* l& melse
" m! G6 M; r" f3 k" H2 {) ?printf("position eror\n");& W* ^# ^, \4 O4 _
return 0;
* k+ `5 `' W0 i+ X/ U3 {}/ Z% L7 ?& G5 d$ @8 Q/ c% g
int InitPool(processPool * p)
- n) [8 B, p3 S8 ^' \6 y, T+ j{
% S. _& j7 `# o5 rint i=0;4 S: V. @. S0 X' C9 x
(*p).proNum = initProcessNum;
7 E! y( l/ S1 p# V(*p).p = (process*)malloc(initProcessNum*sizeof(process));
' q2 g9 m) i% C) g6 L5 Jfor(i=0; i<initProcessNum; i++)                                        //init process information$ U2 h& D+ ~8 F, H4 z
{
: ], J9 X( T! e. {4 p' X! ^. p(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
, Z$ N+ {5 w; C, C( T(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
$ A7 w5 J. R/ oproduce_one_task(&(*p),i,ID_FIFO++);3 j/ f- T& s8 [% d# l$ M8 j+ f
}7 ?% |- o) [0 Y) P( O" |% v+ |
return 0;8 {1 D. i" B( y0 C5 n
}
" M7 J$ i/ `& w6 x& Rint produce_one_task(processPool * p,int i,int id)
9 u. I3 r4 e# n  r4 `2 Z{& s( y9 f1 c- k- V
int time=MAX_COMING_TIME,j=0,totallTime=0;2 X: Z, L. |; n1 B5 N, k0 V
(*p).p.processID = initProcessID+id;           
5 I5 D. `' p9 J0 R0 V2 [, p(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);: L4 c, P. R. R" m* k
(*p).p.produceTime = systemClock;
6 [" u9 [* b/ N" s/ X* |(*p).p.ioNum = rand()%4+20;                                        //IO number setting to 2--5;/ g* _' L4 ^8 ^- z* i; b9 o1 g
(*p).p.computeNum = rand()%4+30;                                   //computNum setting to 3--6;# U9 S7 N! r) M1 O7 K
totallTime = (*p).p.computeNum  + (*p).p.ioNum;7 G" \. E1 |7 A0 l
(*p).p.computeTime=0;
+ b( ^6 A' H6 g) P) d) Gfor(j=0; j<(*p).p.computeNum; j++)9 Y3 v- f3 c! t
{
2 R2 w1 u/ O  [- w(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;6 L% Q# \' F- y
(*p).p.computeTime += (*p).p.computeClock[j];( Z) @0 m) i0 i8 C1 ^
}
$ r. ^9 ~5 y5 n9 d(*p).p.ioTime=0;
/ l- i$ F0 @+ B0 M" O. Rfor(j=0; j<(*p).p.ioNum; j++)% ^+ Q5 U: T8 E! \0 `' _  k, g
{$ M( R& g, @. [# b5 _" c
(*p).p.ioClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
* E7 g0 s6 q8 O7 ~$ j(*p).p.ioTime += (*p).p.ioClock[j];# f- H5 Y. d5 Y! W7 b9 ~8 b
}( i: t9 ~  Z8 n2 Q" Y
(*p).p.askMemory = rand()%(MAX_MEMORY/4);
0 b- S" q- t5 t, D" D(*p).p.flag = ready;
6 f2 l7 L) h- b  a* Nreturn 0;) q! @" v# A$ c+ x: ~# C, ~' Y
}
* |8 H! k1 F5 l* [- }3 aint showProcessInf(processPool p)" L% L4 u8 V0 s8 P
{
9 V7 N6 [! k; H5 u! L# k. Eint i=0,j=0;+ I8 C( }; I! c" D' O3 ~) x
for(i=0;i<p.proNum;i++)
( a' ?$ }- I" D' U: `  [. K{% c/ ]' p, H) A, P8 ^7 Q2 B7 q# C
printf("ID:%d,%d,%d,%d,%d,%d,%d\n",p.p.processID,p.p.comeingTime,p.p.ioNum,p.p.computeNum,p.p.ioTime,p.p.computeTime
' P; E3 Y2 U6 v* j: q+ y# [,p.p.askMemory);$ [: s0 h  `: @8 O. g3 b$ a7 r
for(j=0;j<p.p.ioNum;j++)% F2 B0 x# P( _7 H& T, L: J1 i
{
# c7 J) s! r& w1 [8 g% ^9 g4 h/ {printf("%d ",p.p.ioClock[j]);
+ r3 P/ z4 m5 o3 |+ V2 B}
  b; ~! ^( ^9 s3 jprintf("\n");. Q2 [9 f, C( t$ I3 ]
for( j=0;j<p.p.computeNum;j++)
- U  [# v3 n2 \# @{
/ a/ r( }! P+ Y" r' P7 O( l7 [printf("%d ",p.p.computeClock[j]);
# E8 P1 ]2 o4 R/ ~* N}
: {: y5 u4 u! hprintf("\n");8 H2 d& a0 Q0 P, Y5 F& X! F  k, Z
}/ G6 Y$ E% T6 b( `' D
return 0;
- j- E# p" Y) H3 S# s7 E}# \* p% s: v0 o- O
————————————————! i7 C& w/ J' a6 S" n
版权声明:本文为CSDN博主「wang_dong001」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。/ ?4 ^. r) o: W0 B. ~5 p
原文链接:https://blog.csdn.net/wang_dong001/article/details/47843519
. i- w; f3 u- h( D. c% |8 d
# w& J* H) e5 D# ^. S& n  c& Y3 H. H; o6 y) r: _





欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5