public void DrawTour(TSPStats stats) { lock (Lock) { Graphics g = this.GetGraphics(); this.Clear(g); TSPTour Tour = (TSPTour)stats.solution; TSPCity[] cities = Tour.GetCities(); TSPCity from, to; int[] tour = Tour.GetTour(); // 1. draw tour for (int i = 0; i < tour.Length; i++) { from = cities[tour[i]]; to = cities[tour[(i + 1) % tour.Length]]; this.DrawPath(g, from, to); } // 2. draw cities foreach (TSPCity city in cities) { this.DrawCity(g, city); } // 3. draw stats this.DrawStats(g, stats); g.Flush(); g.Dispose(); } // refresh display this.form.Invoke(new Action(() => { lock (Lock) { this.pb.Image = this.bitmap; } })); }
private void DrawStats(Graphics g, TSPStats stats) { TSPTour Tour = (TSPTour)stats.solution; string text = ""; text += String.Format("Score: {0}\n", Tour.Score()); text += String.Format("Iterations: {0}\n", stats.iterations); text += String.Format("Cities: {0}\n", Tour.GetCities().Length); if (stats.working) { text += String.Format("Heat: {0}\n", stats.heat); text += "Searching..."; } RectangleF pos = new RectangleF(2, 2, this.bitmap.Width - 2, this.bitmap.Height - 2); g.DrawString(text, TEXT_FONT, TEXT_BRUSH, pos); }