Beispiel #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
                       ));
        }
Beispiel #2
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)
                       ));
        }
Beispiel #3
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();
        }
        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
                );
        }