Documentation/Howto/ImplementANewVRPEncoding: MultiTripVisualizationPatch.patch

File MultiTripVisualizationPatch.patch, 7.6 KB (added by pfleck, 6 years ago)
  • HeuristicLab.Problems.VehicleRouting.Views/3.4/HeuristicLab.Problems.VehicleRouting.Views-3.4.csproj

     
    9696    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    9797  </PropertyGroup>
    9898  <ItemGroup>
     99    <Reference Include="HeuristicLab.MultiTripVRP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     100      <SpecificVersion>False</SpecificVersion>
     101      <HintPath>..\..\bin\HeuristicLab.MultiTripVRP.dll</HintPath>
     102      <Private>False</Private>
     103    </Reference>
    99104    <Reference Include="System" />
    100105    <Reference Include="System.Core">
    101106      <RequiredTargetFramework>3.5</RequiredTargetFramework>
  • 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;
     25using System.Linq;
    2826using System.Windows.Forms;
     27using HeuristicLab.Data;
    2928using HeuristicLab.MainForm;
     29using HeuristicLab.MultiTripVRP;
    3030using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    31 using HeuristicLab.Data;
    3231
    3332namespace HeuristicLab.Problems.VehicleRouting.Views {
    3433  [View("SingleDepotVRPProblemInstance View")]
     
    4847      DoubleMatrix distanceMatrix = Content.DistanceMatrix;
    4948      BoolValue useDistanceMatrix = Content.UseDistanceMatrix;
    5049
     50      MultiTripEncoding mt = Solution as MultiTripEncoding;
     51
    5152      if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
    5253        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    5354        for (int i = 0; i < coordinates.Rows; i++) {
     
    6162        double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
    6263        double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
    6364
     65        double maxDemand = Content.Demand.Max();
     66
    6467        using (Graphics graphics = Graphics.FromImage(bitmap)) {
    6568          if (Solution != null) {
    66              List<Tour> tours = Solution.GetTours();
    67              List<Pen> pens = GetColors(tours.Count);
     69            List<Tour> tours = Solution.GetTours();
     70            List<Pen> pens = GetColors(tours.Count);
    6871
    6972            int currentTour = 0;
    7073            foreach (Tour tour in tours) {
    71               Point[] tourPoints = new Point[tour.Stops.Count + 2];
     74              var tourPoints = new List<Point>(tour.Stops.Count + 2);
     75
    7276              Brush[] customerBrushes = new Brush[tour.Stops.Count];
    7377              int lastCustomer = 0;
    7478
     79              bool[] delimiters = new bool[0];
     80              if (mt != null)
     81                delimiters = mt.GetDelimiters(Solution.GetTourIndex(tour));
     82
    7583              for (int i = -1; i <= tour.Stops.Count; i++) {
    7684                int location = 0;
    7785
     
    8088                else
    8189                  location = tour.Stops[i];
    8290
    83                 Point locationPoint = new Point(border + ((int)((coordinates[location, 0] - xMin) * xStep)),
    84                                 bitmap.Height - (border + ((int)((coordinates[location, 1] - yMin) * yStep))));
    85                 tourPoints[i + 1] = locationPoint;
     91                Point locationPoint = new Point(border + (int)((coordinates[location, 0] - xMin) * xStep),
     92                                bitmap.Height - (border + (int)((coordinates[location, 1] - yMin) * yStep)));
    8693
     94                if (mt != null && i > 0 && delimiters.Length >= i && delimiters[i - 1]) {
     95                  tourPoints.Add(new Point(border + (int)((coordinates[0, 0] - xMin) * xStep),
     96                                           bitmap.Height - (border + (int)((coordinates[0, 1] - yMin) * yStep))));
     97                }
     98                tourPoints.Add(locationPoint);
     99
    87100                if (i != -1 && i != tour.Stops.Count) {
    88101                  Brush customerBrush = Brushes.Black;
    89102                  customerBrushes[i] = customerBrush;
     
    91104                lastCustomer = location;
    92105              }
    93106
    94               graphics.DrawPolygon(pens[currentTour], tourPoints);
     107              graphics.DrawPolygon(pens[currentTour], tourPoints.ToArray());
    95108
    96109              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);
     110                float size = (float)(10.0 * (Content.GetDemand(tour.Stops[i]) / maxDemand));
     111                size = Math.Max(size, 2);
     112
     113                graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - size / 2, tourPoints[i + 1].Y - size / 2, size, size);
    98114              }
    99115
    100116              graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
     
    103119            }
    104120
    105121            for (int i = 0; i < pens.Count; i++)
    106                pens[i].Dispose();
     122              pens[i].Dispose();
    107123          } else {
    108124            Point locationPoint;
    109125            //just draw customers
     
    111127              locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
    112128                              bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
    113129
    114               graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6);
     130              float size = (float)(10.0 * (Content.GetDemand(i) / maxDemand));
     131              size = Math.Max(size, 2);
     132
     133              graphics.FillRectangle(Brushes.Black, locationPoint.X - size / 2, locationPoint.Y - size / 2, size, size);
    115134            }
    116135
    117136            locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),
  • HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs

     
    2020#endregion
    2121
    2222using System;
     23using System.Linq;
    2324using System.Text;
    2425using System.Windows.Forms;
    2526using HeuristicLab.MainForm;
     27using HeuristicLab.MultiTripVRP;
    2628
    2729namespace HeuristicLab.Problems.VehicleRouting.Views {
    2830  [View("VRPSolution View")]
     
    8991      StringBuilder sb = new StringBuilder();
    9092
    9193      if (Content != null && Content.Solution != null) {
     94        MultiTripEncoding mt = Content.Solution as MultiTripEncoding;
     95
    9296        foreach (Tour tour in Content.Solution.GetTours()) {
    93           foreach (int city in tour.Stops) {
    94             sb.Append(city);
     97          bool[] delimiters = new bool[0];
     98          if (mt != null)
     99            delimiters = mt.GetDelimiters(Content.Solution.GetTourIndex(tour));
     100
     101          for (int stop = 0; stop < tour.Stops.Count; stop++) {
     102            sb.Append(tour.Stops[stop]);
    95103            sb.Append(" ");
     104
     105            if (delimiters.Length > stop && delimiters[stop])
     106              sb.Append("     |      ");
    96107          }
    97108          sb.AppendLine();
    98109        }