Скачиваний:
4
Добавлен:
01.05.2014
Размер:
9.02 Кб
Скачать
unit Sistol;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, Grids, Tabs, ImgList;

const NUM_STUP = 9;
MATRIX_SIZE = 5;

type

TProcessElem = class
public
A,X,Y,YNew:integer;
ACh,XCh,YCh,YNewCh:string;
Empty: boolean;
Constructor Create;
procedure ShowElem(ProcessElemGrid:TStringGrid; FlagCh:Boolean);
procedure SetElem (A0, X0, Y0, YNew0:integer);
procedure SetElemCh(ACh0,XCh0,YCh0,YNewCh0:string);
procedure SetNull;
procedure CalcYNew;
end;

TTableElem = class
public
A:integer;
ACh: string;
Empty: boolean;
Constructor Create;
function StrElemStr(FlagCh:Boolean):string;
procedure SetNull;
end;

TSistolSystem = class
public
TableGrid:TStringGrid;
ProcessElemSGrid : array [1..NUM_STUP] of TStringGrid;
Step:integer;
MatrixA : array[1..MATRIX_SIZE,1..MATRIX_SIZE] of integer;
MatrixACh : array[1..MATRIX_SIZE,1..MATRIX_SIZE] of string;
VectorX : array[1..MATRIX_SIZE] of integer;
VectorXCh : array[1..MATRIX_SIZE] of string;
VectorY : array[1..MATRIX_SIZE] of integer;
VectorYCh : array[1..MATRIX_SIZE] of string;
VectorYCur : array[1..MATRIX_SIZE] of integer;
ProcessElemS : array [1..NUM_STUP] of TProcessElem;
TableElemS : array [1..NUM_STUP,1..NUM_STUP] of TTableElem;
constructor Create;
destructor Destroy;
procedure ShowSystem(FlagCh:boolean);
procedure AllHide;
procedure AllShow;
procedure GoStart;
procedure GoNext;
procedure GoStep(NewStep: integer);
procedure GoPred;
end;


implementation

{ TProcessElem }

constructor TProcessElem.Create;
begin
A:=-1; X:=-1; Y:=-1; YNew:=-1;
ACh:=''; XCh:=''; YCh:=''; YNewCh:='';
Empty := true;
end;
procedure TProcessElem.ShowElem(ProcessElemGrid:TStringGrid; FlagCh:Boolean);
begin
with ProcessElemGrid do begin
if not empty then begin
if FlagCh then begin
Cells[0,0] := ACh;
Cells[1,0] := XCh;
Cells[0,1] := YNewCh;
Cells[1,1] := YCh;
end else begin
if A<>-1 then Cells[0,0] := ' ' + inttostr(A) else Cells[0,0]:='';
if X<>-1 then Cells[1,0] := inttostr(X) else Cells[1,0]:='';
if YNew<>-1 then Cells[0,1] := inttostr(YNew) else Cells[0,1]:='';
if Y<>-1 then Cells[1,1] := inttostr(Y) else Cells[1,1]:='';
end
end else begin
Cells[0,0] := '';
Cells[1,0] := '';
Cells[0,1] := '';
Cells[1,1] := '';
end;
end;
end;
procedure TProcessElem.SetElem (A0, X0, Y0, YNew0:integer);
begin
A := A0; X := X0; Y := Y0; YNew := YNew0;
end;
procedure TProcessElem.SetElemCh (ACh0,XCh0,YCh0,YNewCh0:string);
begin
ACh := ACh0;
XCh := XCh0;
YCh := YCh0;
YNewCh := YNewCh0;
end;
procedure TProcessElem.SetNull;
begin
SetElemCh('','','','');
SetElem(-1,-1,-1,-1);
Empty:=true;
end;
procedure TProcessElem.CalcYNew;
begin
if (Y<>-1) then
if (X<>-1)and(A<>-1) then YNew := Y + A*X else YNew := Y
end;

{ TTableElem }

constructor TTableElem.Create;
begin
A:=-1; ACh:=''; Empty := true;
end;
function TTableElem.StrElemStr(FlagCh:Boolean):string;
begin
if not empty then
if FlagCh then
result := ACh
else
if A<>-1 then result := ' '+inttostr(A) else result := ''
else result := '';
end;
procedure TTableElem.SetNull;
begin
A:=-1; ACh:='';
Empty:=true;
end;

{ TSistolSystem }

constructor TSistolSystem.Create;
var i,j: integer;
begin
Step := 0;
TableGrid := nil;
for j:= 1 to NUM_STUP do begin
ProcessElemSGrid[j] := nil;
ProcessElemS[j] := TProcessElem.Create;
for i:= 1 to NUM_STUP do begin
TableElemS[i,j] := TTableElem.Create;
end;
end;
for j:= 1 to MATRIX_SIZE do begin
VectorXCh[j] := 'x' + inttostr(j);
VectorX[j] := 0;
VectorYCh[j] := 'y' + inttostr(j);
VectorY[j] := 0;
VectorYCur[j] := 0;
for i:= 1 to MATRIX_SIZE do begin
MatrixACh[i,j] := 'a' + inttostr(i) + inttostr(j);
MatrixA[i,j] := 0;
end;
end;
end;

destructor TSistolSystem.Destroy;
begin
//
end;

procedure TSistolSystem.AllHide;
var i,j: integer;
begin
for j := 1 to NUM_STUP do begin
ProcessElemS[j].empty := true;
for i:= 1 to NUM_STUP do TableElemS[i,j].Empty := true;
end;
end;
procedure TSistolSystem.AllShow;
var i,j: integer;
begin
for j := 1 to NUM_STUP do begin
ProcessElemS[j].empty := false;
for i:= 1 to NUM_STUP do TableElemS[i,j].Empty := false;
end;
end;

procedure TSistolSystem.GoStart;
var i,j,l,k,col,row: integer;
begin
//AllHide;
for i := 1 to NUM_STUP do ProcessElemS[i].SetNull;
for j := 1 to NUM_STUP do
for i := 1 to NUM_STUP do TableElemS[i,j].SetNull;



Step := 0;
ProcessElemS[2].SetElemCh('',VectorXCh[2],'','');
ProcessElemS[2].SetElem (-1,VectorX [2],-1,-1);
ProcessElemS[2].Empty := false;
ProcessElemS[4].SetElemCh('',VectorXCh[1],'','');
ProcessElemS[4].SetElem (-1,VectorX [1],-1,-1);
ProcessElemS[4].Empty := false;
ProcessElemS[6].SetElemCh('','',VectorYCh[1],'');
ProcessElemS[6].SetElem (-1,-1,VectorY [1],0); //VectorY[1] = 0
ProcessElemS[6].Empty := false;
ProcessElemS[8].SetElemCh('','',VectorYCh[2],'');
ProcessElemS[8].SetElem (-1,-1,VectorY [2],0); //VectorY[2] = 0
ProcessElemS[8].Empty := false;
for i := 1 to MATRIX_SIZE do
for j := 1 to MATRIX_SIZE do begin
row := 11 - (i+j);
col := 5 + (i-j);
TableElemS[row,col].A := MatrixA [i,j];
TableElemS[row,col].ACh := MatrixACh[i,j];
TableElemS[row,col].Empty := false;
end;
for i := 1 to MATRIX_SIZE do VectorYCur[i] := 0;
end;

procedure TSistolSystem.GoNext;
var i,j,l,k,col,row: integer;
begin
if Step>=15 then exit;

inc(Step);

// Матричные эл-ты входят в конвейер
for j := 1 to NUM_STUP do
if (not TableElemS[NUM_STUP,j].Empty) then
begin
ProcessElemS[j].A := TableElemS[NUM_STUP,j].A; {_v2}
ProcessElemS[j].ACh := TableElemS[NUM_STUP,j].ACh;
end;
// Матричные эл-ты опускаются
for j := 1 to NUM_STUP do
for i := NUM_STUP downto 2 do begin
if TableElemS[i,j].Empty then
begin
TableElemS[i,j].A := TableElemS[i-1,j].A; {_v2}
TableElemS[i,j].ACh := TableElemS[i-1,j].ACh;
end;
end;
// Матричные эл-ты перекрашиваются
for j := 1 to NUM_STUP do
for i := 1 to NUM_STUP do begin
if Odd(Step+i+j) then TableElemS[i,j].SetNull
else TableElemS[i,j].Empty := false;
end;


// Переносим Y-ки
for i := 1 to NUM_STUP-1 do
if ProcessElemS[i].Empty then
begin
if ProcessElemS[i+1].YNew <>-1 then ProcessElemS[i].Y := ProcessElemS[i+1].YNew;//_v2
ProcessElemS[i].YCh := ProcessElemS[i+1].YCh;
end;
// Переносим X-сы
for i := NUM_STUP downto 2 do
if ProcessElemS[i].Empty then
begin
ProcessElemS[i].X := ProcessElemS[i-1].X; //_v2
ProcessElemS[i].XCh := ProcessElemS[i-1].XCh;
end;
// Входящие на конвейер
if (step<=5)and Odd(Step) then begin
ProcessElemS[9].YCh := VectorYCh[(step div 2)+3];
ProcessElemS[1].XCh := VectorXCh[(step div 2)+3];
ProcessElemS[9].Y := VectorY [(step div 2)+3];//_v2
ProcessElemS[9].YNew:= 0; //_v2
ProcessElemS[1].X := VectorX [(step div 2)+3];//_v2
end;
// No comment
for i := 1 to NUM_STUP do
if ProcessElemS[i].Empty then ProcessElemS[i].CalcYNew;

// Ищем текущие YCur
if Step in [0..5] then VectorYCur[1] := ProcessElemS[ 6-Step].YNew;
if Step in [0..7] then VectorYCur[2] := ProcessElemS[ 8-Step].YNew;
if Step in [1..9] then VectorYCur[3] := ProcessElemS[10-Step].YNew;
if Step in [3..11] then VectorYCur[4] := ProcessElemS[12-Step].YNew;
if Step in [5..13] then VectorYCur[5] := ProcessElemS[14-Step].YNew;


///ProcessElemS[9].Empty := ProcessElemS[8].YCh <> '';
//if ProcessElemS[8].YCh <> '' then ProcessElemS[9].SetNull;


for i := 1 to NUM_STUP do
if Odd(Step+i) then ProcessElemS[i].SetNull
else ProcessElemS[i].Empty := false;


end;

procedure TSistolSystem.GoStep(NewStep: integer);
var i,j: integer;
begin
if NewStep = 0 then GoStart;
if (NewStep>0)and(NewStep<15) then begin
GoStart;
for i := 1 to NewStep do GoNext;
end;
end;

procedure TSistolSystem.GoPred;
begin
GoStep(Step-1);
end;

procedure TSistolSystem.ShowSystem(FlagCh:boolean);
var i,j: integer;
begin
for j := 1 to NUM_STUP do begin
ProcessElemS[j].ShowElem(ProcessElemSGrid[j], FlagCh);
for i:= 1 to NUM_STUP do TableGrid.Cells[2*(j-1),2*(i-1)] := TableElemS[i,j].StrElemStr(FlagCh);;
end;
end;

end.
Соседние файлы в папке Лабораторная работа