예제 #1
0
 public UndirectedGraph(bool allowParallelEdges)
 {
     this.allowParallelEdges   = allowParallelEdges;
     this.edgeEqualityComparer = EdgeExtensions.GetUndirectedVertexEquality <TVertex, TEdge>();
     this.edges2 = new Dictionary <TVertex, List <TVertex> >();
     //this.adjacentEdges = new VertexEdgeDictionary<TVertex, TEdge>(EqualityComparer<TVertex>.Default);
 }
예제 #2
0
        public bool IsSelfEdge <TVertex, TEdge>(TEdge edge)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.IsSelfEdge(IEdge`1<!!0>)
            bool result = EdgeExtensions.IsSelfEdge <TVertex, TEdge>(edge);

            return(result);
        }
예제 #3
0
        public bool IsPathWithoutCycles <TVertex, TEdge>(IEnumerable <TEdge> path)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.IsPathWithoutCycles(IEnumerable`1<!!1>)
            bool result = EdgeExtensions.IsPathWithoutCycles <TVertex, TEdge>(path);

            return(result);
        }
예제 #4
0
        public bool IsAdjacent <TVertex, TEdge>(TEdge edge, TVertex vertex)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.IsAdjacent(!!1, !!0)
            bool result = EdgeExtensions.IsAdjacent <TVertex, TEdge>(edge, vertex);

            return(result);
        }
예제 #5
0
        public SEquatableEdge <TVertex> ToVertexPair <TVertex, TEdge>(TEdge edge)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.ToVertexPair(IEdge`1<!!0>)
            SEquatableEdge <TVertex> result = EdgeExtensions.ToVertexPair <TVertex, TEdge>(edge);

            return(result);
        }
예제 #6
0
        /// <summary>Test stub for HasCycles(IEnumerable`1&lt;!!1&gt;)</summary>
        private bool HasCycles <TVertex, TEdge>(IEnumerable <TEdge> path)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.HasCycles(IEnumerable`1<!!1>)
            bool result = EdgeExtensions.HasCycles <TVertex, TEdge>(path);

            return(result);
        }
예제 #7
0
        public TVertex GetOtherVertex <TVertex, TEdge>(TEdge edge, TVertex vertex)
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.GetOtherVertex(!!1, !!0)
            TVertex result = EdgeExtensions.GetOtherVertex <TVertex, TEdge>(edge, vertex);

            Assert.AreNotEqual(vertex, result);
            Assert.IsTrue(
                edge.Source.Equals(result) ||
                edge.Target.Equals(result));
            return(result);
        }
예제 #8
0
        public bool IsPredecessor <TVertex, TEdge>(
            IDictionary <TVertex, TEdge> predecessors,
            TVertex root,
            TVertex vertex
            )
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.IsPredecessor(IDictionary`2<!!0,!!1>, !!0, !!0)
            bool result
                = EdgeExtensions.IsPredecessor <TVertex, TEdge>(predecessors, root, vertex);

            return(result);
        }
예제 #9
0
        public bool TryGetPath <TVertex, TEdge>(
            IDictionary <TVertex, TEdge> predecessors,
            TVertex v,
            out IEnumerable <TEdge> result
            )
            where TEdge : IEdge <TVertex>
        {
            // TODO: add assertions to method EdgeExtensionsTest.TryGetPath(IDictionary`2<!!0,!!1>, !!0, IEnumerable`1<!!1>&)
            bool result01
                = EdgeExtensions.TryGetPath <TVertex, TEdge>(predecessors, v, out result);

            return(result01);
        }
 public bool TryGetOutEdges(TVertex v, out IEnumerable<SReversedEdge<TVertex, TEdge>> edges)
 {
     IEnumerable<TEdge> inEdges;
     if (this.OriginalGraph.TryGetInEdges(v, out inEdges))
     {
         edges = EdgeExtensions.ReverseEdges<TVertex, TEdge>(inEdges);
         return true;
     }
     else
     {
         edges = null;
         return false;
     }
 }
예제 #11
0
        public bool RemoveEdge(TEdge edge)
        {
            bool removed = this.adjacentEdges[edge.Source].Remove(edge);

            if (removed)
            {
                if (!EdgeExtensions.IsSelfEdge <TVertex, TEdge>(edge))
                {
                    this.adjacentEdges[edge.Target].Remove(edge);
                }
                this.edgeCount--;
                Contract.Assert(this.edgeCount >= 0);
                this.OnEdgeRemoved(edge);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #12
0
        public bool AddEdge(TEdge edge)
        {
            var sourceEdges = this.adjacentEdges[edge.Source];

            if (!this.AllowParallelEdges)
            {
                if (this.ContainsEdgeBetweenVertices(sourceEdges, edge))
                {
                    return(false);
                }
            }

            sourceEdges.Add(edge);
            if (!EdgeExtensions.IsSelfEdge <TVertex, TEdge>(edge))
            {
                var targetEdges = this.adjacentEdges[edge.Target];
                targetEdges.Add(edge);
            }
            this.edgeCount++;
            this.OnEdgeAdded(edge);

            return(true);
        }
 public IEnumerable<SReversedEdge<TVertex, TEdge>> OutEdges(TVertex v)
 {
     return EdgeExtensions.ReverseEdges<TVertex, TEdge>(this.OriginalGraph.InEdges(v));
 }
예제 #14
0
 public UndirectedGraph(bool allowParallelEdges)
     : this(allowParallelEdges, EdgeExtensions.GetUndirectedVertexEquality <TVertex, TEdge>())
 {
     this.allowParallelEdges = allowParallelEdges;
 }