Методы минимизации логических функций
i, j : integer;
Begin
for i:=1 to IndexSImp do
for j:=1 to IndexDSNF do
if Metka(i, j) then
QM[i, j]:=1
else
QM[i, j]:=0;
End;
Procedure PrintMatrix;
Var
i, j: integer;
Begin
TextColor(LIGHTGREEN);
Write(' ');
for i:=1 to IndexDSNF do
Write(DSNF[i]:6);
WriteLn;
for i:=1 to IndexSImp do
begin
TextColor(LIGHTGREEN);
Write(SimpleImp[i]:6);
for j:=1 to IndexDSNF do
case QM[i, j] of
1 : begin TextColor(LIGHTRED); Write(' 1'); end;
0 : begin TextColor(RED); Write(' -'); end;
end;
WriteLn;
end;
End;
Function Bin(N :integer): string16;
Var
i : integer;
S : string16;
Begin
S:='0000000000000000';
i:=0;
while N>0 do
begin
Inc(i);
Insert(Chr((N mod 2)+48), S, i);
N:=N div 2;
end;
Bin:=S;
End;
Function Pokritie(var S: string16): boolean;
Var
V : array[1..16] of integer;
i, j, Sum: integer;
Begin
Pokritie:=False;
for i:=1 to 16 do
V[i]:=0;
for i:=1 to IndexSImp do
if S[i]='1' then
for j:=1 to IndexDSNF do
if QM[i, j]=1 then
V[j]:=1;
Sum:=0;
for i:=1 to IndexDSNF do
if V[i]=1 then
Sum:=Sum+1;
if Sum=IndexDSNF then
Pokritie:=True;
End;
Function Count(S: string16): integer;
Var
i, j, C: integer;
Begin
C:=0;
for i:=1 to IndexSImp do
if S[i]='1' then
for j:=1 to 4 do
if SimpleImp[i, j]<>'*' then
C:=C+1;
Count:=C;
End;
Procedure ActionsPetrik;
Var
i, j, Index : integer;
S16 : string16;
Begin
Index:=(1 shl IndexSImp)-1;
S16Min:='1111111111111111';
for i:=1 to Index do
begin
S16:=Bin(i);
if Pokritie(S16) then
if Count(S16)<Count(S16Min) then
S16Min:=S16;
end;
End;
Procedure PrintRezult;
Var
i : integer;
Begin
WriteLn;
WriteLn;
TextColor(LIGHTGREEN);
WriteLn('Минимальная дизъюнктивная нормальная форма.');
WriteLn;
TextColor(LIGHTRED);
for i:=1 to IndexSImp do
if S16Min[i]='1' then
WriteLn(SimpleImp[i]:8);
End;
Begin
ClrScr;
Input; {ввод данных}
FormMatrix; {формирование матрицы покрытия для ее дальнейшей обработки}
PrintMatrix; {вывод матрицы}
ActionsPetrik; {формирование конъюнкции дизъюнкций
по методу Петрика и выбор минимальной из них}
PrintRezult; {печать МДНФ}
ReadKey;
End.
Результаты работы программы.
0000 0010 0011 0101 0110 0111 1010 1011 1111
0*1* - 1 1 - 1 1 - - -
*01* - 1 1 - - - 1 1 -
**11 - - 1 - - 1 - 1 1
00*0 1 1 - - - - - - -
01*1 - - - 1 - 1 - - -
Минимальная дизъюнктивная нормальная форма.
0*1*
*01*
**11
00*0
01*1