Ejemplo n.º 1
0
        public void AddEdgeTargetNotFound(IEdgeMutableGraph g)
        {
            IVertex u = g.AddVertex();
            IVertex v = g.AddVertex();

            g.RemoveVertex(v);
            IEdge e = g.AddEdge(u, v);
        }
Ejemplo n.º 2
0
        public void RemoveEdge(IEdgeMutableGraph g)
        {
            IVertex v = g.AddVertex();
            IVertex u = g.AddVertex();
            IEdge   e = g.AddEdge(u, v);

            g.RemoveEdge(e);
        }
Ejemplo n.º 3
0
        public void AddEdge(IEdgeMutableGraph g)
        {
            IVertex v = g.AddVertex();
            IVertex u = g.AddVertex();
            IEdge   e = g.AddEdge(u, v);

            Assert.AreEqual(e.Source, u);
            Assert.AreEqual(e.Target, v);
        }
Ejemplo n.º 4
0
        public void ClearVertexTargetSource(IEdgeMutableGraph g)
        {
            IVertex u = g.AddVertex();
            IVertex v = g.AddVertex();

            g.AddEdge(u, v);
            g.ClearVertex(v);
            g.ClearVertex(u);
        }
Ejemplo n.º 5
0
        public void RemoveEdgeNotFound()
        {
            IEdgeMutableGraph g = Graph;
            IVertex           v = g.AddVertex();
            IVertex           u = g.AddVertex();
            IEdge             e = g.AddEdge(u, v);

            g.RemoveEdge(e);
            g.RemoveEdge(e);
        }
Ejemplo n.º 6
0
        public void ClearVertexSourceTarget()
        {
            IEdgeMutableGraph g = Graph;
            IVertex           v = g.AddVertex();
            IVertex           u = g.AddVertex();

            g.AddEdge(u, v);
            g.ClearVertex(u);
            g.ClearVertex(v);
        }
Ejemplo n.º 7
0
        public void AddRemoveVertexNotFound(IEdgeMutableGraph g)
        {
            IVertex v = g.AddVertex();

            g.RemoveVertex(v);
            g.RemoveVertex(v);
        }
Ejemplo n.º 8
0
        public void AddRemoveVertex()
        {
            IEdgeMutableGraph g = Graph;
            IVertex           v = g.AddVertex();

            g.RemoveVertex(v);
        }
Ejemplo n.º 9
0
 public void AddEdgeTargetNotFound()
 {
     IEdgeMutableGraph g  = Graph;
     IEdgeMutableGraph g2 = Graph;
     IVertex           v  = g.AddVertex();
     IVertex           u  = g2.AddVertex();
     IEdge             e  = g.AddEdge(v, u);
 }
Ejemplo n.º 10
0
 public void AddEdgeSourceNotFound()
 {
     IEdgeMutableGraph g  = Graph;
     IEdgeMutableGraph g2 = Graph;
     IVertex           v  = g.AddVertex();
     IVertex           u  = g2.AddVertex();
     IEdge             e  = g.AddEdge(u, v);
 }
Ejemplo n.º 11
0
        public void AddRemoveVertexNotFound()
        {
            IEdgeMutableGraph g  = Graph;
            IEdgeMutableGraph g2 = Graph;
            IVertex           v  = g2.AddVertex();

            g.RemoveVertex(v);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Generates a random graph
        /// </summary>
        /// <param name="g">Graph to fill</param>
        /// <param name="V">number of vertices</param>
        /// <param name="E">number of edges</param>
        /// <param name="rnd">random generator</param>
        /// <param name="selfEdges">self edges allowed</param>
        public static void Graph(
            IEdgeMutableGraph g,
            int V,
            int E,
            Random rnd,
            bool selfEdges
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (rnd == null)
            {
                throw new ArgumentNullException("random generator");
            }

            IVertex a = null;
            IVertex b = null;

            // When parallel edges are not allowed, we create a new graph which
            // does not allow parallel edges, construct it and copy back.
            // This is not efficient if 'g' already disallow parallel edges,
            // but that's task for later.
            if (!g.AllowParallelEdges)
            {
                throw new Exception("not implemented");
            }
            else
            {
                for (int i = 0; i < V; ++i)
                {
                    g.AddVertex();
                }

                for (int j = 0; j < E; ++j)
                {
                    a = Vertex((IVertexListGraph)g, rnd);
                    do
                    {
                        b = Vertex((IVertexListGraph)g, rnd);
                    }while (selfEdges == false && a == b);

                    g.AddEdge(a, b);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Generates a random graph
        /// </summary>
        /// <param name="g">Graph to fill</param>
        /// <param name="vertexCount">number of vertices</param>
        /// <param name="edgeCount">number of edges</param>
        /// <param name="rnd">random generator</param>
        /// <param name="selfEdges">self edges allowed</param>
        public static void Graph(
            IEdgeMutableGraph g,
            int vertexCount,
            int edgeCount,
            Random rnd,
            bool selfEdges
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (rnd == null)
            {
                throw new ArgumentNullException("random generator");
            }

            IVertex a = null;
            IVertex b = null;

            for (int i = 0; i < vertexCount; ++i)
            {
                g.AddVertex();
            }


            int j = 0;

            while (j < edgeCount)
            {
                a = Vertex((IVertexListGraph)g, rnd);
                do
                {
                    b = Vertex((IVertexListGraph)g, rnd);
                }while (selfEdges == false && a == b);
                try
                {
                    g.AddEdge(a, b);
                    ++j;
                }
                catch (Exception)
                {}
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Clones the <paramref name="source"/> to <paramref name="target"/> and
        /// reverses the edges.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Use this class to create clone of different graphs with possible different
        /// provider types.
        /// </para>
        /// <para>
        /// The <see cref="CloneVertex"/> and <see cref="CloneEdge"/> events can be
        /// used to copy the custom properties
        /// attached to each vertex and edge.
        /// </para>
        /// </remarks>
        public void ReversedClone(IVertexAndEdgeListGraph source, IEdgeMutableGraph target)
        {
            VertexVertexDictionary vertexMap = new VertexVertexDictionary();

            // copy vertices
            foreach (IVertex v in source.Vertices)
            {
                IVertex vc = target.AddVertex();
                // clone properties
                OnCloneVertex(v, vc);
                // store in table
                vertexMap[v] = vc;
            }

            // copy edges
            foreach (IEdge e in source.Edges)
            {
                IEdge ec = target.AddEdge(vertexMap[e.Target], vertexMap[e.Source]);
                // cone properties
                OnCloneEdge(e, ec);
            }
        }
Ejemplo n.º 15
0
		/// <summary>
		/// Makes a copy of the source graph to the clone graph.
		/// </summary>
		/// <param name="source">source graph</param>
		/// <param name="target">clone graph</param>
		public void Clone(IVertexAndEdgeListGraph source, IEdgeMutableGraph target)
		{
			VertexVertexDictionary vertexMap = new VertexVertexDictionary();

			// copy vertices
			foreach(IVertex v in source.Vertices)
			{
				IVertex vc = target.AddVertex();
				// clone properties
				OnCloneVertex(v,vc);
				// store in table
				vertexMap[v]=vc;
			}

			// copy edges
			foreach(IEdge e in source.Edges)
			{
				IEdge ec = target.AddEdge(vertexMap[e.Source], vertexMap[e.Target]);
				// cone properties
				OnCloneEdge(e,ec);
			}
		}
Ejemplo n.º 16
0
 public void AddEdgeSourceNotFound(IEdgeMutableGraph g)
 {
     IVertex u  = g.AddVertex();
     g.RemoveVertex(u);
     IVertex v = g.AddVertex();
     IEdge e = g.AddEdge(u,v);
 }
Ejemplo n.º 17
0
        public void AddEdge(IEdgeMutableGraph g)
        {
            IVertex v = g.AddVertex();
            IVertex u  = g.AddVertex();
            IEdge e = g.AddEdge(u,v);

            Assert.AreEqual(e.Source,u);
            Assert.AreEqual(e.Target,v);
        }
Ejemplo n.º 18
0
 public void RemoveEdgeNotFound(IEdgeMutableGraph g)
 {
     IVertex v = g.AddVertex();
     IVertex u  = g.AddVertex();
     IEdge e = g.AddEdge(u,v);
     g.RemoveEdge(e);
     g.RemoveEdge(e);
 }
Ejemplo n.º 19
0
 public void ClearVertexTargetSource(IEdgeMutableGraph g)
 {
     IVertex u  = g.AddVertex();
     IVertex v = g.AddVertex();
     g.AddEdge(u,v);
     g.ClearVertex(v);
     g.ClearVertex(u);
 }
Ejemplo n.º 20
0
 public void AddRemoveVertexNotFound(IEdgeMutableGraph g)
 {
     IVertex v = g.AddVertex();
     g.RemoveVertex(v);
     g.RemoveVertex(v);
 }
Ejemplo n.º 21
0
		/// <summary>
		/// Generates a random graph
		/// </summary>
		/// <param name="g">Graph to fill</param>
		/// <param name="vertexCount">number of vertices</param>
		/// <param name="edgeCount">number of edges</param>
		/// <param name="rnd">random generator</param>
		/// <param name="selfEdges">self edges allowed</param>
		public static void Graph(
			IEdgeMutableGraph g, 
			int vertexCount, 
			int edgeCount, 
			Random rnd, 
			bool selfEdges
			)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			if (rnd == null)
				throw new ArgumentNullException("random generator");

			IVertex a=null;
			IVertex b=null;

			for (int i = 0; i < vertexCount; ++i)
				g.AddVertex();


			int j=0;
			while(j<edgeCount)
			{
				a = Vertex((IVertexListGraph)g, rnd);
				do 
				{
					b = Vertex((IVertexListGraph)g, rnd);
				} 
				while (selfEdges == false && a == b);
				try
				{
					g.AddEdge(a, b);
					++j;
				}
				catch(Exception)
				{}
			}
		}
Ejemplo n.º 22
0
        /// <summary>
        /// Generates a random graph
        /// </summary>
        /// <param name="g">Graph to fill</param>
        /// <param name="V">number of vertices</param>
        /// <param name="E">number of edges</param>
        /// <param name="rnd">random generator</param>
        /// <param name="selfEdges">self edges allowed</param>
        public static void Graph(
            IEdgeMutableGraph g,
            int V,
            int E,
            Random rnd,
            bool selfEdges
            )
        {
            if (g == null)
                throw new ArgumentNullException("g");
            if (rnd == null)
                throw new ArgumentNullException("random generator");

            IVertex a=null;
            IVertex b=null;
            // When parallel edges are not allowed, we create a new graph which
            // does not allow parallel edges, construct it and copy back.
            // This is not efficient if 'g' already disallow parallel edges,
            // but that's task for later.
            if (!g.AllowParallelEdges)
            {
                throw new Exception("not implemented");
            }
            else
            {
                for (int i = 0; i < V; ++i)
                    g.AddVertex();

                for (int j = 0; j < E; ++j)
                {
                    a = Vertex((IVertexListGraph)g, rnd);
                    do
                    {
                        b = Vertex((IVertexListGraph)g, rnd);
                    }
                    while (selfEdges == false && a == b);

                    g.AddEdge(a, b);
                }
            }
        }