Ejemplo n.º 1
0
        public static List <List <int> > SearchNaturalCycles(ControlFlowGraph cfg)
        {
            var list   = cfg.GetAsAdjacencyList();
            var cycles = NaturalCycles.GetListCycles(list);

            return(cycles);
        }
Ejemplo n.º 2
0
 public static void WriteNestedCycles(List <List <int> > cycles)
 {
     for (int i = 0; i < cycles.Count; i++)
     {
         for (int j = 0; j < cycles.Count; j++)
         {
             var a = cycles[j].All(cycles[i].Contains) && cycles[j].Count < cycles[i].Count;
             if (a)
             {
                 Console.WriteLine(NaturalCycles.ListToString(cycles[j]) + "contains in " + NaturalCycles.ListToString(cycles[i]));
             }
         }
     }
 }
Ejemplo n.º 3
0
        private static List <List <int> > GetListCycles(List <List <int> > list)
        {
            var way  = new List <int>();
            var ways = new List <List <int> >();

            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < list[i].Count; j++)
                {
                    if (list[i][j] < i)
                    {
                        way = NaturalCycles.GetWay(list, list[i][j], i);
                        ways.Add(way);
                    }
                }
            }

            for (int i = 0; i < ways.Count; i++)
            {
                int j = 0;
                while (j < ways.Count)
                {
                    if ((ways[i][0] == ways[j][0]) && (i != j))
                    {
                        ways.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }

            for (int i = 0; i < ways.Count; i++)
            {
                for (int j = 0; j < ways.Count; j++)
                {
                    var gg = ways[i].Intersect(ways[j]).ToList();
                    if ((gg.Count == 1) && (ways[i][ways[i].Count - 1] == ways[j][0]))
                    {
                        for (int l = 1; l < ways[j].Count; l++)
                        {
                            ways[i].Add(ways[j][l]);
                        }
                    }
                    else
                    {
                        if ((gg.Count != ways[j].Count) && (ways[i][0] < ways[j][0]))
                        {
                            for (int l = 0; l < ways[j].Count; l++)
                            {
                                if (!ways[i].Contains(ways[j][l]))
                                {
                                    ways[i].Add(ways[j][l]);
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < ways.Count; i++)
            {
                ways[i].Sort();
            }
            return(ways);
        }