Exemple #1
0
        private static results runner(Graph g, string outputFile, Algorithm a)
        {
            Visualizer v = new Visualizer();
            int        i = 0;

            a.start(g);
            var start     = Process.GetCurrentProcess().TotalProcessorTime;
            var stopwatch = Stopwatch.StartNew();

            while (!a.step(g))
            {
                i++;
                if (outputFile != null)
                {
                    string s = String.Format("{0}.{1}", outputFile, i);
                    v.Visualize(g, s);
                }
            }
            stopwatch.Stop();
            var stop = Process.GetCurrentProcess().TotalProcessorTime;

            if (outputFile != null)
            {
                v.Visualize(g, outputFile, 1024, 1024);
            }

            results r = new results();

            r.iterations = i + 1;
            r.runtime    = stopwatch.ElapsedMilliseconds;//(stop - start).TotalMilliseconds;
            r.stats      = GraphStatistics.From(g);
            r.graph      = g;
            return(r);
        }
        /// <summary>
        /// Start visualizing
        /// </summary>
        /// <param name="g">The graph to Visualize</param>
        /// <param name="path">The path to write an image to</param>
        /// <param name="imageWidth">The width of the image file</param>
        /// <param name="imageHeight">The height of the image file</param>
        /// <param name="boundary">The boundary around the graph on the image, so that there's a bit of clear space around the graph</param>
        /// <param name="nodeSize">The diameter of the nodes, in pixels</param>
        public void Visualize(Graph g, string path, int imageWidth = 300, int imageHeight = 300, int boundary = 30, int nodeSize = 5)
        {
            _stats = GraphStatistics.From(g);
            CalculateScale(_stats, imageWidth, imageHeight, boundary);

            _bitmap   = new Bitmap(imageWidth, imageHeight);
            _graphics = Graphics.FromImage(_bitmap);
            _graphics.FillRectangle(_backgroundColor, 0, 0, _bitmap.Width, _bitmap.Height);

            NodeSize = nodeSize;

            DrawGraph(g, path);

            _graphics.Dispose();
            _bitmap.Dispose();
        }