Здравствуйте уважаемые форумчане. Не могли бы вы подсказать как реализовать минимизацию методом Петрика?
Исходные данные - пользователь вводит таблицу импликант в StringGrid. Ну и далее я взаимодейстую с таблицей.
В итоге должна получится минимизированная ДНФ.
Вот код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids;
type
TArr=array [1..32] of string;
TForm1 = class(TForm)
SG1: TStringGrid;
LE1: TLabeledEdit;
LE2: TLabeledEdit;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
LE1.Text:='';
LE2.Text:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var C:TArr;i,j,k,l,r,posc,posr:integer;fk,fk1:boolean;
begin
fk:=false;
fk1:=false;
sg1.RowCount:=strtoint(LE2.Text)+1;
sg1.ColCount:=strtoint(LE1.Text)+1;
r:=0;j:=0;posc:=0;posr:=0;
for k:=1 to form1.SG1.ColCount do
begin
for l:=1 to form1.SG1.RowCount do
begin
if (form1.SG1.Cells[k,l]='x')or(form1.SG1.Cells[k,l]='X') then
begin
fk1:=true;
posc:=k;
posr:=l;
end;
if (fk1) and (l<>posr) then
begin
fk:=true;
j:=l;
fk1:=false;
end;
if (fk) and (l<>j) then
fk1:=true;
if (not fk) and (l=form1.SG1.RowCount) then
begin
inc(r);
c[r]:=form1.SG1.Cells[posc,posr];
end;
end;
end;
for i:=1 to r do
form1.Edit1.Text:=form1.Edit1.Text+c[i];
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
LE1.Text:='';
LE2.Text:='';
for i:=0 to form1.SG1.RowCount do
for j:=0 to form1.SG1.ColCount do
form1.SG1.Cells[j,i]:='';
end;
end.
Всем спасибо за внимание!