public static bool Equate <TVertex, TEdge>(
     [CanBeNull] IEdgeListGraph <TVertex, TEdge> g,
     [CanBeNull] IEdgeListGraph <TVertex, TEdge> h)
     where TEdge : IEdge <TVertex>
 {
     return(Equate(g, h, EqualityComparer <TVertex> .Default, EqualityComparer <TEdge> .Default));
 }
Exemple #2
0
 public static string ToSvg <TVertex, TEdge>(
     [NotNull] this IEdgeListGraph <TVertex, TEdge> graph,
     [NotNull, InstantHandle] Action <GraphvizAlgorithm <TVertex, TEdge> > initAlgorithm)
     where TEdge : IEdge <TVertex>
 {
     throw new NotSupportedException("Conversion via external web service no longer supported.");
 }
Exemple #3
0
        /// <summary>
        /// Picks an edge randomly in the edge list
        /// </summary>
        /// <param name="g">edge list</param>
        /// <param name="rnd">random generator</param>
        /// <returns>randomaly chosen edge</returns>
        public static IEdge Edge(IEdgeListGraph g, Random rnd)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (rnd == null)
            {
                throw new ArgumentNullException("random generator");
            }
            if (g.EdgesCount == 0)
            {
                throw new ArgumentException("g is empty");
            }

            int i = rnd.Next(g.EdgesCount);

            foreach (IEdge e in g.Edges)
            {
                if (i == 0)
                {
                    return(e);
                }
                else
                {
                    --i;
                }
            }

            // failed
            throw new Exception();
        }
Exemple #4
0
 public static void Visualize <TVertex, TEdge>(this IEdgeListGraph <TVertex, TEdge> graph,
                                               string dotProgramLocation, string outputFullFileName)
     where TEdge : IEdge <TVertex>
     where TVertex : ExpansionTreeNode
 {
     Visualize(graph, dotProgramLocation, outputFullFileName, NoOpEdgeFormatter);
 }
Exemple #5
0
        public MsaglIndentifiableGraphPopulator(IEdgeListGraph <TVertex, TEdge> visitedGraph, VertexIdentity <TVertex> vertexIdentities)
            : base(visitedGraph)
        {
            Contract.Requires(vertexIdentities != null);

            this.vertexIdentities = vertexIdentities;
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MsaglIdentifiableGraphPopulator{TVertex,TEdge}"/> class.
 /// </summary>
 /// <param name="visitedGraph">Graph to convert to MSAGL graph.</param>
 /// <param name="vertexIdentity">Delegate that given a vertex return its identifier.</param>
 public MsaglIdentifiableGraphPopulator(
     [NotNull] IEdgeListGraph <TVertex, TEdge> visitedGraph,
     [NotNull] VertexIdentity <TVertex> vertexIdentity)
     : base(visitedGraph)
 {
     _vertexIdentity = vertexIdentity ?? throw new ArgumentNullException(nameof(vertexIdentity));
 }
Exemple #7
0
        public static string ToGraphviz <TVertex, TEdge>([NotNull] this IEdgeListGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            var algorithm = new GraphvizAlgorithm <TVertex, TEdge>(graph);

            return(algorithm.Generate());
        }
Exemple #8
0
 public static string ToSvg <TVertex, TEdge>(
     [NotNull] this IEdgeListGraph <TVertex, TEdge> graph,
     [NotNull, InstantHandle] Action <GraphvizAlgorithm <TVertex, TEdge> > initAlgorithm)
     where TEdge : IEdge <TVertex>
 {
     return(ToSvg(ToGraphviz(graph, initAlgorithm)));
 }
		/// <summary>
		/// Construct a graph that filters edges
		/// </summary>
		/// <param name="g">graph to filter</param>
		/// <param name="edgePredicate">edge predicate</param>
		/// <param name="vertexPredicate">vertex predicate</param>
		/// <exception cref="ArgumentNullException">
		/// g or edgePredicate or vertexPredicate is null
		/// </exception>
		public FilteredEdgeListGraph(
			IEdgeListGraph g, 
			IEdgePredicate edgePredicate,
			IVertexPredicate vertexPredicate
			)
			: base(g,edgePredicate,vertexPredicate)
		{}
Exemple #10
0
 /// <summary>
 /// Creates an <see cref="MsaglGraphPopulator{TVertex,TEdge}"/>.
 /// </summary>
 /// <typeparam name="TVertex">Vertex type.</typeparam>
 /// <typeparam name="TEdge">Edge type.</typeparam>
 /// <param name="graph">Graph to convert to MSAGL graph.</param>
 /// <param name="vertexIdentity">Delegate that given a vertex return its identifier.</param>
 /// <returns>Graph populator.</returns>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="graph"/> is <see langword="null"/>.</exception>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="vertexIdentity"/> is <see langword="null"/>.</exception>
 public static MsaglGraphPopulator <TVertex, TEdge> CreateMsaglPopulator <TVertex, TEdge>(
     [NotNull] this IEdgeListGraph <TVertex, TEdge> graph,
     [NotNull] VertexIdentity <TVertex> vertexIdentity)
     where TEdge : IEdge <TVertex>
 {
     return(new MsaglIdentifiableGraphPopulator <TVertex, TEdge>(graph, vertexIdentity));
 }
Exemple #11
0
        public static void AssertEquivalentGraphs <TVertex, TEdge>(
            [NotNull] IEdgeListGraph <TVertex, TEdge> expected,
            [NotNull] IEdgeListGraph <TVertex, TEdge> actual)
            where TEdge : IEdge <TVertex>
        {
            Assert.AreEqual(expected.IsDirected, actual.IsDirected);
            Assert.AreEqual(expected.AllowParallelEdges, actual.AllowParallelEdges);

            if (expected.IsVerticesEmpty)
            {
                AssertNoVertex(actual);
            }
            else
            {
                AssertHasVertices(actual, expected.Vertices);
            }

            if (expected.IsEdgesEmpty)
            {
                AssertNoEdge(actual);
            }
            else
            {
                AssertHasEdges(actual, expected.Edges);
            }
        }
Exemple #12
0
        public static GraphvizAlgorithm <HeapObject, TEdge> ToLeakGraphviz <TEdge> (this IEdgeListGraph <HeapObject, TEdge> graph, Heapshot heapshot) where TEdge : IEdge <HeapObject>
        {
            var graphviz = new GraphvizAlgorithm <HeapObject, TEdge> (graph);

            graphviz.FormatVertex += (sender, e) => {
                var currentObj = e.Vertex;

                // Look up the object and set its type name.
                var typeName = currentObj.TypeInfo.Name;

                var formatter = e.VertexFormatter;

                e.VertexFormatter.Label = typeName;
                // Append root information.
                if (heapshot.Roots.TryGetValue(currentObj.Address, out var rootRegisterEvent))
                {
                    e.VertexFormatter.Label = $"{typeName}\\nRoot Kind: {rootRegisterEvent.Source.ToString ()}";
                    e.VertexFormatter.Shape = QuickGraph.Graphviz.Dot.GraphvizVertexShape.Box;
                }
                else
                {
                    e.VertexFormatter.Label = typeName;
                }
            };

            return(graphviz);
        }
Exemple #13
0
        /// <summary>
        /// Converts <paramref name="graph"/> to an <see cref="Microsoft.Msagl.Drawing.Graph"/>.
        /// </summary>
        /// <typeparam name="TVertex">Vertex type.</typeparam>
        /// <typeparam name="TEdge">Edge type.</typeparam>
        /// <param name="graph">Graph to convert to MSAGL graph.</param>
        /// <param name="nodeAdded">Node added delegate.</param>
        /// <param name="edgeAdded">Edge added delegate.</param>
        /// <returns>MSAGL Graph.</returns>
        public static Graph ToMsaglGraph <TVertex, TEdge>(
            [NotNull] this IEdgeListGraph <TVertex, TEdge> graph,
            [CanBeNull] MsaglVertexNodeEventHandler <TVertex> nodeAdded  = null,
            [CanBeNull] MsaglEdgeEventHandler <TVertex, TEdge> edgeAdded = null)
            where TEdge : IEdge <TVertex>
        {
            MsaglGraphPopulator <TVertex, TEdge> populator = CreateMsaglPopulator(graph);

            try
            {
                if (nodeAdded != null)
                {
                    populator.NodeAdded += nodeAdded;
                }
                if (edgeAdded != null)
                {
                    populator.EdgeAdded += edgeAdded;
                }

                populator.Compute();
                return(populator.MsaglGraph);
            }
            finally
            {
                if (nodeAdded != null)
                {
                    populator.NodeAdded -= nodeAdded;
                }
                if (edgeAdded != null)
                {
                    populator.EdgeAdded -= edgeAdded;
                }
            }
        }
Exemple #14
0
 public static void AssertEmptyGraph <TVertex, TEdge>(
     IEdgeListGraph <TVertex, TEdge> graph)
     where TEdge : IEdge <TVertex>
 {
     AssertNoVertex(graph);
     AssertNoEdge(graph);
 }
Exemple #15
0
 public static bool InEdgeSet <TVertex, TEdge>(
     IEdgeListGraph <TVertex, TEdge> graph,
     TEdge edge)
     where TEdge : IEdge <TVertex>
 {
     return(InVertexSet(graph, edge) && graph.ContainsEdge(edge));
 }
 public static GleeGraphPopulator <TVertex, TEdge> CreateIdentifiableGleePopulator <TVertex, TEdge>(
     this IEdgeListGraph <TVertex, TEdge> visitedGraph,
     VertexIdentity <TVertex> vertexIdentities)
     where TEdge : IEdge <TVertex>
 {
     return(new GleeIndentifiableGraphPopulator <TVertex, TEdge>(visitedGraph, vertexIdentities));
 }
Exemple #17
0
        public static TEdge GetEdge <TVertex, TEdge>(IEdgeListGraph <TVertex, TEdge> g, Random rnd)
            where TEdge : IEdge <TVertex>
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (rnd == null)
            {
                throw new ArgumentNullException("random generator");
            }
            if (g.EdgeCount == 0)
            {
                throw new ArgumentException("g is empty");
            }

            int i = rnd.Next(g.EdgeCount);

            foreach (TEdge e in g.Edges)
            {
                if (i == 0)
                {
                    return(e);
                }
                else
                {
                    --i;
                }
            }

            // failed
            throw new InvalidOperationException("Could not find edge");
        }
 public EdgeCoverageMetric(IEdgeListGraph graph)
 {
     if (graph == null)
     {
         throw new ArgumentNullException("graph");
     }
     this.graph = graph;
 }
Exemple #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitiveClosureAlgorithm{TVertex,TEdge}"/> class.
 /// </summary>
 /// <param name="visitedGraph">Graph to visit.</param>
 /// <param name="edgeFactory">Function that create an edge between the 2 given vertices.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="visitedGraph"/> is <see langword="null"/>.</exception>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="edgeFactory"/> is <see langword="null"/>.</exception>
 public TransitiveClosureAlgorithm(
     [NotNull] IEdgeListGraph <TVertex, TEdge> visitedGraph,
     [NotNull] Func <TVertex, TVertex, TEdge> edgeFactory)
     : base(visitedGraph)
 {
     TransitiveClosure = new BidirectionalGraph <TVertex, TEdge>();
     _createEdge       = edgeFactory ?? throw new ArgumentNullException(nameof(edgeFactory));
 }
Exemple #20
0
        //TODO: Add [BsonConstructor] to constructors in all entities
        public GridModel(IEdgeListGraph <string, Edge <string> > graph, Dictionary <Edge <string>, double> edgeCost) : base()
        {
            var graphviz = new GraphvizAlgorithm <string, Edge <string> >(graph);

            Dot      = graphviz.Generate();
            Graph    = JsonConvert.SerializeObject(graph);
            EdgeCost = JsonConvert.SerializeObject(edgeCost);
        }
Exemple #21
0
 /// <summary>
 /// Construct a graph that filters edges
 /// </summary>
 /// <param name="g">graph to filter</param>
 /// <param name="edgePredicate">edge predicate</param>
 /// <param name="vertexPredicate">vertex predicate</param>
 /// <exception cref="ArgumentNullException">
 /// g or edgePredicate or vertexPredicate is null
 /// </exception>
 public FilteredEdgeListGraph(
     IEdgeListGraph g,
     IEdgePredicate edgePredicate,
     IVertexPredicate vertexPredicate
     )
     : base(g, edgePredicate, vertexPredicate)
 {
 }
Exemple #22
0
 public EdgeCoverageMetric(IEdgeListGraph graph)
 {
     if (graph == null)
     {
         throw new ArgumentNullException("graph");
     }
     this.graph = graph;
 }
Exemple #23
0
 /// <summary>
 /// Creates an <see cref="MsaglGraphPopulator{TVertex,TEdge}"/>.
 /// </summary>
 /// <typeparam name="TVertex">Vertex type.</typeparam>
 /// <typeparam name="TEdge">Edge type.</typeparam>
 /// <param name="graph">Graph to convert to MSAGL graph.</param>
 /// <param name="format">Graph format.</param>
 /// <param name="formatProvider">Graph format provider.</param>
 /// <returns>Graph populator.</returns>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="graph"/> is <see langword="null"/>.</exception>
 public static MsaglGraphPopulator <TVertex, TEdge> CreateMsaglPopulator <TVertex, TEdge>(
     [NotNull] this IEdgeListGraph <TVertex, TEdge> graph,
     [CanBeNull] string format,
     [CanBeNull] IFormatProvider formatProvider = null)
     where TEdge : IEdge <TVertex>
 {
     return(new MsaglToStringGraphPopulator <TVertex, TEdge>(graph, format, formatProvider));
 }
Exemple #24
0
 public static bool InVertexSet <TVertex, TEdge>(
     IEdgeListGraph <TVertex, TEdge> graph,
     TEdge edge)
     where TEdge : IEdge <TVertex>
 {
     return(InVertexSet(graph, edge.Source) &&
            InVertexSet(graph, edge.Target));
 }
 public static GleeGraphPopulator <TVertex, TEdge> CreateGleePopulator <TVertex, TEdge>(
     this IEdgeListGraph <TVertex, TEdge> visitedGraph,
     IFormatProvider formatProvider,
     string format)
     where TEdge : IEdge <TVertex>
 {
     return(new GleeToStringGraphPopulator <TVertex, TEdge>(visitedGraph, formatProvider, format));
 }
Exemple #26
0
 /// <summary>
 /// Returns the last edge of the graph
 /// </summary>
 /// <param name="g">graph</param>
 /// <returns>last edge if any, otherwise a null reference</returns>
 public static IEdge LastEdge(IEdgeListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     return(LastEdge(g.Edges));
 }
Exemple #27
0
 public static void AssertEdgeCountEqual <TVertex, TEdge>(
     this IEdgeListGraph <TVertex, TEdge> left,
     IEdgeListGraph <TVertex, TEdge> right)
     where TEdge : IEdge <TVertex>
 {
     Assert.IsNotNull(left);
     Assert.IsNotNull(right);
     Assert.AreEqual(left.EdgeCount, right.EdgeCount);
 }
Exemple #28
0
        public static MsaglGraphPopulator <TVertex, TEdge> CreateMsaglPopulator <TVertex, TEdge>(
#if !NET20
            this
#endif
            IEdgeListGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            return(new MsaglDefaultGraphPopulator <TVertex, TEdge>(visitedGraph));
        }
Exemple #29
0
 public static void AssertAreEquivalent <TVertex, TEdge>(
     [NotNull] IEdgeListGraph <TVertex, TEdge> graph,
     [NotNull] Graph msaglGraph)
     where TEdge : IEdge <TVertex>
 {
     Assert.AreEqual(graph.IsDirected, msaglGraph.Directed);
     Assert.AreEqual(graph.VertexCount, msaglGraph.NodeCount);
     Assert.AreEqual(graph.EdgeCount, msaglGraph.EdgeCount);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MsaglToStringGraphPopulator{TVertex,TEdge}"/> class.
 /// </summary>
 /// <param name="visitedGraph">Graph to convert to MSAGL graph.</param>
 /// <param name="formatProvider">Graph format provider.</param>
 /// <param name="format">Graph format.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="visitedGraph"/> is <see langword="null"/>.</exception>
 public MsaglToStringGraphPopulator(
     [NotNull] IEdgeListGraph <TVertex, TEdge> visitedGraph,
     [CanBeNull] string format = null,
     [CanBeNull] IFormatProvider formatProvider = null)
     : base(visitedGraph)
 {
     FormatProvider = formatProvider;
     Format         = string.IsNullOrEmpty(format) ? "{0}" : format;
 }
Exemple #31
0
        public static Microsoft.Msagl.Drawing.Graph ToMsaglGraph <TVertex, TEdge>(
#if !NET20
            this
#endif
            IEdgeListGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            return(ToMsaglGraph <TVertex, TEdge>(visitedGraph, null, null));
        }
Exemple #32
0
        public static void ShowMsaglGraph <TVertex, TEdge>(
#if !NET20
            this
#endif
            IEdgeListGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            ShowDialog(ToMsaglGraph(visitedGraph));
        }
Exemple #33
0
		public void Iteration(IEdgeListGraph g)
		{
			int n = g.EdgesCount;
			int i = 0;
			foreach(IEdge e in g.Edges)
			{
				e.ToString();
				++i;
			}
		}
        public static void OutputUndirectedGraph(IEdgeListGraph<int, TaggedEdge<int, string>> graph, string filename)
        {
            var graphviz = new GraphvizAlgorithm<int, TaggedEdge<int, string>>(graph);

            graphviz.FormatVertex += graphviz_FormatVertex;
            graphviz.FormatEdge += graphviz_FormatEdge;

            graphviz.Generate(new FileDotEngineUndirected(), filename);

            // "C:\Program Files (x86)\Graphviz 2.28\bin\dot.exe" -Tbmp -ograph.bmp graph.dot
        }
Exemple #35
0
		public void Count(IEdgeListGraph g)
		{
			int n = g.EdgesCount;
			if (n==0)
				Assert.IsTrue(g.EdgesEmpty);

			int i = 0;
			foreach(IEdge e in g.Edges)
			{
				e.ToString();
				++i;
			}
			Assert.AreEqual(n,i);
		}
Exemple #36
0
        /// <summary>
        /// Picks an edge randomly in the edge list
        /// </summary>
        /// <param name="g">edge list</param>
        /// <param name="rnd">random generator</param>
        /// <returns>randomaly chosen edge</returns>
        public static IEdge Edge(IEdgeListGraph g, Random rnd)
        {
            if (g == null)
                throw new ArgumentNullException("g");
            if (rnd == null)
                throw new ArgumentNullException("random generator");
            if (g.EdgesCount == 0)
                throw new ArgumentException("g is empty");

            int i = rnd.Next(g.EdgesCount);
            foreach(IEdge e in g.Edges)
            {
                if (i==0)
                    return e;
                else
                    --i;
            }

            // failed
            throw new Exception();
        }
Exemple #37
0
		/// <summary>
		/// Checks wheter an edge that goes from source to target 
		/// belongs to the edge set
		/// </summary>
		/// <param name="g">graph containing the edge set</param>
		/// <param name="source">edge source</param>
		/// <param name="target">edge target</param>
		/// <returns>true if e is in the graph edge set</returns>
		public static bool IsInEdgeSet(
			IEdgeListGraph g, 
			IVertex source, 
			IVertex target)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (source==null)
				throw new ArgumentNullException("source");
			if (target==null)
				throw new ArgumentNullException("target");
	
			foreach(IEdge e in g.Edges)
			{
				if (g.IsDirected)
					if (e.Source==source && e.Target==target)
						return true;
					else
						if ((e.Source==source && e.Target==target)
						|| (e.Source==target && e.Target==source))
						return true;
			}
			return false;
		}
Exemple #38
0
		/// <summary>
		/// Checks wheter an edge belongs to the edge set
		/// </summary>
		/// <param name="g">graph containing the edge set</param>
		/// <param name="e">edge to test</param>
		/// <returns>true if e is in the graph edge set</returns>
		public static bool IsInEdgeSet(IEdgeListGraph g, IEdge e)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (e==null)
				throw new ArgumentNullException("e");			
	
			foreach(IEdge ei in g.Edges)
				if (ei==e)
					return true;
			return false;
		}
 public static EdgeDoubleDictionary UnaryWeightsFromEdgeList(IEdgeListGraph graph)
 {
     if (graph == null)
     {
         throw new ArgumentNullException("graph");
     }
     EdgeDoubleDictionary dictionary = new EdgeDoubleDictionary();
     IEdgeEnumerator enumerator = graph.get_Edges().GetEnumerator();
     while (enumerator.MoveNext())
     {
         IEdge edge = enumerator.get_Current();
         dictionary.set_Item(edge, 1.0);
     }
     return dictionary;
 }
		/// <summary>
		/// Construct a graph that filters edges
		/// </summary>
		/// <param name="g">graph to filter</param>
		/// <param name="edgePredicate">edge predicate</param>
		/// <exception cref="ArgumentNullException">
		/// g or edgePredicate is null
		/// </exception>
		public FilteredEdgeListGraph(
			IEdgeListGraph g, 
			IEdgePredicate edgePredicate)
			: base(g,edgePredicate)
		{}
		/// <summary>
		/// Create a edge unary weight dictionary.
		/// </summary>
		/// <param name="graph">graph to map</param>
		/// <returns>Dictionary where each edge wheight is 1</returns>
		public static EdgeDoubleDictionary UnaryWeightsFromEdgeList(IEdgeListGraph graph)
		{
			if (graph==null)
				throw new ArgumentNullException("graph");
			EdgeDoubleDictionary weights=new EdgeDoubleDictionary();
			foreach(IEdge e in graph.Edges)
				weights[e]=1;
			return weights;
		}
 /// <summary>
 /// Returns the first edge of the graph
 /// </summary>
 /// <param name="g">graph</param>
 /// <returns>first edge if any, otherwise a null reference</returns>
 public static IEdge FirstEdge(IEdgeListGraph g)
 {
     if (g==null)
         throw new ArgumentNullException("g");
     return FirstEdge(g.Edges);
 }