Documentation/Howto/ImplementANewVRPEvaluator: CapacityDependentStopSizeViewPatch.patch

File CapacityDependentStopSizeViewPatch.patch, 3.2 KB (added by pfleck, 5 years ago)
  • HeuristicLab.Problems.VehicleRouting.Views/3.4/SingleDepotVRPView.cs

     
    2121
    2222using System;
    2323using System.Collections.Generic;
    24 using System.ComponentModel;
    25 using System.Data;
    2624using System.Drawing;
    27 using System.Text;
    28 using System.Windows.Forms;
     25using System.Linq;
     26using HeuristicLab.Data;
    2927using HeuristicLab.MainForm;
    3028using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    31 using HeuristicLab.Data;
    3229
    3330namespace HeuristicLab.Problems.VehicleRouting.Views {
    3431  [View("SingleDepotVRPProblemInstance View")]
     
    6158        double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
    6259        double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
    6360
     61        double maxDemand = Content.Demand.Max();
     62
    6463        using (Graphics graphics = Graphics.FromImage(bitmap)) {
    6564          if (Solution != null) {
    66              List<Tour> tours = Solution.GetTours();
    67              List<Pen> pens = GetColors(tours.Count);
     65            List<Tour> tours = Solution.GetTours();
     66            List<Pen> pens = GetColors(tours.Count);
    6867
    6968            int currentTour = 0;
    7069            foreach (Tour tour in tours) {
     
    9190                lastCustomer = location;
    9291              }
    9392
    94               graphics.DrawPolygon(pens[currentTour], tourPoints);
     93              graphics.DrawPolygon(pens[currentTour], tourPoints.ToArray());
    9594
    9695              for (int i = 0; i < tour.Stops.Count; i++) {
    97                 graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
     96                float size = (float)(10.0 * (Content.GetDemand(tour.Stops[i]) / maxDemand));
     97                size = Math.Max(size, 2);
     98
     99                graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - size / 2, tourPoints[i + 1].Y - size / 2, size, size);
    98100              }
    99101
    100102              graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
     
    103105            }
    104106
    105107            for (int i = 0; i < pens.Count; i++)
    106                pens[i].Dispose();
     108              pens[i].Dispose();
    107109          } else {
    108110            Point locationPoint;
    109111            //just draw customers
     
    111113              locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
    112114                              bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
    113115
    114               graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6);
     116              float size = (float)(10.0 * (Content.GetDemand(i) / maxDemand));
     117              size = Math.Max(size, 2);
     118
     119              graphics.FillRectangle(Brushes.Black, locationPoint.X - size / 2, locationPoint.Y - size / 2, size, size);
    115120            }
    116121
    117122            locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),