Ejemplo n.º 1
0
        private static void RemoveCyclesFromGraph(IMutableVertexAndEdgeListGraph <Type, MEdge> graph)
        {
            IDictionary <Type, int> components;

            graph.StronglyConnectedComponents(out components);

            var cycles = components.GroupBy(x => x.Value, x => x.Key)
                         .Where(x => x.Count() > 1)
                         .Select(x => x.ToList());

            foreach (var cycle in cycles)
            {
                var clippedTypes = cycle.Where(
                    x => x.Name.EndsWith("Reference") ||
                    x.GetProperties().Length == 1 &&
                    x.GetProperties().Single().PropertyType.Name
                    .EndsWith("Reference"));

                var edges = graph.Edges.Where(e => cycle.Contains(e.Target) && clippedTypes.Contains(e.Source));
                graph.RemoveEdgeIf(e => edges.Contains(e));
            }
        }