public static AFD Konverto(AFJD nd) { var Q = new List <string>(); var Sigma = nd.Sigma.ToList(); var Delta = new List <Kalim>(); var Q0 = nd.Q0.ToList(); var F = new List <string>(); var processed = new List <string>(); var queue = new Queue <string>(Q0); while (queue.Count > 0) { var setState = queue.Dequeue(); processed.Add(setState); Q.Add(setState); var statesInCurrentSetState = setState.Split(',').ToList(); foreach (var state in statesInCurrentSetState) { if (nd.F.Contains(state)) { F.Add(setState); break; } } var symbols = nd.Delta .Where(t => statesInCurrentSetState.Contains(t.GjendjaFillestare)) .Select(t => t.Simbol) .Distinct(); foreach (var symbol in symbols) { var reachableStates = nd.Delta .Where(t => t.Simbol == symbol && statesInCurrentSetState.Contains(t.GjendjaFillestare)) .OrderBy(t => t.GjendjePerfundimtare). Select(t => t.GjendjePerfundimtare); var reachableSetState = string.Join(",", reachableStates); Delta.Add(new Kalim(setState, symbol, reachableSetState)); if (!processed.Contains(reachableSetState)) { queue.Enqueue(reachableSetState); } } } return(new AFD(Q, Sigma, Delta, Q0, F)); }
private static void Main() { using (StreamReader str = new StreamReader("Rastet.txt")) { while (!str.EndOfStream) { string[] parts = str.ReadLine().Split(' '); var Q = parts[0].Split(','); var BashkesiaE = new List <char>(); foreach (var gj in parts[1].Split(',')) { BashkesiaE.Add(Convert.ToChar(gj)); } var Q0 = parts[2].Split(','); var F = parts[3].Split(','); string[] kalimet = parts[4].Split(','); var Kalimet = new List <Kalim>(); foreach (var kalim in kalimet) { string[] elements = kalim.Split('-'); Kalim kalimiIRradhes = new Kalim(elements[0], Convert.ToChar(elements[1]), elements[2]); Kalimet.Add(kalimiIRradhes); } var afjd = new AFJD(Q, BashkesiaE, Kalimet, Q0, F); var afd = Konvertuesi.Konverto(afjd); foreach (var kalim in afd.Delta) { Console.WriteLine(kalim.ToString()); } Console.WriteLine("Shtyp nje celes per te pare automatin e rradhes!"); Console.ReadKey(); } } Console.ReadLine(); }