Exemplo n.º 1
0
 public bool ContainsEdge(TVertex source, TVertex target)
 {
     GraphContracts.AssumeInVertexSet(this, source, "source");
     GraphContracts.AssumeInVertexSet(this, target, "target");
     foreach (var outEdge in this.OutEdges(source))
     {
         if (outEdge.Target.Equals(target))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 3
0
        public void ClearInEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

            EdgeList inEdges = this.vertexInEdges[v];

            foreach (var 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        public void ClearOutEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

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

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

            this.edgeCount -= edges.Count;
            foreach (var 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);
        }
Exemplo n.º 7
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 (var edge in outEdges)
            {
                if (predicate(edge))
                {
                    edges.Add(edge);
                }
            }

            this.RemoveEdges(edges);
            return(edges.Count);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public int RemoveInEdgeIf(TVertex v, EdgePredicate <TVertex, TEdge> predicate)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");
            GraphContracts.AssumeNotNull(predicate, "predicate");
            EdgeList edges = new EdgeList();

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