Anda di halaman 1dari 4

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DFA1.DFA2
{
public struct Z
{
public int x;
public List<int> y;
}
public struct resultant
{
public int a;
public int b;
}
class Program
{
static void Main(string[] args)
{
int[,] tt1 = new int[,]
{
{1,2},
{1,1},
{2,2}
};
int[,] tt2 = new int[,]
{
{3,1},
{2,1},
{2,1},
{3,3}
};
int is_tt1 = 0;
int is_tt2 = 0;
int[] fs_tt1 = new int[] { 1 };
int[] fs_tt2 = new int[] { 2};
concatenate(tt1, tt2, is_tt1, is_tt2, fs_tt1, fs_tt2);

}
public static void concatenate(int[,] tt1, int[,] tt2, int is_tt1, int i
s_tt2, int[] fs_tt1, int[] fs_tt2)
{
List<Z> combination = new List<Z>();
List<resultant> Resultant = new List<resultant>(); //tranisition tab
le after concantenate
Z z = new Z();
resultant r = new resultant(); // temporary node for a index of resu
ltant
z.x = is_tt1;
z.y = new List<int>();

combination.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 = new List<int>();
// transition of tt1
for (int m = 0; m < fs_tt1.Length; m++) // agr final state pe h
dfa1 k tu dfa2 ki initial state add krdaingy
{
if (z_a.x == fs_tt1[m])
z_a.y.Add(is_tt2);
}
for (int m = 0; m < combination[k - 1].y.Count; m++)
{
if (!z_a.y.Contains(tt2[combination[k - 1].y[m], 0])) // tra
nisition(lekin tranisition un states ki nh hngi jo repeated arhi hain)
z_a.y.Add(tt2[combination[k - 1].y[m], 0]);
}

if (!contains(combination, z_a)) //agr combination phly sy exist


nh krta tu add hogi combination table me
{
combination.Add(z_a);
r.a = combination.Count-1;
}
else
{
r.a = index_of(combination, z_a); // index lekr aega jahan e
xist phly sy z krta h
}
Z z_b = new Z();
z_b.y = new List<int>();
z_b.x = tt1[i, 1];
for (int m = 0; m < fs_tt1.Length; m++) // final state pe h agr
dfa1 tu dfa2 ki initial state add hojaegi
{
if (z_b.x == fs_tt1[m])
z_b.y.Add(is_tt2);
}
for (int m = 0; m < combination[k - 1].y.Count; m++)
{
{if(!z_b.y.Contains(tt2[combination[k-1].y[m],1])) // tranis
ition(lekin tranisition un states ki nh hngi jo repeated arhi hain)
z_b.y.Add(tt2[combination[k - 1].y[m], 1]);
}

}
if (!contains(combination,z_b)) // agr phly sy exist nh krta tu
combination table me add hojaega
{
combination.Add(z_b);
r.b = combination.Count - 1;
}
else
{
r.b = index_of(combination, z_b); // otherwise phly sy exist
krta tu jahan mojood h wahan ka index
}
Resultant.Add(r); // resultant tranisition table me states add h
ojaengi
if (combination.Count == k) break; // agr combination table poin
ter list ki length ko point krrha tu stop loop khtm hojaega
i = combination[k].x;
k++;
}
// printing purpose
Console.WriteLine("states\t a\t b\t");
for (i = 0; i < Resultant.Count; i++)
{
if (j<fs_tt2.Length && fs_tt2[j] == i)
{ Console.WriteLine("+{0}\t {1}\t {2}\t", i, Resultant[i]
.a, Resultant[i].b);
j++; }
else
Console.WriteLine(" {0}\t {1}\t {2}\t", i, Resultant[
i].a, Resultant[i].b);
}

}
public static int index_of(List<Z> combination, Z z_a) // list me node k
a index le aega
{
for (int i = 0; i < combination.Count; i++)
{
if (combination[i].x == z_a.x && combination[i].y.SequenceEqual(
z_a.y))
return i;
}
return -1;
}
public static bool contains(List<Z> combination, Z z_a)
{
for (int i = 0; i < combination.Count; i++)
{
if (combination[i].x == z_a.x && combination[i].y.SequenceEqual(
z_a.y))
return true;
}
return false;
}
}
}

Anda mungkin juga menyukai