Ejemplo n.º 1
0
        public virtual DataRelationJoinEdge AddEdge(
            DataTableJoinVertex source,
            DataTableJoinVertex target,
            JoinType joinType
            )
        {
            // look for the relation in the original graph
            DataRelation    relation     = null;
            DataTableVertex sourceVertex = this.DataGraph.GetVertex(source.Table);

            foreach (DataRelationEdge edge in this.DataGraph.OutEdges(sourceVertex))
            {
                if (edge.Target.Table == target.Table)
                {
                    if (relation != null)
                    {
                        throw new ArgumentNullException("Multiple relation, cannot choose one");
                    }
                    relation = edge.Relation;
                }
            }
            if (relation == null)
            {
                throw new ArgumentNullException("Could not find relation between tables "
                                                + source.Table.TableName + " and " + target.Table.TableName
                                                );
            }
            return(this.AddEdge(source, target, joinType, relation));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns an iterable collection over the in-edge connected to v
 /// </summary>
 /// <param name="v"></param>
 /// <returns>in-edges of v</returns>
 /// <exception cref="ArgumentNullException">
 /// v is a null reference (Nothing in Visual Basic)
 /// </exception>
 /// <exception cref="VertexNotFoundException">
 /// <paramref name="v"/> is not part of the graph.
 /// </exception>		
 public IEdgeCollection InEdges(DataTableVertex v)
 {
     if (v == null)
         throw new ArgumentNullException("v");
     DataRelationEdgeCollection edges = this.vertexInEdges[v];
     if (edges==null)
         throw new VertexNotFoundException(v.ToString());
     return edges;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the number of in-degree edges of v
 /// </summary>
 /// <param name="v"></param>
 /// <returns>number of in-edges of the vertex v</returns>
 /// <exception cref="ArgumentNullException">
 /// v is a null reference (Nothing in Visual Basic)
 /// </exception>
 /// <exception cref="VertexNotFoundException">
 /// <paramref name="v"/> is not part of the graph.
 /// </exception>		
 public int InDegree(DataTableVertex v)
 {
     if (v == null)
         throw new ArgumentNullException("v");
     DataRelationEdgeCollection edges = this.vertexInEdges[v];
     if (edges==null)
         throw new VertexNotFoundException("v");
     return edges.Count;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns the number of in-edges plus out-edges.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public int Degree(DataTableVertex v)
 {
     if (v == null)
         throw new ArgumentNullException("v");
     DataRelationEdgeCollection outEdges = this.vertexOutEdges[v];
     if (outEdges==null)
         throw new VertexNotFoundException("v");
     DataRelationEdgeCollection inEdges = this.vertexInEdges[v];
     Debug.Assert(inEdges!=null);
     return outEdges.Count + inEdges.Count;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Tests if a <see cref="DataTableVertex"/> is part of the graph
 /// </summary>
 /// <param name="v">Vertex to test</param>
 /// <returns>true if is part of the graph, false otherwize</returns>
 public bool ContainsVertex(DataTableVertex v)
 {
     return this.vertexOutEdges.Contains(v);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a new vertex to the graph and returns it.
        /// </summary>
        /// <returns>Create vertex</returns>
        internal virtual void AddVertex(DataTableVertex v)
        {
            if (v==null)
                throw new ArgumentNullException("vertex");
            if (this.vertexOutEdges.Contains(v))
                throw new ArgumentException("vertex already in graph");

            this.version++;
            this.VertexProvider.UpdateVertex(v);
            this.vertexOutEdges.Add(v);
            this.vertexInEdges.Add(v);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the collection of out-edges that matches the predicate
        /// </summary>
        /// <param name="v"></param>
        /// <param name="ep">Edge predicate</param>
        /// <returns>enumerable colleciton of vertices that matches the 
        /// criteron</returns>
        /// <exception cref="ArgumentNullException">v or ep is null</exception>
        public IEdgeEnumerable SelectOutEdges(DataTableVertex v, IEdgePredicate ep)
        {
            if (v==null)
                throw new ArgumentNullException("v");
            if (ep==null)
                throw new ArgumentNullException("ep");

            return new FilteredEdgeEnumerable(this.OutEdges(v),ep);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Remove all the out-edges of vertex u for which the predicate pred 
        /// returns true.
        /// </summary>
        /// <param name="u">vertex</param>
        /// <param name="pred">edge predicate</param>
        public virtual void RemoveOutEdgeIf(DataTableVertex u, IEdgePredicate pred)
        {
            if (u==null)
                throw new ArgumentNullException("u");
            if (pred == null)
                throw new ArgumentNullException("pred");

            DataRelationEdgeCollection edges = this.vertexOutEdges[u];
            DataRelationEdgeCollection removedEdges = new DataRelationEdgeCollection();
            foreach(DataRelationEdge e in edges)
            {
                if (pred.Test(e))
                    removedEdges.Add(e);
            }

            foreach(DataRelationEdge e in removedEdges)
                this.RemoveEdge(e);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets a value indicating if the set of edges connected to v is empty
 /// </summary>
 /// <remarks>
 /// <para>
 /// Usually faster that calling <see cref="Degree"/>.
 /// </para>
 /// </remarks>
 /// <value>
 /// true if the adjacent edge set is empty, false otherwise.
 /// </value>
 /// <exception cref="ArgumentNullException">v is a null reference</exception>
 public bool AdjacentEdgesEmpty(DataTableVertex v)
 {
     if (v==null)
         throw new ArgumentNullException("v");
     return this.OutEdgesEmpty(v) && this.InEdgesEmpty(v);
 }
Ejemplo n.º 10
0
 public void Remove(DataTableVertex key)
 {
     this.Dictionary.Remove(key);
 }
Ejemplo n.º 11
0
 public bool Contains(DataTableVertex key)
 {
     return this.Dictionary.Contains(key);
 }
Ejemplo n.º 12
0
 public void Add(DataTableVertex u)
 {
     Debug.Assert(u!=null);
     this.Dictionary.Add(u, new DataRelationEdgeCollection() );
 }
Ejemplo n.º 13
0
 public DataRelationEdgeCollection this[DataTableVertex v]
 {
     get
     {
         return (DataRelationEdgeCollection)this.Dictionary[v];
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Add a new vertex from source to target
        ///  
        /// Complexity: 2 search + 1 insertion
        /// </summary>
        /// <param name="source">Source vertex</param>
        /// <param name="target">Target vertex</param>
        /// <returns>Created Edge</returns>
        /// <exception cref="ArgumentNullException">
        /// source or target is a null reference
        /// </exception>
        /// <exception cref="Exception">source or target are not part of the graph</exception>
        protected virtual DataRelationEdge AddEdge(
            DataTableVertex source,
            DataTableVertex target,
            DataRelation relation
            )
        {
            // look for the vertex in the list
            if (!this.vertexOutEdges.Contains(source))
                throw new VertexNotFoundException("Could not find source vertex");
            if (!this.vertexOutEdges.Contains(target))
                throw new VertexNotFoundException("Could not find target vertex");
            if (relation==null)
                throw new ArgumentNullException("relation");

            // if parralel edges are not allowed check if already in the graph
            if (!this.AllowParallelEdges)
            {
                if (ContainsEdge(source,target))
                    throw new Exception("Parallel edge not allowed");
            }

            this.version++;
            // create edge
            DataRelationEdge e = (DataRelationEdge)this.EdgeProvider.ProvideEdge(source,target);
            this.vertexOutEdges[source].Add(e);
            this.vertexInEdges[target].Add(e);

            e.Relation = relation;
            this.relationEdges.Add(relation,e);

            return e;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Gets a value indicating if the set of out-edges is empty
 /// </summary>
 /// <remarks>
 /// <para>
 /// Usually faster that calling <see cref="OutDegree"/>.
 /// </para>
 /// </remarks>
 /// <value>
 /// true if the out-edge set is empty, false otherwise.
 /// </value>
 /// <exception cref="ArgumentNullException">
 /// v is a null reference (Nothing in Visual Basic)
 /// </exception>
 /// <exception cref="VertexNotFoundException">
 /// v is not part of the graph.
 /// </exception>
 public bool OutEdgesEmpty(DataTableVertex v)
 {
     if (v == null)
         throw new ArgumentNullException("v");
     DataRelationEdgeCollection edges = this.vertexOutEdges[v];
     if (edges==null)
         throw new VertexNotFoundException(v.ToString());
     return edges.Count==0;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Remove the edge (u,v) from the graph. 
        /// If the graph allows parallel edges this remove all occurrences of 
        /// (u,v).
        /// </summary>
        /// <param name="u">source vertex</param>
        /// <param name="v">target vertex</param>
        public virtual void RemoveEdge(DataTableVertex u, DataTableVertex v)
        {
            if (u == null)
                throw new ArgumentNullException("u");
            if (v == null)
                throw new ArgumentNullException("v");

            this.version++;
            // getting out-edges
            DataRelationEdgeCollection outEdges = this.vertexOutEdges[u];

            // marking edges to remove
            DataRelationEdgeCollection removedEdges = new DataRelationEdgeCollection();
            foreach(DataRelationEdge e in outEdges)
            {
                if (e.Target == v)
                    removedEdges.Add(e);
            }
            //removing out-edges
            foreach(DataRelationEdge e in removedEdges)
                outEdges.Remove(e);

            removedEdges.Clear();
            DataRelationEdgeCollection inEdges = this.vertexInEdges[v];
            foreach(DataRelationEdge e in inEdges)
            {
                if (e.Source == u)
                    removedEdges.Add(e);
            }
            //removing in-edges
            foreach(DataRelationEdge e in removedEdges)
                inEdges.Remove(e);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets an enumerable collection of adjacent vertices
 /// </summary>
 /// <param name="v"></param>
 /// <returns>Enumerable collection of adjacent vertices</returns>
 public IVertexEnumerable AdjacentVertices(DataTableVertex v)
 {
     return new TargetVertexEnumerable(this.OutEdges(v));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Removes the vertex from the graph.
        /// </summary>
        /// <param name="v">vertex to remove</param>
        /// <exception cref="ArgumentNullException">v is null</exception>
        public virtual void RemoveVertex(DataTableVertex v)
        {
            if (v == null)
                throw new ArgumentNullException("v");
            if (!ContainsVertex(v))
                throw new VertexNotFoundException("v");

            this.version++;
            this.ClearVertex(v);

            // removing vertex
            this.vertexOutEdges.Remove(v);
            this.vertexInEdges.Remove(v);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Remove all edges to and from vertex u from the graph.
        /// </summary>
        /// <param name="v"></param>
        public virtual void ClearVertex(DataTableVertex v)
        {
            if (v == null)
                throw new ArgumentNullException("vertex");

            this.version++;
            // removing edges touching v
            this.RemoveEdgeIf(new IsAdjacentEdgePredicate(v));

            // removing edges
            this.vertexOutEdges[v].Clear();
            this.vertexInEdges[v].Clear();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Returns the first out-edge that matches the predicate
        /// </summary>
        /// <param name="v"></param>
        /// <param name="ep">Edge predicate</param>
        /// <returns>null if not found, otherwize the first Edge that
        /// matches the predicate.</returns>
        /// <exception cref="ArgumentNullException">v or ep is null</exception>
        public DataRelationEdge SelectSingleOutEdge(DataTableVertex v, IEdgePredicate ep)
        {
            if (ep==null)
                throw new ArgumentNullException("ep");

            foreach(DataRelationEdge e in this.SelectOutEdges(v,ep))
                return e;

            return null;
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Test is an edge (u,v) is part of the graph
 /// </summary>
 /// <param name="u">source vertex</param>
 /// <param name="v">target vertex</param>
 /// <returns>true if part of the graph</returns>
 public bool ContainsEdge(DataTableVertex u,DataTableVertex v)
 {
     // try to find the edge
     foreach(DataRelationEdge e in this.OutEdges(u))
     {
         if (e.Target == v)
             return true;
     }
     return false;
 }