public bool ContainsEdge(TVertex source, TVertex target)
 {
     GraphContracts.AssumeInVertexSet(this, source, "source");
     GraphContracts.AssumeInVertexSet(this, target, "target");
     foreach (TEdge outEdge in this.OutEdges(source))
     {
         if (outEdge.Target.Equals(target))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
 public virtual bool RemoveEdge(TEdge e)
 {
     GraphContracts.AssumeInVertexSet(this, e, "e");
     if (this.vertexEdges[e.Source].Remove(e))
     {
         this.edgeCount--;
         System.Diagnostics.Debug.Assert(this.edgeCount >= 0);
         this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(e));
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public void ClearInEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

            EdgeList inEdges = this.vertexInEdges[v];

            foreach (TEdge edge in inEdges)
            {
                this.vertexOutEdges[edge.Source].Remove(edge);
                this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
            }

            this.edgeCount -= inEdges.Count;
            inEdges.Clear();
            GraphContracts.Assert(this.edgeCount >= 0);
        }
Beispiel #4
0
        public virtual bool AddEdge(TEdge e)
        {
            GraphContracts.AssumeInVertexSet <TVertex, TEdge>(this, e, "e");
            if (!this.AllowParallelEdges)
            {
                if (this.ContainsEdge(e.Source, e.Target))
                {
                    return(false);
                }
            }
            this.vertexEdges[e.Source].Add(e);
            this.edgeCount++;

            this.OnEdgeAdded(new EdgeEventArgs <TVertex, TEdge>(e));

            return(true);
        }
Beispiel #5
0
        public void ClearOutEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

            EdgeList edges = this.vertexEdges[v];
            int      count = edges.Count;

            if (this.EdgeRemoved != null) // call only if someone is listening
            {
                foreach (TEdge edge in edges)
                {
                    this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
                }
            }
            edges.Clear();
            this.edgeCount -= count;
            GraphContracts.Assert(this.edgeCount >= 0);
        }
        public void ClearAdjacentEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");
            IList <TEdge> edges = this.adjacentEdges[v];

            this.edgeCount -= edges.Count;
            foreach (TEdge edge in edges)
            {
                if (edge.Source.Equals(v))
                {
                    this.adjacentEdges[edge.Target].Remove(edge);
                }
                else
                {
                    this.adjacentEdges[edge.Source].Remove(edge);
                }
            }
            System.Diagnostics.Debug.Assert(this.edgeCount >= 0);
        }
        public int RemoveAdjacentEdgeIf(TVertex v, EdgePredicate <TVertex, TEdge> predicate)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");
            GraphContracts.AssumeNotNull(predicate, "predicate");

            IList <TEdge> outEdges = this.adjacentEdges[v];
            List <TEdge>  edges    = new List <TEdge>(outEdges.Count);

            foreach (TEdge edge in outEdges)
            {
                if (predicate(edge))
                {
                    edges.Add(edge);
                }
            }

            this.RemoveEdges(edges);
            return(edges.Count);
        }
        public bool AddEdge(TEdge edge)
        {
            GraphContracts.AssumeInVertexSet(this, edge, "edge");

            if (!this.AllowParallelEdges)
            {
                if (this.adjacentEdges[edge.Source].Contains(edge))
                {
                    return(false);
                }
            }
            this.adjacentEdges[edge.Source].Add(edge);
            this.adjacentEdges[edge.Target].Add(edge);
            this.edgeCount++;

            this.OnEdgeAdded(new EdgeEventArgs <TVertex, TEdge>(edge));

            return(true);
        }
        public int RemoveInEdgeIf(TVertex v, EdgePredicate <TVertex, TEdge> predicate)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");
            GraphContracts.AssumeNotNull(predicate, "predicate");
            EdgeList edges = new EdgeList();

            foreach (TEdge edge in this.InEdges(v))
            {
                if (predicate(edge))
                {
                    edges.Add(edge);
                }
            }
            foreach (TEdge edge in edges)
            {
                this.RemoveEdge(edge);
            }
            return(edges.Count);
        }
Beispiel #10
0
 public bool IsAdjacentEdgesEmpty(TVertex v)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.adjacentEdges[v].Count == 0);
 }
Beispiel #11
0
 public int AdjacentDegree(TVertex v)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.adjacentEdges[v].Count);
 }
Beispiel #12
0
 public IEnumerable <TEdge> AdjacentEdges(TVertex v)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.adjacentEdges[v]);
 }
 public bool ContainsEdge(TEdge edge)
 {
     GraphContracts.AssumeInVertexSet(this, edge, "edge");
     return(this.vertexOutEdges[edge.Source].Contains(edge));
 }
 public int Degree(TVertex v)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.OutDegree(v) + this.InDegree(v));
 }
 public TEdge InEdge(TVertex v, int index)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.vertexInEdges[v][index]);
 }
 public int InDegree(TVertex v)
 {
     GraphContracts.AssumeInVertexSet(this, v, "v");
     return(this.vertexInEdges[v].Count);
 }