Index: branches/FitnessLandscapeAnalysis/VRPProblemAnalyzer/PictureGenerator.cs
===================================================================
--- branches/FitnessLandscapeAnalysis/VRPProblemAnalyzer/PictureGenerator.cs	(revision 7316)
+++ branches/FitnessLandscapeAnalysis/VRPProblemAnalyzer/PictureGenerator.cs	(revision 7321)
@@ -9,16 +9,18 @@
 namespace VRPProblemAnalyzer {
   public class PictureGenerator {
-    private static int TourSize = 1000;
+
+    private static int TourWidth = 500;
+    private static int TourHeight = 500;
     private static double MinDemandSize = 2;
-    private static double MaxDemandSize = TourSize / 25.0;
+    private static double MaxDemandSize = Math.Min(TourWidth, TourHeight) / 25.0;
 
     private static int TourBorder = (int)Math.Ceiling(MaxDemandSize);
 
-    private static int ChartWidth = TourSize / 2;
-    private static int ChartHeight = 250;
+    private static int ChartWidth = 400;
+    private static int ChartHeight = TourHeight/2;
     
-    private static int DemandSegments = 10;
-
-    private static int DistanceSegments = 10;
+    private static int DemandSegments = 20;
+
+    private static int DistanceSegments = 20;
 
     public static Image GeneratePicture(TSPLIBParser problemInstance, SolutionParser solution) {    
@@ -27,13 +29,31 @@
       Image distanceDistribution = GenerateDistanceDistribution(problemInstance);
 
-      Bitmap bmp = new Bitmap(Math.Max(TourSize, ChartWidth * 2), tourVisualization.Height + ChartHeight);
-      using (Graphics g = Graphics.FromImage(bmp)) {
-        g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
-        g.DrawImage(tourVisualization, 0, 0);
-        g.DrawImage(demandDistribution, 0, tourVisualization.Height);
-        g.DrawImage(distanceDistribution, ChartWidth, tourVisualization.Height); 
-      }
-      return bmp;
-    }
+      SizeF titleSize;
+      using (var font = new Font("Helvetica", 20)) {
+        using (var b = new Bitmap(1, 1)) {
+          using (Graphics g = Graphics.FromImage(b)) {
+            titleSize = g.MeasureString(problemInstance.Name, font);
+          }
+        }
+        Bitmap bmp = new Bitmap(TourWidth+ChartWidth,
+                                Math.Max(TourHeight,  2*ChartHeight) + (int)titleSize.Height);
+        using (Graphics g = Graphics.FromImage(bmp)) {
+          g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
+          g.DrawString(problemInstance.Name, font, Brushes.Black, (bmp.Width-titleSize.Width)/2, 0);
+          g.DrawImage(tourVisualization, (TourWidth-tourVisualization.Width)/2, titleSize.Height+(TourHeight-tourVisualization.Height)/2);
+          g.DrawImage(demandDistribution, TourWidth, titleSize.Height);
+          g.DrawImage(distanceDistribution, TourWidth, ChartHeight + titleSize.Height);
+        }
+        return bmp;
+      }
+    }
+
+    private static Color[] TourColors = new[] {
+      Color.FromArgb(100, 92, 20,237), Color.FromArgb(100,237,183, 20), Color.FromArgb(100,237, 20,219), Color.FromArgb(100, 20,237, 76),
+      Color.FromArgb(100,237, 61, 20), Color.FromArgb(100,115, 78, 26), Color.FromArgb(100, 20,237,229), Color.FromArgb(100, 39,101, 19),
+      Color.FromArgb(100,230,170,229), Color.FromArgb(100,142,136, 89), Color.FromArgb(100,157,217,166), Color.FromArgb(100, 31, 19,101),
+      Color.FromArgb(100,173,237, 20), Color.FromArgb(100,230,231,161), Color.FromArgb(100,142, 89, 89), Color.FromArgb(100, 93, 89,142),
+      Color.FromArgb(100,146,203,217), Color.FromArgb(100,101, 19, 75), Color.FromArgb(100,198, 20,237), Color.FromArgb(100,185,185,185),
+      Color.FromArgb(100,179, 32, 32), Color.FromArgb(100, 18,119,115), Color.FromArgb(100,104,158,239), Color.Black};
 
     private static Image GenerateTourVisualization(TSPLIBParser problemInstance, SolutionParser solution) {
@@ -47,76 +67,42 @@
         if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
       }
-      double xWidth = xMax - xMin;
-      double yHeight = yMax - yMin;
-
-      int width, height;
-      if (xWidth > yHeight) {
-        width = TourSize;
-        height = (int)Math.Round(TourSize * (yHeight / xWidth));
-      } else {
-        width = (int)Math.Round(TourSize * (xWidth / yHeight));
-        height = TourSize;
-      }
-      Bitmap bitmap = new Bitmap(width, height);
-
-      double xStep = (width - 2 * TourBorder) / xWidth;
-      double yStep = (height - 2 * TourBorder) / yHeight;
-
-      Pen[] pens = {new Pen(Color.FromArgb(100, 92,20,237)), new Pen(Color.FromArgb(100, 237,183,20)), new Pen(Color.FromArgb(100, 237,20,219)), new Pen(Color.FromArgb(100, 20,237,76)),
-                    new Pen(Color.FromArgb(100, 237,61,20)), new Pen(Color.FromArgb(100, 115,78,26)), new Pen(Color.FromArgb(100, 20,237,229)), new Pen(Color.FromArgb(100, 39,101,19)),
-                    new Pen(Color.FromArgb(100, 230,170,229)), new Pen(Color.FromArgb(100, 142,136,89)), new Pen(Color.FromArgb(100, 157,217,166)), new Pen(Color.FromArgb(100, 31,19,101)),
-                    new Pen(Color.FromArgb(100, 173,237,20)), new Pen(Color.FromArgb(100, 230,231,161)), new Pen(Color.FromArgb(100, 142,89,89)), new Pen(Color.FromArgb(100, 93,89,142)),
-                    new Pen(Color.FromArgb(100, 146,203,217)), new Pen(Color.FromArgb(100, 101,19,75)), new Pen(Color.FromArgb(100, 198,20,237)), new Pen(Color.FromArgb(100, 185,185,185)),
-                    new Pen(Color.FromArgb(100, 179,32,32)), new Pen(Color.FromArgb(100, 18,119,115)), new Pen(Color.FromArgb(100, 104,158,239)), new Pen(Color.Black)};
-
-      foreach (Pen pen in pens) {
-        pen.Width = 2;
-      }
-
-      using (Graphics graphics = Graphics.FromImage(bitmap)) {
-        graphics.FillRectangle(Brushes.White, 0, 0, width, height);
-
-        int currentTour = 0;
-        foreach (List<int> tour in solution.Routes) {
-          Point[] tourPoints = new Point[tour.Count + 2];
-          int[] customerSizes = new int[tour.Count];
-          int lastCustomer = 0;
-
-          for (int i = -1; i <= tour.Count; i++) {
-            int location = 0;
-
-            if (i == -1 || i == tour.Count)
-              location = 0; //depot
-            else
-              location = tour[i];
-
-            Point locationPoint = new Point(TourBorder + ((int)((coordinates[location, 0] - xMin) * xStep)),
-                            bitmap.Height - (TourBorder + ((int)((coordinates[location, 1] - yMin) * yStep))));
-            tourPoints[i + 1] = locationPoint;
-
-            if (i != -1 && i != tour.Count) {
-              customerSizes[i] = (int)Math.Round(MinDemandSize + problemInstance.Demands[location] / problemInstance.Capacity * (MaxDemandSize - MinDemandSize));
+      double xRange = xMax - xMin;
+      double yRange = yMax - yMin;
+      double scaling = Math.Min((TourWidth-TourBorder*2)/xRange, (TourHeight-TourBorder*2)/yRange);
+      Bitmap bitmap = new Bitmap((int)Math.Ceiling(xRange*scaling+TourBorder*2), (int)Math.Ceiling(yRange*scaling+TourBorder*2));
+      var pens = TourColors.Select(c => new Pen(c, 2)).ToList();
+      using (Graphics g = Graphics.FromImage(bitmap)) {
+        using (var brush = new SolidBrush(Color.FromArgb(100, 0, 0, 0))) {
+          g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
+
+          int currentTour = 0;
+          foreach (List<int> tour in solution.Routes) {
+            Point[] tourPoints = new Point[tour.Count + 2];
+            int[] customerSizes = new int[tour.Count];
+
+            for (int i = -1; i <= tour.Count; i++) {
+              int location = (i == -1 || i == tour.Count) ? 0 : tour[i];
+              Point locationPoint = new Point(TourBorder + ((int) ((coordinates[location, 0] - xMin)*scaling)),
+                                              bitmap.Height -
+                                              (TourBorder + ((int) ((coordinates[location, 1] - yMin)*scaling))));
+              tourPoints[i + 1] = locationPoint;
+              if (i != -1 && i != tour.Count) {
+                customerSizes[i] =
+                  (int)
+                  Math.Round(MinDemandSize +
+                             problemInstance.Demands[location]/problemInstance.Capacity*(MaxDemandSize - MinDemandSize));
+              }
             }
-            lastCustomer = location;
-          }
-
-          graphics.DrawPolygon(pens[((currentTour >= pens.Length) ? (pens.Length - 1) : (currentTour))], tourPoints);
-
-          using(Brush brush = new SolidBrush(Color.FromArgb(100, 0, 0, 0))) {
+            g.DrawPolygon(pens[((currentTour >= pens.Count) ? (pens.Count - 1) : (currentTour))], tourPoints);
             for (int i = 0; i < tour.Count; i++) {
               int size = customerSizes[i];
-              graphics.FillEllipse(brush, tourPoints[i + 1].X - size, tourPoints[i + 1].Y - size, size * 2, size * 2);
+              g.FillEllipse(brush, tourPoints[i + 1].X - size, tourPoints[i + 1].Y - size, size*2, size*2);
             }
+            g.FillRectangle(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
+            currentTour++;
           }
-
-          graphics.FillRectangle(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
-
-          currentTour++;
-        }
-      }
-
-      for (int i = 0; i < pens.Length; i++)
-        pens[i].Dispose();
-
+        }
+      }
+      foreach (var p in pens) p.Dispose();
       return bitmap;
     }
@@ -141,20 +127,14 @@
       chart.Size = new Size(ChartWidth, ChartHeight);
 
-      chart.Titles.Add("Demand Distribution");
       chart.ChartAreas.Add("");
-
-      chart.ChartAreas[0].BackColor = Color.White;
-
-      chart.ChartAreas[0].AxisX.Title = "Demand";
+      ConfigureChartAppearance(chart);
+      chart.ChartAreas[0].AxisX.Title = "Demands";
       chart.ChartAreas[0].AxisX.Minimum = 0;
       chart.ChartAreas[0].AxisX.Maximum = problemInstance.Capacity;
-      chart.ChartAreas[0].AxisX.Interval = problemInstance.Capacity / (double)DemandSegments;
-      chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
-
+      chart.ChartAreas[0].AxisX.Interval = problemInstance.Capacity/DemandSegments;
+      chart.ChartAreas[0].AxisX.LabelStyle.Interval = problemInstance.Capacity/DemandSegments*2;
       chart.ChartAreas[0].AxisY.Title = "Customers";
       chart.ChartAreas[0].AxisY.Minimum = 0;
       chart.ChartAreas[0].AxisY.Maximum = problemInstance.Vertices.GetLength(0);
-      chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
-      chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(100, Color.Blue);
 
       chart.Series.Add("");
@@ -173,4 +153,13 @@
     }
 
+    private static void ConfigureChartAppearance(Chart chart) {
+      chart.ChartAreas[0].BackColor = Color.White;
+      chart.ChartAreas[0].AxisX.TitleFont = new Font("Helvetica", 16);
+      chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
+      chart.ChartAreas[0].AxisY.TitleFont = new Font("Helvetica", 16);
+      chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
+      chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(100, Color.LightBlue);
+    }
+
     private static double GetAverageDistance(int customer, double[,] vertices) {
       double dist = 0;
@@ -211,20 +200,14 @@
       chart.Size = new Size(ChartWidth, ChartHeight);
 
-      chart.Titles.Add("Distance Distribution");
       chart.ChartAreas.Add("");
-
-      chart.ChartAreas[0].BackColor = Color.White;
-
-      chart.ChartAreas[0].AxisX.Title = "Distance";
+      ConfigureChartAppearance(chart);
+      chart.ChartAreas[0].AxisX.Title = "Distances";
       chart.ChartAreas[0].AxisX.Minimum = 0;
       chart.ChartAreas[0].AxisX.Maximum = 1;
-      chart.ChartAreas[0].AxisX.Interval = 1.0 / (double)DistanceSegments;
-      chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
-
+      chart.ChartAreas[0].AxisX.Interval = 1.0/DistanceSegments;
+      chart.ChartAreas[0].AxisX.LabelStyle.Interval = 1.0/DistanceSegments*2;
       chart.ChartAreas[0].AxisY.Title = "Customers";
       chart.ChartAreas[0].AxisY.Minimum = 0;
       chart.ChartAreas[0].AxisY.Maximum = problemInstance.Vertices.GetLength(0);
-      chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
-      chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(100, Color.Blue);
 
       chart.Series.Add("");
