程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 模擬進程調度

模擬進程調度

編輯:Delphi
unit Unit1;

  interface

  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ComCtrls, StdCtrls, ExtCtrls, Grids, Calendar, Gauges, jpeg;

  type
    TForm1 = class(TForm)
      Shape1: TShape;
      Shape2: TShape;
      Shape3: TShape;
      Shape4: TShape;
      Shape5: TShape;
      Shape6: TShape;
      Shape7: TShape;
      Shape8: TShape;
      Shape9: TShape;
      Shape10: TShape;
      Shape11: TShape;
      Shape12: TShape;
      StaticText1: TStaticText;
      StaticText2: TStaticText;
      StaticText3: TStaticText;
      StaticText4: TStaticText;
      StaticText5: TStaticText;
      StaticText6: TStaticText;
      StaticText7: TStaticText;
      Edit1: TEdit;
      Edit2: TEdit;
      Edit3: TEdit;
      Edit4: TEdit;
      Edit5: TEdit;
      Edit6: TEdit;
      Edit7: TEdit;
      Edit8: TEdit;
      Edit9: TEdit;
      Edit10: TEdit;
      Edit11: TEdit;
      Edit12: TEdit;
      Edit13: TEdit;
      Edit14: TEdit;
      Edit15: TEdit;
      Edit16: TEdit;
      Edit17: TEdit;
      Edit18: TEdit;
      Edit19: TEdit;
      Edit20: TEdit;
      Edit21: TEdit;
      Edit22: TEdit;
      Edit23: TEdit;
      Edit24: TEdit;
      Edit25: TEdit;
      Edit26: TEdit;
      Edit27: TEdit;
      Edit28: TEdit;
      Button1: TButton;
      Edit29: TEdit;
      Timer1: TTimer;
      Timer2: TTimer;
      ListBox1: TListBox;
      Gauge1: TGauge;
      Gauge2: TGauge;
      Gauge3: TGauge;
      Gauge4: TGauge;
      Label1: TLabel;
      Label2: TLabel;
      Label3: TLabel;
      Label4: TLabel;
      Edit30: TEdit;
      Image1: TImage;
      Label5: TLabel;
      Button2: TButton;
      Timer3: TTimer;
      Button4: TButton;
      Button5: TButton;
      Button3: TButton;
      Label6: TLabel;
      Button6: TButton;
      Timer4: TTimer;
      procedure Timer1Timer(Sender: TObject);
      procedure Button1Click(Sender: TObject);
      procedure Timer2Timer(Sender: TObject);
      procedure Button2Click(Sender: TObject);
      procedure Timer3Timer(Sender: TObject);
      procedure Button3Click(Sender: TObject);
      procedure Button4Click(Sender: TObject);
      procedure Button5Click(Sender: TObject);
      procedure FormCreate(Sender: TObject);
      procedure Button6Click(Sender: TObject);
      procedure Timer4Timer(Sender: TObject);

    private
      { Private declarations }
    public
      { Public declarations }
    end;

  type

  pcb=record
  name:string;
  arv:integer;
  svt:integer;
  stt:integer;
  fnt:integer;
  zzsj:integer;
  dqsj:real;
  fnhflg:bool;
  sttflg:bool;
  end;
  pcbx=array[1..4]of pcb;
  var
  nullflag:bool=false;
  forWord:bool=false;
  subtemp:integer=0;
  j:integer=1;
  openflg:bool=true;
  tempid:integer=1;
  fnhnum:integer=0;
  pcbnum:integer=0;
  ntp:bool=false;
  tempok:bool=false;
    flag:bool=false;
    Form1: TForm1;
    showt:tdatetime;
    count:integer=-1;
    pro:integer=0;
    //pcbnum:integer=1;
    writeflg:integer=0;
    pcbs:pcbx;
  ho,min,sec,msec:Word;
  method:integer=1;
  implementation

  uses  Unit3;

  {$R *.dfm}

  

  
  procedure TForm1.Timer1Timer(Sender: TObject);
  var
  w:integer;
  f:integer;
  begin
  if flag=true and nullflag=false  then      // 改 false 遠為 true
  begin
  count:=count+1;
  listbox1.Items.Add(inttostr(count));

  for w:=1 to 4 do
  begin
  if pcbs[w].arv=count then
  begin
  timer2.Enabled:=false;
  pcbnum:=pcbnum+1;
  timer2.Enabled:=true;
  end;
  end;
  if openflg=false then
  begin
  if (count=pcbs[tempid].stt+pcbs[tempid].svt) then
  begin
  pcbs[tempid].fnhflg:=true;

  fnhnum:=fnhnum+1;
  if fnhnum=4 then
  begin
  flag:=false;
  pcbs[1].fnt:=pcbs[1].stt+pcbs[1].svt;
  pcbs[1].zzsj:=pcbs[1].fnt-pcbs[1].arv;
  pcbs[1].dqsj:=pcbs[1].zzsj/(pcbs[1].fnt-pcbs[1].stt);
  pcbs[2].fnt:=pcbs[2].stt+pcbs[2].svt;
  pcbs[2].zzsj:=pcbs[2].fnt-pcbs[2].arv;
  pcbs[2].dqsj:=pcbs[2].zzsj/(pcbs[2].fnt-pcbs[2].stt);
  pcbs[3].fnt:=pcbs[3].stt+pcbs[3].svt;
  pcbs[3].zzsj:=pcbs[3].fnt-pcbs[3].arv;
  pcbs[3].dqsj:=pcbs[3].zzsj/(pcbs[3].fnt-pcbs[3].stt);
  pcbs[4].fnt:=pcbs[4].stt+pcbs[4].svt;
  pcbs[4].zzsj:=pcbs[4].fnt-pcbs[4].arv;
  pcbs[4].dqsj:=pcbs[4].zzsj/(pcbs[4].fnt-pcbs[4].stt);
  edit13.Text:=inttostr(pcbs[1].stt);
  edit14.Text:=inttostr(pcbs[1].stt+pcbs[1].svt);
  edit15.Text:=inttostr(pcbs[1].zzsj);
  edit16.Text:=floattostr(pcbs[1].dqsj);
  edit17.Text:=inttostr(pcbs[2].stt);
  edit18.Text:=inttostr(pcbs[2].stt+pcbs[2].svt);
  edit19.Text:=inttostr(pcbs[2].zzsj);
  edit20.Text:=floattostr(pcbs[2].dqsj);
  edit21.Text:=inttostr(pcbs[3].stt);
  edit22.Text:=inttostr(pcbs[3].stt+pcbs[3].svt);
  edit23.Text:=inttostr(pcbs[3].zzsj);
  edit24.Text:=floattostr(pcbs[3].dqsj);
  edit25.Text:=inttostr(pcbs[4].stt);
  edit26.Text:=inttostr(pcbs[4].stt+pcbs[4].svt);
  edit27.Text:=inttostr(pcbs[4].zzsj);
  edit28.Text:=floattostr(pcbs[4].dqsj);   
  end;
  openflg:=true;  //改!!!!!true 應為 false
  tempok:=false;
  end;
  end;
  for f:=1 to 4 do
  begin
  if ((count=pcbs[f].stt+pcbs[f].svt) and pcbs[f].fnhflg=true) then
  listbox1.Items.Add(pcbs[f].Name+'完成!!!');
  end; //for
  end;//flag=ture
  if openflg=false then
  begin
  case tempid of
  1:begin
  if pcbs[1].svt=1 then
  begin
  gauge1.MaxValue:=2;
  gauge1.Progress:=2;
  end
  else
  begin
  gauge1.MaxValue:=pcbs[1].svt;
  gauge1.Progress:=count-pcbs[1].stt;
  end;
  end;//1;
  2:begin
  gauge2.MaxValue:=pcbs[2].svt;
  gauge2.Progress:=count-pcbs[2].stt;
  end;//2;
  3:begin
  gauge3.MaxValue:=pcbs[3].svt;
  gauge3.Progress:=count-pcbs[3].stt;
  end;//3;
  4:begin
  gauge4.MaxValue:=pcbs[4].svt;
  gauge4.Progress:=count-pcbs[4].stt;
  end; //4;
  end;//case of over
  end;// if openflg=false then over
  if pcbs[1].fnhflg=true then
  gauge1.Progress:=pcbs[1].svt;
  if pcbs[2].fnhflg=true then
  gauge2.Progress:=pcbs[2].svt;
  if pcbs[3].fnhflg=true then
  gauge3.Progress:=pcbs[3].svt;
  if pcbs[4].fnhflg=true then
  gauge4.Progress:=pcbs[4].svt;

  end;//procedure over
  procedure TForm1.Button1Click(Sender: TObject);
  begin
  button2.Enabled:=false;
  timer3.Enabled:=false;
  timer2.Enabled:=true;
  timer1.Enabled:=true;
  timer4.Enabled:=false;
  try
  flag:=true;
  pcbs[1].name:=edit1.text;
  pcbs[1].arv:=strtoint(edit2.text );
  pcbs[1].svt:=strtoint(edit3.text );
  pcbs[1].sttflg:=false;
  pcbs[1].fnhflg:=false;
  pcbs[2].name:=edit4.text;
  pcbs[2].arv:=strtoint(edit5.text );
  pcbs[2].svt:=strtoint(edit6.text );
  pcbs[2].sttflg:=false;
  pcbs[2].fnhflg:=false;
  pcbs[3].name:=edit7.text;
  pcbs[3].arv:=strtoint(edit8.text );
  pcbs[3].svt:=strtoint(edit9.text );
  pcbs[3].sttflg:=false;
  pcbs[3].fnhflg:=false;
  pcbs[4].name:=edit10.text;
  pcbs[4].arv:=strtoint(edit11.text );
  pcbs[4].svt:=strtoint(edit12.text );
  pcbs[4].sttflg:=false;
  pcbs[4].fnhflg:=false;
  nullflag:=false;
  except
  nullflag:=true;
  showmessage('請將數據填完整');
  end;
  end;

  procedure TForm1.Timer2Timer(Sender: TObject);
  var
  i:integer;
  begin
  if fnhnum<pcbnum then
  begin
  if ((openflg=true) and (pcbnum>0)) then
  begin
  for i:=1 to pcbnum do
  begin
  if pcbs[i].fnhflg=false then
  begin
  if tempok=false then
  begin
  subtemp:=tempid;
  tempid:=i;
  tempok:=true;
  end;
  if pcbs[i].svt<pcbs[tempid].svt then
  begin
  //timer1.Enabled:=false;
  tempid:=i;
  //timer1.Enabled:=true;
  end;//if pcbs[i].svt<pcbs[tempid].svt then
  end;//for
  end;
  openflg:=false;
  pcbs[tempid].stt:=count;
  pcbs[tempid].sttflg:=true;
  //listbox1.Items.Add('進程'+pcbs[subtemp].name+'fnh');
  listbox1.Items.Add('進程'+pcbs[tempid].name+'被調度');
  end;//if(openflg=true and pcbnum>0)then
  end;//if fnhnum<pcbnum then

  end; //procedure

  procedure TForm1.Button2Click(Sender: TObject);
  begin
  button1.Enabled:=false;
  timer1.Enabled:=false;
  timer2.Enabled:=false;
  timer3.Enabled:=true;
  timer4.Enabled:=true;
  try
  flag:=true;
  pcbs[1].name:=edit1.text;
  pcbs[1].arv:=strtoint(edit2.text );
  pcbs[1].svt:=strtoint(edit3.text );
  pcbs[1].sttflg:=true;
  pcbs[1].fnhflg:=false;
  pcbs[2].name:=edit4.text;
  pcbs[2].arv:=strtoint(edit5.text );
  pcbs[2].svt:=strtoint(edit6.text );
  pcbs[2].sttflg:=false;
  pcbs[2].fnhflg:=false;
  pcbs[3].name:=edit7.text;
  pcbs[3].arv:=strtoint(edit8.text );
  pcbs[3].svt:=strtoint(edit9.text );
  pcbs[3].sttflg:=false;
  pcbs[3].fnhflg:=false;
  pcbs[4].name:=edit10.text;
  pcbs[4].arv:=strtoint(edit11.text );
  pcbs[4].svt:=strtoint(edit12.text );
  pcbs[4].sttflg:=false;
  pcbs[4].fnhflg:=false;
  nullflag:=false;
  except
  nullflag:=true;
  showmessage('請將數據填完整');
  end;
  end;

  procedure TForm1.Timer3Timer(Sender: TObject);
  var
  m:integer;

  
  begin

  if ((flag=true )and (ntp=false)and (nullflag=false)) then
  begin//if falg=true then
  count:=count+1;

  listbox1.Items.Add(inttostr(count));
  for m:=1 to 4do
  begin //for m:=1 to 5 do
  if((pcbs[m].sttflg=true) and (pcbs[m].fnhflg=false))then
  begin//if(pcb[m].sttflg=true and pcb[m].fnhflg=false)
  if count=pcbs[m].stt+pcbs[m].svt then
  begin//if (count=pcbs[m].stt+pcbs[m].svt)then
  pcbs[m].fnhflg:=true;
  //timer4.Enabled:=false;
  pro:=0;

  //timer4.Enabled:=true;
  listbox1.Items.Add('進程:'+pcbs[m].name+'完成!!');
  if m<4 then
  begin//if m<4 then
  //pcbs[m+1].sttflg:=true;
  //pcbs[m+1].stt:=count;
  forWord:=true;
  end;//if m<4 then
  pcbs[m].fnt:=count;
  pcbs[m].zzsj:=pcbs[m].fnt-pcbs[m].arv;
  pcbs[m].dqsj:=pcbs[m].zzsj/(pcbs[m].fnt-pcbs[m].stt);
  end;//if (count=pcbs[m].stt+pcbs[m].svt)then
  end;//if(pcb[m].sttflg=true and pcb[m].fnhflg=false)
  end;//for m:=1 to 5 do

  if pcbs[4].fnhflg=true then
  begin
  ntp:=true;
  edit13.Text:=inttostr(pcbs[1].stt);
  edit14.Text:=inttostr(pcbs[1].stt+pcbs[1].svt);
  edit15.Text:=inttostr(pcbs[1].zzsj);
  edit16.Text:=floattostr(pcbs[1].dqsj);
  edit17.Text:=inttostr(pcbs[2].stt);
  edit18.Text:=inttostr(pcbs[2].stt+pcbs[2].svt);
  edit19.Text:=inttostr(pcbs[2].zzsj);
  edit20.Text:=floattostr(pcbs[2].dqsj);
  edit21.Text:=inttostr(pcbs[3].stt);
  edit22.Text:=inttostr(pcbs[3].stt+pcbs[3].svt);
  edit23.Text:=inttostr(pcbs[3].zzsj);
  edit24.Text:=floattostr(pcbs[3].dqsj);
  edit25.Text:=inttostr(pcbs[4].stt);
  edit26.Text:=inttostr(pcbs[4].stt+pcbs[4].svt);
  edit27.Text:=inttostr(pcbs[4].zzsj);
  edit28.Text:=floattostr(pcbs[4].dqsj);
  end;
  for m:=1 to 4 do
  begin
  if ((count>=pcbs[m].arv) and (pcbs[m].sttflg=false))  then
  if forWord=true then
  begin
  pcbs[m].sttflg:=true;
  pcbs[m].stt:=count;
  forWord:=false;
  end;//3and
  end;// for m:=1 to 4 do
  gauge1.MaxValue:=pcbs[1].svt;
  gauge2.MaxValue:=pcbs[2].svt;
  gauge3.MaxValue:=pcbs[3].svt;
  gauge4.MaxValue:=pcbs[4].svt;
  if pcbs[1].sttflg=true and  pcbs[1].fnhflg=false then
  begin
  //gauge1.Progress:=gauge1.MaxValue:=pcbs[1].svt;
  gauge1.Progress:=count-pcbs[1].stt;
  end// if pcbs[1].sttflg=true and  pcbs[1].fnhflg=false then
  else if pcbs[1].fnhflg=true then
  gauge1.Progress:=pcbs[1].svt;
  if pcbs[2].sttflg=true and  pcbs[2].fnhflg=false then
  begin
  gauge2.Progress:=count-pcbs[2].stt;
  end// if pcbs[1].sttflg=true and  pcbs[1].fnhflg=false then
  else if pcbs[2].fnhflg=true then
  gauge2.Progress:=pcbs[2].svt;

  
  if pcbs[3].sttflg=true and  pcbs[3].fnhflg=false then
  begin
  gauge3.Progress:=count-pcbs[3].stt;
  end// if pcbs[1].sttflg=true and  pcbs[1].fnhflg=false then
  else if pcbs[3].fnhflg=true then
  gauge3.Progress:=pcbs[3].svt;

  
  if pcbs[4].sttflg=true and  pcbs[4].fnhflg=false then
  begin
  gauge4.Progress:=count-pcbs[4].stt;
  end// if pcbs[1].sttflg=true and  pcbs[1].fnhflg=false then
  else if pcbs[4].fnhflg=true then
  gauge4.Progress:=pcbs[4].svt;
  end; //if falg=true then

  

  
  end;//procedure over

  procedure TForm1.Button3Click(Sender: TObject);
  begin
  form1.Close;
  //end.//do over
  end;
  procedure TForm1.Button4Click(Sender: TObject);
  begin
  forWord:=false;
  subtemp:=0;
  j:=1;
  openflg:=true;
  tempid:=1;
  fnhnum:=0;
  pcbnum:=0;
  ntp:=false;
  tempok:=false;
  flag:=false;
  gauge1.Progress:=0;
  gauge2.Progress:=0;
  gauge3.Progress:=0;
  gauge4.Progress:=0;
  button2.Enabled:=true;
  button1.Enabled:=true;
  count:=-1;
  pro:=0;
    //pcbnum:integer=1;
  writeflg:=0;
  flag:=false;
  nullflag:=false;
  edit1.Text:='';
  edit2.Text:='';
  edit3.Text:='';
  edit4.Text:='';
  edit5.Text:='';
  edit6.Text:='';
  edit7.Text:='';
  edit8.Text:='';
  edit9.Text:='';
  edit10.Text:='';
  edit11.Text:='';
  edit12.Text:='';
  edit13.Text:='系統填寫';
  edit14.Text:='系統填寫';

  
  edit15.Text:='系統填寫';
  edit16.Text:='系統填寫';
  edit17.Text:='系統填寫';
  edit18.Text:='系統填寫';
  edit19.Text:='系統填寫';
  edit20.Text:='系統填寫';
  edit21.Text:='系統填寫';
  edit22.Text:='系統填寫';
  edit23.Text:='系統填寫';
  edit24.Text:='系統填寫';
  edit25.Text:='系統填寫';
  edit26.Text:='系統填寫';
  edit27.Text:='系統填寫';
  edit28.Text:='系統填寫';
  pcbs[1].fnhflg:=false;
  pcbs[1].sttflg:=false;
  pcbs[2].fnhflg:=false;
  pcbs[2].sttflg:=false;
  pcbs[3].fnhflg:=false;
  pcbs[3].sttflg:=false;
  pcbs[4].fnhflg:=false;
  pcbs[4].sttflg:=false;
  end;

  
  procedure TForm1.Button5Click(Sender: TObject);
  begin
  form3.show;

  end;

  procedure TForm1.FormCreate(Sender: TObject);
  begin
  form1.FormStyle:=fsstayontop;
  animatewindow(handle,2000,AW_center);
  form1.FormStyle:=fsnormal;
  end;

  procedure TForm1.Button6Click(Sender: TObject);
  begin
  edit1.Text:='A';
  edit2.Text:='0';
  edit3.Text:='3';
  edit4.Text:='B';
  edit5.Text:='5';
  edit6.Text:='2';
  edit7.Text:='C';
  edit8.Text:='5';
  edit9.Text:='3';
  edit10.Text:='D';
  edit11.Text:='5';
  edit12.Text:='2';
  end;

  procedure TForm1.Timer4Timer(Sender: TObject);
  begin
  if ((pcbs[1].arv=count) and  (pcbs[1].sttflg=false))  then
  begin
  forWord:=true;
  end;
  end;

  end.

  unit Unit2;

  interface

  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, jpeg, ExtCtrls, StdCtrls;

  type
    TForm2 = class(TForm)
      Image1: TImage;
      Label1: TLabel;
      Label2: TLabel;
      Label3: TLabel;
    private
      { Private declarations }
    public
      { Public declarations }
    end;
    type

  pcb=record
  name:string;
  arv:integer;
  svt:integer;
  stt:integer;
  fnt:integer;
  zzsj:integer;
  dqsj:real;
  fnhflg:bool;
  sttflg:bool;
  end;
  pcbx=array[1..4]of pcb;

  var
    Form2: TForm2;
    pcbs:pcbx;
  implementation
  uses Unit1;
  {$R *.dfm}

  end.
  unit Unit3;

  interface

  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ComCtrls, jpeg, ExtCtrls;

  type
    TForm3 = class(TForm)
      RichEdit1: TRichEdit;
    private
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form3: TForm3;

  implementation

  {$R *.dfm}

  end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved