Вы находитесь на странице: 1из 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DFA1_DFA2
{
public struct Z
{
public int x;
public int y;
}
public struct DFAR//DFAR = resultant DFA
{
public int a;
public int b;
}
class Program
{
static void Main(string[] args)
{
int[,] tt1 = new int[,]
{
{1,0},
{2,1},
{1,2}
};
int[,] tt2 = new int[,]
{
{0,1},
{0,2},
{0,2}
};

OR(tt1, tt2, 0, 0, new int[] { 2 }, new int[] { 2 });


}
public static void OR(int[,] tt1, int[,] tt2,int is1,int is2,int[] fs1,int
[] fs2)
{

List<Z> loc = new List<Z>();//loc = list of combinations


List<DFAR> ttlist = new List<DFAR>();//ttlist = trasition table list

Z z = new Z();
z.x = is1;
z.y = is2;//creating initial initial state i.e Z_not

DFAR dfa = new DFAR();

loc.Add(z);
int i = 0;
int j = 0;
int k = 1;
while(true)
{
Z z_a = new Z();
z_a.x = tt1[i, 0];
z_a.y = tt2[j, 0];
if (loc.Contains(z_a) == false)//yani list me element mojood nae hy
to add krdo final dfa me
{
loc.Add(z_a);
dfa.a = loc.Count;
}
else
{
int ind = loc.IndexOf(z_a);
dfa.a = ind;
}
Z z_b = new Z();
z_b.x = tt1[i, 1];
z_b.y = tt2[j, 1];//1 for transition of b
if (loc.Contains(z_b) == false)
{
loc.Add(z_b);
dfa.b = loc.Count;
}
else
{
int ind = loc.IndexOf(z_b);
dfa.b = ind;
}

ttlist.Add(dfa);
if (loc.Count== k) break;//agar list pointer (k) == list of
combinations ki lenght k to the end...
i = loc[k].x;
j = loc[k].y;
k++;
}
//Now finding final states of the Resultant DFA
List<int> finalstates = new List<int>();
for (i = 0; i < fs1.Length; i++)
{
for (j = 0; j < loc.Count; j++)
{
if (fs1[i] == loc[j].x || fs1[i] == loc[j].y)
{
finalstates.Add(j);
}
}

}
for (i = 0; i < fs1.Length; i++)
{
for (j = 0; j < loc.Count; j++)
{
if (fs2[i] == loc[j].x || fs2[i] == loc[j].y)
{
if (!finalstates.Contains(i)) { finalstates.Add(j); }
}
}
}
int[] fs = new int[finalstates.Count];
for (i = 0; i < fs.Length; i++)
{
fs[i] = finalstates[i];
}
}
}
}

Вам также может понравиться