Example #1
0
        /// <summary>
        /// Populates a DGML graph from a graph
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TEdge"></typeparam>
        /// <param name="visitedGraph"></param>
        /// <param name="vertexColors"></param>
        /// <returns></returns>
        public static DirectedGraph ToDirectedGraphML <TVertex, TEdge>(
#if !NET20
            this
#endif
            IVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph,
            Func <TVertex, GraphColor> vertexColors)
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);
            Contract.Requires(vertexColors != null);
            Contract.Ensures(Contract.Result <DirectedGraph>() != null);

            return(ToDirectedGraphML <TVertex, TEdge>(
                       visitedGraph,
                       AlgorithmExtensions.GetVertexIdentity <TVertex>(visitedGraph),
                       AlgorithmExtensions.GetEdgeIdentity <TVertex, TEdge>(visitedGraph),
                       (v, n) =>
            {
                var color = vertexColors(v);
                switch (color)
                {
                case GraphColor.Black:
                    n.Background = "Black"; break;

                case GraphColor.Gray:
                    n.Background = "LightGray"; break;

                case GraphColor.White:
                    n.Background = "White"; break;
                }
            },
                       null
                       ));
        }
Example #2
0
        public void Repro13482()
        {
            var graph = new AdjacencyGraph <Person, TaggedEdge <Person, string> >();

            Person jacob = new Person("Jacob", "Hochstetler")
            {
                BirthDate  = new DateTime(1712, 01, 01),
                BirthPlace = "Alsace, France",
                DeathDate  = new DateTime(1776, 01, 01),
                DeathPlace = "Pennsylvania, USA",
                Gender     = Gender.Male
            };

            Person john = new Person("John", "Hochstetler")
            {
                BirthDate  = new DateTime(1735, 01, 01),
                BirthPlace = "Alsace, France",
                DeathDate  = new DateTime(1805, 04, 15),
                DeathPlace = "Summit Mills, PA",
                Gender     = Gender.Male
            };

            Person jonathon = new Person("Jonathon", "Hochstetler")
            {
                BirthPlace = "Pennsylvania",
                DeathDate  = new DateTime(1823, 05, 08),
                Gender     = Gender.Male,
            };

            Person emanuel = new Person("Emanuel", "Hochstedler")
            {
                BirthDate = new DateTime(1855, 01, 01),
                DeathDate = new DateTime(1900, 01, 01),
                Gender    = Gender.Male
            };

            graph.AddVerticesAndEdge(new TaggedEdge <Person, string>(jacob, john, jacob.ChildRelationshipText));
            graph.AddVerticesAndEdge(new TaggedEdge <Person, string>(john, jonathon, john.ChildRelationshipText));
            graph.AddVerticesAndEdge(new TaggedEdge <Person, string>(jonathon, emanuel, jonathon.ChildRelationshipText));

            var settings = new XmlWriterSettings()
            {
                Indent = true, IndentChars = @"    "
            };

            using (var writer = XmlWriter.Create(Console.Out, settings))
            {
                SerializationExtensions.SerializeToXml(
                    graph,
                    writer,
                    v => v.Id,
                    AlgorithmExtensions.GetEdgeIdentity(graph),
                    "graph",
                    "person",
                    "relationship",
                    "");
            }
        }
Example #3
0
        /// <summary>
        /// Populates a DGML graph from a graph
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TEdge"></typeparam>
        /// <param name="visitedGraph"></param>
        /// <returns></returns>
        public static DirectedGraph ToDirectedGraphML <TVertex, TEdge>(this IVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);
            Contract.Ensures(Contract.Result <DirectedGraph>() != null);

            return(ToDirectedGraphML <TVertex, TEdge>(
                       visitedGraph,
                       AlgorithmExtensions.GetVertexIdentity <TVertex>(visitedGraph),
                       AlgorithmExtensions.GetEdgeIdentity <TVertex, TEdge>(visitedGraph)
                       ));
        }
        public static void SerializeToGraphML <TVertex, TEdge, TGraph>(
            this TGraph graph, XmlWriter writer)
            where TEdge : IEdge <TVertex>
            where TGraph : IEdgeListGraph <TVertex, TEdge>
        {
            Contract.Requires(graph != null);
            Contract.Requires(writer != null);

            var vertexIdentity = AlgorithmExtensions.GetVertexIdentity <TVertex>(graph);
            var edgeIdentity   = AlgorithmExtensions.GetEdgeIdentity <TVertex, TEdge>(graph);

            SerializeToGraphML <TVertex, TEdge, TGraph>(
                graph,
                writer,
                vertexIdentity,
                edgeIdentity
                );
        }
Example #5
0
        public static void Serialize(Stream stream, MyGraph graph)
        {
            var settings = new XmlWriterSettings
            {
                Indent = true
            };

            using (var writer = XmlWriter.Create(stream, settings))
            {
                graph.SerializeToXml(writer, AlgorithmExtensions.GetVertexIdentity(graph), AlgorithmExtensions.GetEdgeIdentity(graph), "MyGraph", "Job", "MyEdge", "",
                                     (wr, gr) => { },
                                     SerializeNode,
                                     (wr, ed) => { }
                                     );
            }
            stream.Close();
        }