Esempio n. 1
1
        public List<Edge<int>> mfas(BidirectionalGraph<int, Edge<int>> G)
        {
            List<Edge<int>> F = new List<Edge<int>>();
            IDictionary<int, int> P = new Dictionary<int, int>();

            int sccCount = G.StronglyConnectedComponents(out P);

            if (sccCount == 0)
            {
                return F;
            }

            if (sccCount == 1)
            {
                Tuple<List<int>, List<int>> T = bisect(G);
                F = mfas(subGraph(T.Item1, G));
                F.AddRange(mfas(subGraph(T.Item2, G)));
                F.AddRange(fromV2toV1(T, G));
            }
            else
            {
                var scc = new HashSet<int>(P.Values);
                foreach (int k in scc)
                {
                    List<int> S = P.Select(x => x).Where(x => x.Value == k).Select(x => x.Key).ToList<int>();
                    F.AddRange(mfas(subGraph(S, G)));
                }
            }

            return F;
        }
        public void Repro13160()
        {
            // create a new graph			
            var graph = new BidirectionalGraph<int, SEquatableEdge<int>>(false);

            // adding vertices		    
            for (int i = 0; i < 3; ++i)
                for(int j = 0;j<3;++j)
                    graph.AddVertex(i * 3 + j);

            // adding Width edges			    
            for (int i = 0; i < 3; ++i)
                for(int j = 0; j < 2;++j)
                graph.AddEdge(new SEquatableEdge<int>(i * 3 +j, i * 3 + j + 1));

            // adding Length edges			    
            for (int i = 0; i < 2; ++i)
                for(int j = 0; j < 3;++j)
                graph.AddEdge(new SEquatableEdge<int>(i * 3 + j, (i+1) * 3 + j));

            // create cross edges 
            foreach (var e in graph.Edges)
                graph.AddEdge(new SEquatableEdge<int>(e.Target, e.Source));

            // breaking graph apart
            for (int i = 0; i < 3; ++i)
                for (int j = 0; j < 3; ++j)
                    if (i == 1)
                        graph.RemoveVertex(i * 3 + j);

            var target = new CyclePoppingRandomTreeAlgorithm<int, SEquatableEdge<int>>(graph);
            target.Compute(2);
            foreach(var kv in target.Successors)
                Console.WriteLine("{0}: {1}", kv.Key, kv.Value);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        public RaceDetectionEngine(Configuration configuration)
        {
            this.Configuration = configuration;

            this.AllThreadTraces = new List<ThreadTrace>();
            this.CGraph = new BidirectionalGraph<Node, Edge>();
        }
		public void NonAcyclic()
		{
			var g = new BidirectionalGraph<string, Edge<string>>( );
			var vs = new string[ 4 ];
			for ( int i = 1; i < 5; i++ )
			{
				vs[ i - 1 ] = i.ToString( );
				g.AddVertex( i.ToString( ) );
			}
			g.AddEdge( new Edge<string>( vs[ 0 ], vs[ 1 ] ) );
			g.AddEdge( new Edge<string>( vs[ 1 ], vs[ 2 ] ) );
			g.AddEdge( new Edge<string>( vs[ 2 ], vs[ 0 ] ) );
			g.AddEdge( new Edge<string>( vs[ 3 ], vs[ 0 ] ) );

			try
			{
				var lts = new LayeredTopologicalSortAlgorithm<string, Edge<string>>( g );
				lts.Compute( );

				Assert.Fail( "It does not throw exception for non acyclic graphs." );
			}
			catch ( NonAcyclicGraphException ex )
			{
				Debug.WriteLine( ex.Message );
			}
		}
        public void CloneTest()
        {
            var g = new BidirectionalGraph<int, Edge<int>>();
            g.AddVertexRange(new int[3] {1, 2, 3});
            g.AddEdge(new Edge<int>(1, 2));
            g.AddEdge(new Edge<int>(2, 3));
            g.AddEdge(new Edge<int>(3, 1));

            Assert.AreEqual(3, g.VertexCount);
            Assert.AreEqual(3, g.EdgeCount);

            var h = g.Clone();

            Assert.AreEqual(3, h.VertexCount);
            Assert.AreEqual(3, h.EdgeCount);

            h.AddVertexRange(new int[4] { 10, 11, 12, 13 });
            h.AddEdge(new Edge<int>(10, 11));

            Assert.AreEqual(7, h.VertexCount);
            Assert.AreEqual(4, h.EdgeCount);

            var i = 0;
            foreach (var e in h.Edges)
                i++;

            Assert.AreEqual(4, i);

            Assert.AreEqual(3, g.VertexCount);
            Assert.AreEqual(3, g.EdgeCount);
        }
Esempio n. 6
0
        public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
        {
            var g = new BidirectionalGraph<object, IEdge<object>>();

            foreach (var method in Methods)
            {
                g.AddVertex(method.Name);
            }

            foreach (var field in Fields)
            {
                g.AddVertex(field.Name);
            }

            foreach (var method in Methods)
            {
                foreach (var methodUse in method.MethodUses)
                {
                    g.AddEdge(new Edge<object>(method.Name, methodUse.Name));
                }

                foreach (var fieldUse in method.FieldUses)
                {
                    g.AddEdge(new Edge<object>(method.Name, fieldUse.Name));
                }
            }

            return g;
        }
Esempio n. 7
0
        Tuple<List<int>, List<int>> bisect(BidirectionalGraph<int, Edge<int>> G)
        {
            List<int> vl = G.Vertices.ToList<int>();
            int vlc = vl.Count();
            Tuple<List<int>, List<int>> V = new Tuple<List<int>, List<int>>(vl.GetRange(0, vlc / 2), vl.GetRange(vlc / 2, vlc - vlc / 2));
            Tuple<List<int>, List<int>> B = new Tuple<List<int>, List<int>>(new List<int>(V.Item1), new List<int>(V.Item2));
            int p = -1;//p0 == -1
            int R = 1;
            int d = 2;
            int counter = 0;
            int Cpre, Cpost;
            int BC;
            Cpre = fromV2toV1(V, G).Count();
            BC = Cpre;
            do
            {
                perturb(V, p, G);
                Cpost = fromV2toV1(V, G).Count();
                if (Cpost < Cpre && BC > Cpost) {
                    B = new Tuple<List<int>, List<int>> (new List<int>(V.Item1), new List<int>(V.Item2));
                    BC = Cpost;
                    counter -= R;
                } else {
                    counter++;
                }
                if (Cpost == Cpre) {
                    p = p - d;
                } else {
                    p = -1; //p0 == -1;
                }
                Cpre = Cpost;
            } while(!(counter > R));

            return B;
        }
Esempio n. 8
0
        internal GcTypeHeap(BidirectionalGraph<GcType, GcTypeEdge> graph)
        {
            if (graph == null)
                throw new ArgumentNullException("graph");

            this.graph = graph;
        }
Esempio n. 9
0
        public static IBidirectionalGraph<object, IEdge<object>> AdjacentyMatrixToGraph(MatrixWithHeaders matrixWithHeaders)
        {
            var graph = new BidirectionalGraph<object, IEdge<object>>();

            var headers = matrixWithHeaders.Headers;
            var matrix = matrixWithHeaders.Matrix;

            foreach (var item in headers)
            {
                graph.AddVertex(item.Value);
            }

            if (headers.Count > 1)
            {
                for (int y = 0; y < matrix.GetLength(1); y++)
                {
                    for (int x = 0; x < matrix.GetLength(0); x++)
                    {
                        if (matrix[x, y] == 1)
                        {
                            graph.AddEdge(new Edge<object>(headers[x], headers[y]));
                        }
                    }
                }
            }
            else
            {
                graph.AddEdge(new Edge<object>(headers[0], headers[0]));
            }

            return graph;
        }
Esempio n. 10
0
        public void SmallTest()
        {
            var g1 = new BidirectionalGraph<int, Edge<int>>();
            var g2 = new BidirectionalGraph<int, Edge<int>>();

            g1.AddVerticesAndEdgeRange(new[] {new Edge<int>(1, 2), new Edge<int>(1, 3), new Edge<int>(2, 4)});

            g2.AddVerticesAndEdgeRange(new[] {new Edge<int>(1, 2), new Edge<int>(1, 3), new Edge<int>(2, 4)});

            var dictionary = new Dictionary<Tuple<int, int>, double>();

            foreach (var i in g1.Vertices)
            {
                foreach (var j in g2.Vertices)
                {
                    if (i == j) dictionary[Tuple.Create(i, j)] = 1.0;
                    else dictionary[Tuple.Create(i, j)] = 0.0;
                }
            }

            var algo = new MaxCardinality<int, Edge<int>>(g1, g2, dictionary, 0.5, (u, v) => new Edge<int>(u, v));
            var res = algo.compMaxCardinality();

            var e = Enumerable.Range(1, 4).Select(x => Tuple.Create(x, x));
            var correctResult = SetModule.OfSeq(e);

            Assert.AreEqual(res, correctResult);
        }
 public MainWindow()
 {
     InitializeLinkedList();
     _graphToVisualize = new BidirectionalGraph<object, IEdge<object>>();
     RefreshGraph();
     InitializeComponent();
     PopulateMethodList();
 }
        public void Test()
        {
            var graph = new BidirectionalGraph<int, Edge<int>>();
            graph.AddVerticesAndEdgeRange(new[] { new Edge<int>(1, 2) , new Edge<int>(2, 3), new Edge<int>(3, 4), new Edge<int>(3, 5) });

            var result = graph.ComputeTransitiveClosure((u, v) => new Edge<int>(u, v));
            Assert.AreEqual(9, result.EdgeCount);
        }
Esempio n. 13
0
        public static void ImportEs(BidirectionalGraph<int, Edge<int>> WorkingGraph, int numObjects, string Filename = "C:\\Users\\perdo\\Desktop\\Test.es")
        {
            string s = "";
            string[] Entries;
            Edge<int> Newedge;
            StreamReader reader = null;
            try
            {
                reader = new StreamReader(Filename);
            }
            catch
            {
                throw new Exception("Could not open File" + Filename);
            }
            reader.ReadLine();
            reader.ReadLine(); //skipping first two useless lines
            if (!isUndirected)
            {
                while ((s = reader.ReadLine()) != null)
                {
                    Entries = s.Split(' ');
                    Newedge = new Edge<int>(int.Parse(Entries[0]), int.Parse(Entries[1]));

                    if (Newedge.Source == Newedge.Target) continue; // removing self-edges

                    WorkingGraph.AddVertex(int.Parse(Entries[0]));
                    WorkingGraph.AddVertex(int.Parse(Entries[1]));
                    WorkingGraph.AddEdge(Newedge);

                }
            }
            else // Would have to change the underlying graph structure to properly support undirected edges. Easier just to mirror each edge
            {
                while ((s = reader.ReadLine()) != null)
                {
                    Entries = s.Split(' ');
                    Newedge = new Edge<int>(int.Parse(Entries[0]), int.Parse(Entries[1]));

                    if (Newedge.Source == Newedge.Target) continue; // removing self-edges

                    WorkingGraph.AddVertex(int.Parse(Entries[0]));
                    WorkingGraph.AddVertex(int.Parse(Entries[1]));
                    WorkingGraph.AddEdge(Newedge);
                    Newedge = new Edge<int>(int.Parse(Entries[1]), int.Parse(Entries[0]));
                    WorkingGraph.AddEdge(Newedge);
                }
            }
            //Following code looks for vertices that have no incoming or outgoing edges
            //I debated not including it but figured i'd make this code robust
            var Verts = WorkingGraph.Vertices;
            var MissingItems = Enumerable.Range(0, numObjects);
            foreach (int item in MissingItems)
            {
                WorkingGraph.AddVertex(item);
            }
            reader.Close();
        }
 public void Repro12901()
 {
     var graph = new BidirectionalGraph<int, Edge<int>>();
     int vertex = 1;
     graph.AddVerticesAndEdge(new Edge<int>(vertex, vertex));
     var pathFinder = AlgorithmExtensions.ShortestPathsBellmanFord<int, Edge<int>>(graph, edge => -1.0, vertex);
     IEnumerable<Edge<int>> path;
     pathFinder(vertex, out path);
 }
Esempio n. 15
0
        public void BindGraph(BidirectionalGraph<object, IEdge<object>> graph)
        {
            Graph = graph;

            var bindingExpression = _graphLayout.GetBindingExpression(GraphLayout.GraphProperty);
            if (bindingExpression != null)
            {
                bindingExpression.UpdateTarget();
            }
        }
Esempio n. 16
0
        public void Prune(BidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            Preconditions.NotNull(graph, "graph");
            this.graph = graph;

            RemoveUnreachableBlocks();
            RemoveEmptyBlocks();

            this.graph = null;
        }
Esempio n. 17
0
 //Preparation for CTL requires all nodes without an outgoing edge to have a loop to self
 public void AddSelfLoops(BidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
 {
     foreach (var vertex in graph.Vertices)
     {
         if (!graph.OutEdges(vertex).Any())
         {
             graph.AddEdge (new TaggedEdge<CFGBlock, EdgeTag> (vertex, vertex, new EdgeTag (EdgeType.Normal)));
         }
     }
 }
        public ActivityArrowGraph GenerateGraph()
        {
            InitializeInternalStructures();

            var nodeGraph = CreateActivityNodeGraphFromProject();
            var nodeGraphReduction = nodeGraph.ComputeTransitiveReduction();
            arrowGraph = ExplodeActivityNodeGraphToArrowGraph(nodeGraphReduction);
            RedirectArrowGraph();
            DropRedundantArrows();
            return CreateResultActivityArrowGraph();
        }
 public BlockModularity(int numClust,int numIts, double eps, BidirectionalGraph<int, Edge<int>> g)
 {
     numClusters = numClust;
     graph = g;
     numObjects = g.VertexCount;
     numEdges = g.EdgeCount;
     epsilon = eps;
     numIterations = numIts;
     rnd = new Random();
     workingClustering= new int[numObjects];
 }
Esempio n. 20
0
        public static void AddEdge(BidirectionalGraph<DataVertex, DataEdge> graph, DataVertex source, DataVertex target, int? sourcePoint = null, int? targetPoint = null, int weight = 0)
        {
            var edge = new DataEdge(source, target, weight)
            {
                Text = string.Empty,
                SourceConnectionPointId = sourcePoint,
                TargetConnectionPointId = targetPoint,
                ToolTipText = "Label "+ source.ID
            };

            graph.AddEdge(edge);
        }
Esempio n. 21
0
        /// <summary>
        /// Get similarities by checking node actual values. Take threshold to limit results.
        /// </summary>
        /// <param name="gSource"></param>
        /// <param name="gTarget"></param>
        /// <param name="threshold"></param>
        /// <returns></returns>
        public double[,] getSimilarity(BidirectionalGraph<AbstractTreeLatticeNode, Edge<AbstractTreeLatticeNode>> gSource, BidirectionalGraph<AbstractTreeLatticeNode, Edge<AbstractTreeLatticeNode>> gTarget, double threshold)
        {
            double[,] simM = new double[gSource.VertexCount, gTarget.VertexCount];

            for (int i = 0; i < gSource.VertexCount; i++)
                for (int j = 0; j < gTarget.VertexCount; j++)
                {
                    simM[i, j] = checkNames(gSource.Vertices.ElementAt(i) as AbstractTreeLatticeNode, gTarget.Vertices.ElementAt(j) as AbstractTreeLatticeNode);
                }

            return normaliseResults(simM);
        }
Esempio n. 22
0
        public void ReadGraph(TextReader reader)
        {
            var g = new BidirectionalGraph<MyType, IEdge<MyType>>();
            try {
                var csv = new CsvHelper.CsvReader(reader);
                while (csv.Read()) {
                    if (!csv.CurrentRecord.Any()) {
                        continue;
                    }
                    var node = csv.CurrentRecord.First();
                    var edges = csv.CurrentRecord.Skip(1)
                        .Where(x => !string.IsNullOrEmpty(x))
                        .Select(x => x.Trim())
                        .Where(x => !string.IsNullOrEmpty(x));
                    foreach (var edge in edges) {
                        g.AddVerticesAndEdge(new Edge<MyType>(node, edge));
                    }
                }

                var dict = new Dictionary<int, HashSet<MyType>>();
                HashSet<MyType> set;
                foreach (var v in g.Vertices) {
                    var edgeCount = g.InEdges(v).Count();
                    if (!dict.TryGetValue(edgeCount, out set)) {
                        set = new HashSet<MyType>();
                        dict.Add(edgeCount, set);
                    }
                    set.Add(v);
                }

                Graph = g;

                Summary = string.Join(Environment.NewLine,
                    dict
                        .OrderBy(kvp => kvp.Key)
                        .Select(kvp => kvp.Key + ": " + string.Join(", ", kvp.Value)))
                    + Environment.NewLine
                    + Environment.NewLine
                    + string.Join(Environment.NewLine,
                        g.Vertices
                            .Where(v => g.OutEdges(v).Count() != 3)
                            .Select(v => v + ": " + g.OutEdges(v).Count()));

                //Summary = string.Join(
                //    Environment.NewLine,
                //    graph.Vertices
                //        .OrderBy(x => graph.InEdges(x).Count())
                //        .Select(v => v + ": " + graph.InEdges(v).Count()));
            } catch (Exception e) {
                Summary = "Failed to read:" + Environment.NewLine + e;
            }
        }
Esempio n. 23
0
        public void makeModel(BidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph, IncludeResolver resolver, string path)
        {
            this.graph = graph;
            this.resolver = resolver;
            var root = graph.Roots ().Single (v => v.IsSpecialBlock);

            BFS (root, this.graph);

            Console.WriteLine("Finished BFS Traversal, generating if sentences...");
            GenerateIf ();

            Console.WriteLine("Writing to file...");
            WriteToFile (path);
        }
 public static BidirectionalGraph<string, Edge<string>> LoadBidirectionalGraph(string graphmlFile)
 {
     TestConsole.WriteLine(graphmlFile);
     var g = new BidirectionalGraph<string, Edge<string>>();
     using (var reader = new StreamReader(graphmlFile))
     {
         g.DeserializeFromGraphML(
             reader,
             id => id,
             (source, target, id) => new Edge<string>(source, target)
             );
     }
     return g;
 }
        public void SmallTest()
        {
            var graph = new BidirectionalGraph<int, Edge<int>>();

            graph.AddVerticesAndEdgeRange(new[]
            {
                new Edge<int>(1, 2), new Edge<int>(1, 3), new Edge<int>(1, 4),
                new Edge<int>(1, 5), new Edge<int>(2, 4), new Edge<int>(3, 4),
                new Edge<int>(3, 5), new Edge<int>(4, 5)
            });

            var result = graph.ComputeTransitiveReduction();
            Assert.AreEqual(5, result.EdgeCount);
        }
Esempio n. 26
0
        private void AssembleGraph(BidirectionalGraph<ParseTree, Edge<ParseTree>> graph, ParseTree parent)
        {
            if (parent.Children == null)
            {
                return;
            }

            foreach (var child in parent.Children)
            {
                graph.AddVertex(child);
                graph.AddEdge(new Edge<ParseTree>(parent, child));
                AssembleGraph(graph, child);
            }
        }
Esempio n. 27
0
        private void BuildPropertyAccessTreeGraph(BidirectionalGraph<object, IEdge<object>> g, string root, IEnumerable<Node> nodes)
        {
            foreach (var node in nodes)
            {
                var property_node = node as PropertyNode;
                if (property_node == null) continue;

                var property_node_name = string.Format("{0} - {1}", property_node.Type.UnderlyingSystemType.Name, property_node.PropertyName);
                g.AddVertex(property_node_name);
                g.AddEdge(new Edge<object>(root, property_node_name));

                if (property_node.Children.Count > 0)
                    BuildPropertyAccessTreeGraph(g, property_node_name, property_node.Children);
            }
        }
        public void ContainsEdgeTest1()
        {
            var bd = new BidirectionalGraph<int, IEdge<int>>();

            var e12 = new SEquatableUndirectedEdge<int>(1, 2);
            var f12 = new SEquatableUndirectedEdge<int>(1, 2);

            bd.AddVerticesAndEdge(e12);

            ContainsEdgeAssertions(bd, e12, f12, null, null);

            var u = new UndirectedBidirectionalGraph<int, IEdge<int>>(bd);

            UndirectedGraphTest.ContainsEdgeAssertions(u, e12, f12, null, null);
        }
Esempio n. 29
0
 	public static BidirectionalGraph<object, IEdge<object>> testGraph()
 	{
 	    var bidirectionalGraph = new BidirectionalGraph<object, IEdge<object>>();
         var vertices = new object[] { "A", "B", "C", "D", "E", "F" };
         var edges = new IEdge<object>[] {
                 new Edge<object>(vertices[0], vertices[1]),
                 new Edge<object>(vertices[1], vertices[2]),
                 new Edge<object>(vertices[1], vertices[3]),
                 new Edge<object>(vertices[3], vertices[4]),
                 new Edge<object>(vertices[0], vertices[4]),
                 new Edge<object>(vertices[4], vertices[5])
             };
         bidirectionalGraph.AddVerticesAndEdgeRange(edges);
         return bidirectionalGraph;
 	}
Esempio n. 30
0
        public void CycleWithNoEdgesFromStart()
        {
            var knownSchedules = new Mock<IStoreSchedules>();
            var verifier = new ScheduleVerifier(knownSchedules.Object);

            var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();

            var start = new StartVertex(1);
            graph.AddVertex(start);

            var end = new EndVertex(2);
            graph.AddVertex(end);

            var vertex1 = new InsertVertex(3);
            graph.AddVertex(vertex1);

            var vertex2 = new InsertVertex(4);
            graph.AddVertex(vertex2);

            var vertex3 = new InsertVertex(5);
            graph.AddVertex(vertex3);

            graph.AddEdge(new ScheduleEdge(start, end));
            graph.AddEdge(new ScheduleEdge(vertex1, end));
            graph.AddEdge(new ScheduleEdge(vertex1, vertex2));
            graph.AddEdge(new ScheduleEdge(vertex2, vertex3));
            graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

            var schedule = new Schedule(graph, start, end);

            var id = new ScheduleId();
            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(3, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[0].Item1);
            Assert.AreSame(vertex1, failures[0].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[1].Item1);
            Assert.AreSame(vertex2, failures[1].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[2].Item1);
            Assert.AreSame(vertex3, failures[2].Item2);
        }
 public void OutDegreeSumEqualsEdgeCountAll(BidirectionalGraph <string, Edge <string> > g)
 {
     this.OutDegreeSumEqualsEdgeCount(g);
 }
Esempio n. 32
0
        public void AddEdgeRange()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >(false);

            AddEdgeRange_Test(graph);
        }
 public ConcurrentBidirectionalGraph(bool allowParallelEdges = true)
 {
     Graph    = new BidirectionalGraph <TVertex, TEdge>(allowParallelEdges);
     SyncRoot = new object();
 }
Esempio n. 34
0
        public void AddVerticesAndEdge()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            AddVerticesAndEdge_Test(graph);
        }
Esempio n. 35
0
        public void ContainsEdge_EquatableEdge()
        {
            var graph = new BidirectionalGraph <int, EquatableEdge <int> >();

            ContainsEdge_EquatableEdge_Test(graph);
        }
Esempio n. 36
0
        private static List <LocalVariableAnalysis> AnalyzeLocalVariables(List <ILInstruction> ilInstructions, MethodBody methodBody, BidirectionalGraph <ILInstruction, Edge <ILInstruction> > flowGraph, HashSet <ILInstruction> methodCalls)
        {
            if ((methodBody?.LocalVariables?.Count ?? 0) == 0)
            {
                return(new List <LocalVariableAnalysis>());
            }

            var localVariableAnalyses = methodBody.LocalVariables.Select(localVariable => new LocalVariableAnalysis()).ToList();

            foreach (var ilInstruction in ilInstructions)
            {
                var opCode      = ilInstruction.Code;
                var opCodeValue = opCode.Value;

                if (IsLoadLocal(opCodeValue))
                {
                    localVariableAnalyses[GetLoadLocalIndex(ilInstruction)].Sinks.Add(ilInstruction);
                }
                else if (IsStoreLocal(opCodeValue))
                {
                    localVariableAnalyses[GetStoreLocalIndex(ilInstruction)].Sources.Add(ilInstruction);
                }
                else if (opCodeValue == OpCodes.Ldloca.Value ||
                         opCodeValue == OpCodes.Ldloca_S.Value)
                {
                    var operand = Convert.ToInt32(ilInstruction.Operand);
                    localVariableAnalyses[operand].AddressSources.Add(ilInstruction);
                }
            }

            foreach (var localVariableAnalysis in localVariableAnalyses)
            {
                var sinkScope          = localVariableAnalysis.Sinks.SelectMany(sink => ComputeSinkScope(sink, localVariableAnalysis.Sources, flowGraph)).Distinct();
                var addressSourceScope = localVariableAnalysis.AddressSources.SelectMany(source => ComputeSourceScope(source, flowGraph)).Distinct();
                localVariableAnalysis.Scope = sinkScope.Union(addressSourceScope).ToHashSet();
                localVariableAnalysis.SpannedMethodCalls = localVariableAnalysis.Scope.Intersect(methodCalls).ToHashSet();
            }

            return(localVariableAnalyses);
        }
Esempio n. 37
0
        public static IEnumerable <string> Get_First_Mutual_Branch_Point_Backwards(string vertex, BidirectionalGraph <string, TaggedEdge <string, Tag> > graph)
        {
            if (!graph.ContainsVertex(vertex))
            {
                yield break;
            }

            int inDegree = graph.InDegree(vertex);

            if (inDegree < 2)
            {
                yield break; // the provided vertex is not a mergePoint
            }

            if (inDegree == 2)
            {
                string s1 = graph.InEdge(vertex, 0).Source;
                string s2 = graph.InEdge(vertex, 1).Source;

                if (s1 != s2)
                {
                    HashSet <string> branchPoints1 = new HashSet <string>();
                    HashSet <string> branchPoints2 = new HashSet <string>();

                    foreach (string v in Get_First_Branch_Point_Backwards(s1, graph))
                    {
                        branchPoints1.Add(v);
                    }

                    foreach (string v in Get_First_Branch_Point_Backwards(s2, graph))
                    {
                        branchPoints2.Add(v);
                    }

                    foreach (string mutual in branchPoints1.Intersect(branchPoints2))
                    {
                        yield return(mutual);
                    }
                }
            }
            else
            {
                Console.WriteLine("WARNING: Get_First_Mutual_Branch_Point_Backwards: multiple merge points at this the provided vertex " + vertex);
            }
        }
Esempio n. 38
0
        public void MergeIf_Test(
            [NotNull] IEnumerable <int> setupVertices,
            [NotNull, ItemNotNull] IEnumerable <EquatableEdge <int> > setupEdges,
            [NotNull, InstantHandle] VertexPredicate <int> vertexPredicate,
            int expectedVerticesRemoved,
            int expectedEdgesAdded,
            int expectedEdgesRemoved,
            [NotNull] IEnumerable <int> expectedVertices,
            [NotNull, ItemNotNull] IEnumerable <EquatableEdge <int> > expectedEdges)
        {
            int verticesAdded   = 0;
            int edgesAdded      = 0;
            int verticesRemoved = 0;
            int edgesRemoved    = 0;

            var graph = new BidirectionalGraph <int, EquatableEdge <int> >();

            graph.AddVertexRange(setupVertices);
            graph.AddEdgeRange(setupEdges);

            graph.VertexAdded += v =>
            {
                Assert.IsNotNull(v);
                ++verticesAdded;
            };
            graph.VertexRemoved += v =>
            {
                Assert.IsNotNull(v);
                // ReSharper disable once AccessToModifiedClosure
                ++verticesRemoved;
            };
            graph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesAdded;
            };
            graph.EdgeRemoved += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesRemoved;
            };

            graph.MergeVerticesIf(vertexPredicate, (source, target) => new EquatableEdge <int>(source, target));
            CheckCounters();
            AssertHasVertices(graph, expectedVertices);
            EquatableEdge <int>[] edges = expectedEdges.ToArray();
            if (!edges.Any())
            {
                AssertNoEdge(graph);
            }
            else
            {
                AssertHasEdges(graph, edges);
            }

            #region Local function

            void CheckCounters()
            {
                Assert.AreEqual(0, verticesAdded);
                Assert.AreEqual(expectedVerticesRemoved, verticesRemoved);
                Assert.AreEqual(expectedEdgesAdded, edgesAdded);
                Assert.AreEqual(expectedEdgesRemoved, edgesRemoved);
                verticesRemoved = 0;
                edgesAdded      = 0;
                edgesRemoved    = 0;
            }

            #endregion
        }
Esempio n. 39
0
        public void AddVertex_Throws()
        {
            var graph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();

            AddVertex_Throws_Test(graph);
        }
Esempio n. 40
0
        public void TryGetInEdges_Throws()
        {
            var graph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();

            TryGetInEdges_Throws_Test(graph);
        }
Esempio n. 41
0
        public void Merge_Test(
            [NotNull] IEnumerable <int> setupVertices,
            [NotNull, ItemNotNull] IEnumerable <EquatableEdge <int> > setupEdges,
            int vertexToMerge,
            int expectedEdgesAdded,
            int expectedEdgesRemoved,
            [NotNull, ItemNotNull] IEnumerable <EquatableEdge <int> > expectedEdges)
        {
            int verticesAdded   = 0;
            int edgesAdded      = 0;
            int verticesRemoved = 0;
            int edgesRemoved    = 0;

            var graph = new BidirectionalGraph <int, EquatableEdge <int> >();

            int[] verticesArray = setupVertices.ToArray();
            graph.AddVertexRange(verticesArray);
            graph.AddEdgeRange(setupEdges);

            graph.VertexAdded += v =>
            {
                Assert.IsNotNull(v);
                ++verticesAdded;
            };
            graph.VertexRemoved += v =>
            {
                Assert.IsNotNull(v);
                // ReSharper disable once AccessToModifiedClosure
                ++verticesRemoved;
            };
            graph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesAdded;
            };
            graph.EdgeRemoved += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesRemoved;
            };

            graph.MergeVertex(vertexToMerge, (source, target) => new EquatableEdge <int>(source, target));
            CheckCounters();
            AssertHasVertices(graph, verticesArray.Except(new[] { vertexToMerge }));
            AssertHasEdges(graph, expectedEdges);

            #region Local function

            void CheckCounters()
            {
                Assert.AreEqual(0, verticesAdded);
                Assert.AreEqual(1, verticesRemoved);
                Assert.AreEqual(expectedEdgesAdded, edgesAdded);
                Assert.AreEqual(expectedEdgesRemoved, edgesRemoved);
                verticesRemoved = 0;
                edgesAdded      = 0;
                edgesRemoved    = 0;
            }

            #endregion
        }
Esempio n. 42
0
        public void TryGetInEdges()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            TryGetInEdges_Test(graph);
        }
Esempio n. 43
0
        public void Degree_Throws()
        {
            var graph = new BidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();

            Degree_Throws_Test(graph);
        }
Esempio n. 44
0
        public void Degree()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            Degree_Test(graph);
        }
 public void DegreeSumEqualsTwiceEdgeCountAll(BidirectionalGraph <string, Edge <string> > g)
 {
     this.DegreeSumEqualsTwiceEdgeCount(g);
 }
Esempio n. 46
0
        public void AddEdge_NoParallelEdges_EquatableEdge()
        {
            var graph = new BidirectionalGraph <int, EquatableEdge <int> >(false);

            AddEdge_NoParallelEdges_EquatableEdge_Test(graph);
        }
Esempio n. 47
0
        private static HashSet <ILInstruction> ComputeSinkScope(ILInstruction sink, HashSet <ILInstruction> sources, BidirectionalGraph <ILInstruction, Edge <ILInstruction> > flowGraph)
        {
            var scope       = new HashSet <ILInstruction>();
            var vertexStack = new Stack <ILInstruction>();

            vertexStack.Push(sink);

            while (vertexStack.TryPop(out var vertex))
            {
                if (!scope.Contains(vertex) && !sources.Contains(vertex))
                {
                    scope.Add(vertex);

                    foreach (var edge in flowGraph.InEdges(vertex))
                    {
                        vertexStack.Push(edge.Source);
                    }
                }
            }

            return(scope);
        }
Esempio n. 48
0
 public void Transform(BidirectionalGraph <Resource, AssociationViewEdge> resourceGraph)
 {
     ApplyStudentTransformation(resourceGraph);
     ApplyStaffTransformation(resourceGraph);
     ApplyParentTransformation(resourceGraph);
 }
Esempio n. 49
0
        /// <summary>traverse the provided vertex backwards and return the first</summary>
        public static IEnumerable <string> Get_First_Branch_Point_Backwards(string vertex, BidirectionalGraph <string, TaggedEdge <string, Tag> > graph)
        {
            HashSet <string> visited = new HashSet <string>();

            return(Get_Branch_Point_Backwards_LOCAL(vertex));

            #region Local Method
            IEnumerable <string> Get_Branch_Point_Backwards_LOCAL(string v1)
            {
                if (visited.Contains(v1))
                {
                    yield break;
                }

                if (!graph.ContainsVertex(v1))
                {
                    yield break;
                }

                if (graph.OutDegree(v1) > 1)
                {
                    visited.Add(v1);
                    yield return(v1);
                }
                else
                {
                    foreach (TaggedEdge <string, Tag> edge in graph.InEdges(v1))
                    {
                        foreach (string v in Get_Branch_Point_Backwards_LOCAL(edge.Source))
                        {
                            yield return(v);
                        }
                    }
                }
            }

            #endregion
        }
Esempio n. 50
0
        public void ContainsEdge_SourceTarget()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            ContainsEdge_SourceTarget_Test(graph);
        }
Esempio n. 51
0
        public void Clone()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            AssertEmptyGraph(graph);

            var clonedGraph = graph.Clone();

            Assert.IsNotNull(clonedGraph);
            AssertEmptyGraph(clonedGraph);

            clonedGraph = new BidirectionalGraph <int, Edge <int> >(graph);
            Assert.IsNotNull(clonedGraph);
            AssertEmptyGraph(clonedGraph);

            clonedGraph = (BidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertEmptyGraph(clonedGraph);

            graph.AddVertexRange(new[] { 1, 2, 3 });
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertNoEdge(graph);

            clonedGraph = graph.Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertNoEdge(clonedGraph);

            clonedGraph = (BidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertNoEdge(clonedGraph);

            var edge1 = new Edge <int>(1, 2);
            var edge2 = new Edge <int>(1, 3);
            var edge3 = new Edge <int>(2, 3);

            graph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3 });
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3 });

            clonedGraph = graph.Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });

            clonedGraph = new BidirectionalGraph <int, Edge <int> >(graph);
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });

            clonedGraph = (BidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });

            graph.AddVertex(4);
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3 });

            clonedGraph = graph.Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });

            clonedGraph = (BidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });
        }
Esempio n. 52
0
        public void AddVerticesAndEdgeRange_Throws()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >(false);

            AddVerticesAndEdgeRange_Throws_Test(graph);
        }
Esempio n. 53
0
        public void NotEnoughPaths()
        {
            int ii    = 0;
            var graph = new BidirectionalGraph <int, TaggedEdge <int, int> >();

            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(493, 495, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(495, 493, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(497, 499, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(499, 497, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(499, 501, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(501, 499, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(501, 503, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(503, 501, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(503, 505, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(505, 503, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(505, 507, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(507, 505, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(507, 509, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(509, 507, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(509, 511, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(511, 509, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2747, 2749, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2749, 2747, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2749, 2751, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2751, 2749, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2751, 2753, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2753, 2751, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2753, 2755, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2755, 2753, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2755, 2757, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2757, 2755, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2757, 2759, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2759, 2757, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2763, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2763, 2761, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2765, 2767, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2767, 2765, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2763, 2765, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2765, 2763, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(654, 978, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(978, 654, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(978, 1302, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1302, 978, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1302, 1626, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1626, 1302, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1626, 1950, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1950, 1626, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1950, 2274, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2274, 1950, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2274, 2598, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2598, 2274, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(513, 676, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(676, 513, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2767, 2608, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2608, 2767, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2287, 2608, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2608, 2287, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(676, 999, ii++));;
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(999, 676, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1321, 1643, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1643, 1321, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1643, 1965, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1965, 1643, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1965, 2287, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2287, 1965, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(999, 1321, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1321, 999, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2745, 2747, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2747, 2745, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(650, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 650, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(650, 970, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(970, 650, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2258, 2582, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2582, 2258, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(970, 1291, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1291, 970, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1935, 2258, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2258, 1935, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1291, 1613, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1613, 1291, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1613, 1935, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1935, 1613, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2582, 2745, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2745, 2582, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(495, 497, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(497, 495, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(511, 513, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(513, 511, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 493, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(493, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 654, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(654, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2598, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2598, 2761, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2759, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2759, 2761, ii++));

            var test1 = new HoffmanPavleyRankedShortestPathAlgorithm <int, TaggedEdge <int, int> >(graph, e => 1.0);

            test1.ShortestPathCount = 5;
            test1.Compute(1626, 1965);
            Assert.AreEqual(4, test1.ComputedShortestPathCount);
            TestConsole.WriteLine("path: {0}", test1.ComputedShortestPathCount);
            foreach (var path in test1.ComputedShortestPaths)
            {
                foreach (var edge in path)
                {
                    Console.Write(edge + ":");
                }
                TestConsole.WriteLine();
            }
        }
Esempio n. 54
0
        public void AddEdgeRange_Throws()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            AddEdgeRange_Throws_Test(graph);
        }
        public void RemoveInEdgeIf_Throws()
        {
            var graph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();

            RemoveInEdgeIf_Throws_Test(graph);
        }
Esempio n. 56
0
        public void AddEdge_ParallelEdges()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            AddEdge_ParallelEdges_Test(graph);
        }
Esempio n. 57
0
        public void ClearEdges()
        {
            int edgesRemoved = 0;

            var graph = new BidirectionalGraph <int, Edge <int> >();

            graph.EdgeRemoved += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesRemoved;
            };

            AssertEmptyGraph(graph);

            // Clear 1 => not in graph
            graph.ClearEdges(1);
            AssertEmptyGraph(graph);
            CheckCounter(0);

            // Clear 1 => In graph but not in/out edges
            graph.AddVertex(1);
            graph.ClearEdges(1);
            AssertHasVertices(graph, new[] { 1 });
            AssertNoEdge(graph);
            CheckCounter(0);

            var edge12 = new Edge <int>(1, 2);
            var edge23 = new Edge <int>(2, 3);

            graph.AddVerticesAndEdgeRange(new[] { edge12, edge23 });

            // Clear 2
            graph.ClearEdges(2);

            AssertNoEdge(graph);
            CheckCounter(2);

            var edge13 = new Edge <int>(1, 3);
            var edge31 = new Edge <int>(3, 1);
            var edge32 = new Edge <int>(3, 2);

            graph.AddVerticesAndEdgeRange(new[] { edge12, edge13, edge31, edge32 });

            // Clear 3
            graph.ClearEdges(3);

            AssertHasEdges(graph, new[] { edge12 });
            CheckCounter(3);

            // Clear 1 = clear
            graph.ClearEdges(1);

            AssertNoEdge(graph);
            CheckCounter(1);

            #region Local function

            void CheckCounter(int expectedRemovedEdges)
            {
                Assert.AreEqual(expectedRemovedEdges, edgesRemoved);
                edgesRemoved = 0;
            }

            #endregion
        }
Esempio n. 58
0
        public void ContainsVertex_EquatableVertex()
        {
            var graph = new BidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();

            ContainsVertex_EquatableVertex_Test(graph);
        }
Esempio n. 59
0
        public void OutEdges()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            OutEdges_Test(graph);
        }
Esempio n. 60
0
        public void InEdge()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            InEdge_Test(graph);
        }