Procedure TMainGraf.Image1MouseMove(Sender: TObject; Shift: TShiftState; X

Y: Integer);

begin

if checkBox1.Checked then begin

if (MouseDowning) AND (MouseDowning) then begin //Label4.Caption:='('+inttostr(X)+','+inttostr(Y)+')';

if UsingPoint<=vershina-1 then begin

masX[UsingPoint]:=X;

masY[UsingPoint]:=Y;

Visualization(MainGraf.image1.Canvas,2);

end;

end;

end;

end;

//-------------------------------------------------------------

procedure TMainGraf.Image1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

Timer1.Enabled:=true;

MouseMoving:=false;

MouseDowning:=false;

end;

//-------------------------------------------------------------

procedure TMainGraf.Button2Click(Sender: TObject);

begin

close;

end;

//------------------------------------------------------------- procedure TMainGraf.Button1Click(Sender: TObject);

var i,j: integer;

begin

PageControl1.TabIndex:=1;

MouseDowning:=false;

Label3.Caption:='';;

UsingPoint:=255;

//ЗАДАЕМ КОЛИЧЕСТВО ВЕРШИН И ИНИЦИАЛИЗИРУЕМ МАССИВЫ

//считываем количество вершин

try

Vershina:=StrToInt(Edit1.text);

if StrToInt(Edit1.text)>255 then

begin

Edit1.text:='255';

Vershina:=255;

end;

except

begin

Vershina:=2;

Edit1.text:='2';

end;

end;

PageControl1.Visible:=true;

//ВВОД НАЧАЛЬНЫХ ПАРАМЕТРОВ ГРАФА

if Vershina<2 then Vershina:=2;

if Vershina>255 then Vershina:=255;

StringGrid1.RowCount:=Vershina+1;

StringGrid2.RowCount:=Vershina+1;

StringGrid1.ColCount:=Vershina+1;

StringGrid2.ColCount:=Vershina+1;

//задаем длину массива точек

SetLength(MasX, Vershina);

SetLength(MasY, Vershina);

SetLength(GroupKS, Vershina);

SetLength(PS, Vershina);

For i:=1 to Vershina do

begin

PS[i-1]:=0;

StringGrid1.Cells[0,i]:=IntToStr(i);

StringGrid1.Cells[i,0]:=IntTostr(i);

end;

if i<21 then begin

StringGrid1.Height:=(i)*25+3;

StringGrid1.Width:=(i)*25+3;

end

else

begin

StringGrid1.Height:=481;

StringGrid1.Width:=441;

end;

//0-ЛИ НА ГЛАВНОЙ ДИАГОНАЛИ

For i:=1 to Vershina do

begin

StringGrid1.Cells[i,i]:='0';

end;

end;

//-------------------------------------------------------------

procedure TMainGraf.FormCreate(Sender: TObject);

var

i,j: integer;

a,b,c: byte;

F: textFile;

S: string;

begin

try

Label20.Caption:='';

AssignFile(f,'help.txt');

Reset(f);

while (Not EOF(F)) do

begin

Readln(f,s);

Label20.Caption:=Label20.Caption+s+#13;

end;

closeFile(F);

except

ShowMessage('Не найден файл справки');

end;

ShowGraf:=false;

CSEl:=0;

RSel:=0;

_TypeOV:=0;

randomize;

ClrOfP[0]:=ColorBox7.Selected;

for i:=1 to 256 do begin

a:=random(255);

b:=random(255);

c:=random(255);

ClrOfP[i]:=RGB(a,b,c);

for j:=1 to 25 do

begin Image3.Canvas.Pixels[i*2-1,j]:=ClrOfP[i];

Image3.Canvas.Pixels[(i)*2,j]:=ClrOfP[i];

end;

end;

CountDel:=18;

Memo1.ReadOnly:=true;

Edit2.Focused;

CenterX:=240;

CenterY:=240;

PageControl1.TabIndex:=0;

RadioGroup1.ItemIndex:=0;

RadioGroup2.ItemIndex:=0;

//ЗАКРАСКА ПОПИКСЕЛЬНО ИЗОБРАЖЕНИЯ БЕЛЫМ ФОНОМ

For i:=0 to Maingraf.ClientHeight do

For j:=0 to MainGraf.ClientWidth do

MainGraf.Canvas.Pixels[i,j]:=clWhite;

Edit1.Focused;

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton5Click(Sender: TObject);

var

TypeG: boolean;

begin

typeG:=true;

Reach();

For i:=1 to Vershina do

For j:=1 to vershina do

if R1[i,j]=0 then typeG:=false;

if typeG then

begin

Memo1.Clear; Memo1.Lines.Add('Данные о графе:');

Memo1.Lines.Add('Данный граф СВЯЗНЫЙ');

end

else begin

Memo1.Clear; Memo1.Lines.Add('Данные о графе:');

Memo1.Lines.Add('Данный граф НЕ СВЯЗНЫЙ');

end;

end;

//-------------------------------------------------------------

procedure TMainGraf.PageControl1Change(Sender: TObject);

begin

If PageControl1.TabIndex=1 then button1.Click;

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton7Click(Sender: TObject);

var z: integer;

begin

k:=false;

SetLength(mark, Vershina);

SetLength(Emark, Vershina);

try

z:=strtoint(Edit2.text);

except

z:=1;

end;

For j:=0 to Vershina-1 do begin mark[j]:=0; Emark[j]:=1; end;

mark[z-1]:=1;

Emark[z-1]:=0;

c:=1;

Memo1.Clear;

Memo1.Lines.Add('Обход в ширину, начиная с вершины: '+'('+inttostr(z)+')'+':');

Memo1.Text:=Memo1.Text+inttostr(z);

recursiya(z);

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton4Click(Sender: TObject);

var

i: integer;

begin

For i:=1 to Vershina do

For j:=1 to Vershina do

if (StringGrid1.Cells[i,j]<>'1') and (StringGrid1.Cells[i,j]<>'0') then StringGrid1.Cells[i,j]:='0';

if Not ShowGraf then SpeedButton2.Click;

Timer1.Interval:=1;

Timer1.Interval:=1000;

ExceptionV:=0;

FindKS(1);

_TypeOV:=2;

Visualization(MainGraf.Image1.Canvas, 2);

_TypeOV:=0;

For i:=0 to Vershina-1 do GroupKs[i]:=0;

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton3Click(Sender: TObject);

var

a,b: integer;

k: integer;

b1: boolean;

begin

Timer1.Interval:=1;

Timer1.Interval:=1000;

if Not ShowGraf then SpeedButton2.Click;

Memo1.Clear;

Memo1.Lines.Add('Точки сочленения:');

for i:=1 to vershina do

begin

PS[i-1]:=0;

for j:=1 to vershina do

StringGrid2.Cells[i,j]:=StringGrid1.Cells[i,j];

ExceptionV:=0;

end;

a:=FindKS(2);

For k:=1 to Vershina do

begin

ExceptionV:=k;

for i:=1 to Vershina do

for j:=1 to Vershina do

StringGrid2.Cells[i,j]:=StringGrid1.Cells[i,j];

for i:=1 to Vershina do

begin

StringGrid2.Cells[ExceptionV,i]:='0';

StringGrid2.Cells[i,ExceptionV]:='0';

end;

b:=FindKS(2);

if a<>b then

begin

Memo1.lines.Add('Вершина: '+inttostr(ExceptionV)+' - точка сочленения, число компонентов связности изменилось до '+inttostr(b));

PS[k-1]:=1;

end

else Memo1.lines.Add('Вершина: '+inttostr(ExceptionV)+ ' - не является точкой сочленения');

end;

Memo1.lines.Add('Таким образом, точки сочленения: ');

For i:=1 to Vershina do if PS[i-1]=1 then Memo1.Text:=Memo1.text+'('+inttostr(i)+')'+' ';

For i:=1 to Vershina do if PS[i-1]=1 then b1:=true;

if Not B1 then Memo1.Text:=Memo1.text+'отсутствуют.';

_TypeOV:=1;

Visualization(MainGraf.Image1.Canvas,2);

_TypeOV:=0;

For i:=0 to Vershina-1 do PS[i]:=0;

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton6Click(Sender: TObject);

var

TypeG: boolean;

a,k,b: integer;

PSP: array of integer; //масси тпа вершины (со связями или нет)

empty: boolean; //относится к массиву выше.

MAXGroups: byte; //число компонент связности, без точек сочленения

consist: boolean; //есть ли дуги из вершины

colKD: byte; //Число компонент двусвязнсти

begin

For i:=1 to Vershina do

For j:=1 to Vershina do

if (StringGrid1.Cells[i,j]<>'1') and (StringGrid1.Cells[i,j]<>'0') then StringGrid1.Cells[i,j]:='0';

if Not ShowGraf then SpeedButton2.Click;

Timer1.Interval:=1;

Timer1.Interval:=1000;

colKD:=0;

setLEngth(PSP, Vershina);

for i:=1 to vershina do

begin

PSP[i-1]:=0;

PS[i-1]:=0;

for j:=1 to vershina do

StringGrid2.Cells[i,j]:=StringGrid1.Cells[i,j];

ExceptionV:=0;

end;

a:=FindKS(2);

For k:=1 to Vershina do

begin

ExceptionV:=k;

for i:=1 to Vershina do

for j:=1 to Vershina do

StringGrid2.Cells[i,j]:=StringGrid1.Cells[i,j];

for i:=1 to Vershina do

begin

StringGrid2.Cells[ExceptionV,i]:='0';

StringGrid2.Cells[i,ExceptionV]:='0';

end;

b:=FindKS(2);

if a<>b then PS[k-1]:=1;

end;

typeG:=true;

For i:=1 to Vershina do if PS[i-1]=1 then typeG:=false;

//-------------------------------------------------------------

Memo1.Clear;

Memo1.Lines.Add('Компоненты двусвязности:');

//----------//нет точек сочленения-----------------

if typeG then

begin

typeG:=true;

Reach();

For i:=1 to Vershina do

For j:=1 to vershina do

if R1[i,j]=0 then typeG:=false;

if typeG then

begin

Memo1.Lines.Add('В данном графе всего одна компонента двусвязности,');

Memo1.Lines.Add('равная самому графу:');

For i:=1 to Vershina do

begin

if i=1 then

Memo1.Text:=Memo1.Text+'({ '+IntToStr(i)+' '

else

if i=Vershina then

Memo1.Text:=Memo1.Text+IntToStr(i)+' })'

else

Memo1.Text:=Memo1.Text+IntToStr(i)+' '

end;

end;

GroupKS[Vershina-1]:=1;

_TypeOV:=2;

Visualization(MainGraf.Image1.Canvas,2);

end

//------------есть точки сочленения----------------

else

begin

For i:=1 to Vershina do

begin

empty:=true;

PSP[i-1]:=0;

if PS[i-1]=1 then

begin

PSP[i-1]:=1;

for j:=1 to Vershina do

if StringGrid1.Cells[i,j]='1' then empty:=false;

if Not empty then PSP[i-1]:=1 else PSP[i-1]:=-1;

end;

end;

FindKS(3); //точки сочленения помечены 0-ми

{остальные вершины разбиты на группы компонентов связности, исключая сами точки

в массиве PSP выедены типы точек сочленения 1 если т.с. и -1 иначе и 0 если просто вершина}

if Vershina<=9 then begin

for i:=1 to Vershina do

begin

Memo1.Text:=Memo1.Text+' '+inttostr(i)+' ';

if i=Vershina then Memo1.Text:=Memo1.Text+'| - № вершины';

end;

Memo1.Lines.Add('');

//

for i:=1 to Vershina do

begin

if PS[i-1]=1 then Memo1.Text:=Memo1.Text+' 1 ' else Memo1.Text:=Memo1.Text+' 0 ';

if i=Vershina then Memo1.Text:=Memo1.Text+'| - 1 если вершина точка сочленения';

end;

Memo1.Lines.Add('');

for i:=1 to Vershina do

begin

if PSP[i-1]=1 then Memo1.Text:=Memo1.Text+' 1 '

else

if PSP[i-1]=-1 then Memo1.Text:=Memo1.Text+' 2 '

else

Memo1.Text:=Memo1.Text+' 0 ';

if i=Vershina then Memo1.Text:=Memo1.Text+'| - 2 если данная вершина не связана с другими';

end;

Memo1.Lines.Add('');

for i:=1 to Vershina do

begin

Memo1.Text:=Memo1.Text+' '+inttostr(GroupKS[i-1])+' ';

if i=Vershina then Memo1.Text:=Memo1.Text+'| - группы связных вершин, 0 - точки сочленения';

end;

Memo1.Lines.Add('На основе этих данных легко разбить граф на двусвязные компоненты.');

end;

_TypeOV:=2;

Visualization(MainGraf.Image1.Canvas,2);

_TypeOV:=0;

//определить точки сочления: найднеы выше (+)

// и выделить компоненты связности исключая вершины (+)

//используя правила нахождения по обходу в глубину...(+)

//выписать двусвязные компоненты (+).

//PS

//PSP/

//GroupKS

//-------------------------------------------------------------MaxGroups:=0;

For i:=1 to Vershina do if (GroupKs[i-1]>=MaxGroups) then MaxGroups:=GroupKs[i-1];

//Memo1.Lines.add('');

Memo1.text:=Memo1.text+'(';

For i:=1 to MaxGroups do

begin

Memo1.text:=Memo1.text+'{';

Inc(colKD);

// добавленние явно входящих в группу вершин

For j:=1 to Vershina do

if GroupKs[j-1]=i then Memo1.text:=Memo1.text+' '+inttostr(j);

//добавление точек сочленения

For j:=1 to Vershina do

begin

if (GroupKs[j-1]=0) and (PSP[j-1]=1) then

begin

consist:=false;

For k:=1 to Vershina do

begin

if (GroupKS[k-1]=i) and (StringGrid1.cells[k,j]='1') then

begin

consist:=true;

//break;

end;

if consist then begin Memo1.text:=Memo1.text+' '+inttostr(j); break; end;

end;

end;

if j=Vershina then Memo1.text:=Memo1.text+' } ';

end;

end;

//добавление связных точек сочленения как компонент двусвязности

For k:=1 to Vershina do

begin

if PSP[k-1]=1 then

begin

for j:=1 to Vershina do if (k>j) and (PSP[j-1]=1) then

begin

if StringGrid1.Cells[k,j]='1' then

begin

Memo1.text:=Memo1.Text+'{'+inttostr(j)+' '+inttostr(k)+'} ';

Inc(colKD);

end;

end;

end;

end;

Memo1.text:=Memo1.text+')';

Memo1.Lines.Add('Число компонент двусвязности: '+inttostr(colKD));

//-------------------------------------------------------------

end;

//очистка массивов для чистого построения

For i:=0 to Vershina-1 do begin PS[i]:=0; PSP[i]:=0; end;

end;

//-------------------------------------------------------------

procedure TMainGraf.SpeedButton8Click(Sender: TObject);

var

s: integer;

begin

Memo1.Clear;

KountKS:=1;

for i:=1 to Vershina do Mark1[i]:=false;

try

s:=strtoint(Edit2.text);

except

s:=1;

end;

Memo1.Lines.Add('Обход в глубину, начиная с вершины: ('+inttostr(s)+')');

Depth(s,2);

end;

//-------------------------------------------------------------

procedure TMainGraf.FormResize(Sender: TObject);

var x,y: integer;

begin

//

CountDel:=(MainGraf.ClientWidth div 52)+1;

GroupBox2.Width:=MainGraf.ClientWidth-2; PageControl1.ClientHeight:=MainGraf.ClientHeight; PageControl1.ClientWidth:=MainGraf.ClientWidth;

//

x:= MainGraf.ClientHeight div 2;

y:=MainGraf.ClientWidth div 2;

GroupBox1.Left:=y-150;

GroupBox1.top:=x-70;

//

Memo1.Left:=448;

Memo1.Width:=MainGraf.ClientWidth -460;

//

x:= (MainGraf.ClientHeight+158) div 2;

y:=(MainGraf.ClientWidth+448) div 2;

if (y-240)>=448 then Image1.Left:=y-240 else Image1.Left:=448;

if (x-240)>=94 then Image1.Top:=x-240 else Image1.Top:=94;

//

Panel3.Height:=151;

Panel3.Width:=MainGraf.ClientWidth-1;

StringGrid1.Top:=158;

//

end;

//-------------------------------------------------------------

procedure TMainGraf.BitBtn1Click(Sender: TObject);

var

a,b,c: byte;

begin

if Not CheckBox2.checked then

begin

randomize;

ClrOfP[0]:=ColorBox7.Selected;

for i:=1 to 256 do begin

a:=random(255);

b:=random(255);

c:=random(255);

ClrOfP[i]:=RGB(a,b,c);

for j:=1 to 25 do

begin Image3.Canvas.Pixels[i*2-1,j]:=ClrOfP[i];

Image3.Canvas.Pixels[i*2,j]:=ClrOfP[i];

end;

end;

end;

if CheckBox2.checked then

begin

a:=0; b:=160; c:=0;

for i:=1 to 256 do begin

{if i<85 then begin dec(a); b:=0; c:=0; end;

if (i>=85) and (i<170) then begin dec(b); a:=0; c:=0; end;

if i>=170 then begin dec(c); b:=0; a:=0; end; }

ClrOfP[i]:=RGB(a,b,c);

inc(a);

inc(c);

for j:=1 to 25 do

begin Image3.Canvas.Pixels[i*2-1,j]:=ClrOfP[i];

Image3.Canvas.Pixels[i*2,j]:=ClrOfP[i];

end;

end;

end;

end;

procedure TMainGraf.Timer1Timer(Sender: TObject);

begin

mouseDowning:=false;

UsingPoint:=255;

Visualization(MainGraf.image1.Canvas,2);

Timer1.Enabled:=false;

end;


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: