Documentation/Howto/ImplementANewVRPEncoding: MultiTripVisualizationPatch.patch
File MultiTripVisualizationPatch.patch, 7.6 KB (added by pfleck, 9 years ago) |
---|
-
HeuristicLab.Problems.VehicleRouting.Views/3.4/HeuristicLab.Problems.VehicleRouting.Views-3.4.csproj
96 96 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 97 97 </PropertyGroup> 98 98 <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> 99 104 <Reference Include="System" /> 100 105 <Reference Include="System.Core"> 101 106 <RequiredTargetFramework>3.5</RequiredTargetFramework> -
HeuristicLab.Problems.VehicleRouting.Views/3.4/SingleDepotVRPView.cs
21 21 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel;25 using System.Data;26 24 using System.Drawing; 27 using System. Text;25 using System.Linq; 28 26 using System.Windows.Forms; 27 using HeuristicLab.Data; 29 28 using HeuristicLab.MainForm; 29 using HeuristicLab.MultiTripVRP; 30 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 31 using HeuristicLab.Data;32 31 33 32 namespace HeuristicLab.Problems.VehicleRouting.Views { 34 33 [View("SingleDepotVRPProblemInstance View")] … … 48 47 DoubleMatrix distanceMatrix = Content.DistanceMatrix; 49 48 BoolValue useDistanceMatrix = Content.UseDistanceMatrix; 50 49 50 MultiTripEncoding mt = Solution as MultiTripEncoding; 51 51 52 if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) { 52 53 double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue; 53 54 for (int i = 0; i < coordinates.Rows; i++) { … … 61 62 double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1; 62 63 double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1; 63 64 65 double maxDemand = Content.Demand.Max(); 66 64 67 using (Graphics graphics = Graphics.FromImage(bitmap)) { 65 68 if (Solution != null) { 66 67 69 List<Tour> tours = Solution.GetTours(); 70 List<Pen> pens = GetColors(tours.Count); 68 71 69 72 int currentTour = 0; 70 73 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 72 76 Brush[] customerBrushes = new Brush[tour.Stops.Count]; 73 77 int lastCustomer = 0; 74 78 79 bool[] delimiters = new bool[0]; 80 if (mt != null) 81 delimiters = mt.GetDelimiters(Solution.GetTourIndex(tour)); 82 75 83 for (int i = -1; i <= tour.Stops.Count; i++) { 76 84 int location = 0; 77 85 … … 80 88 else 81 89 location = tour.Stops[i]; 82 90 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))); 86 93 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 87 100 if (i != -1 && i != tour.Stops.Count) { 88 101 Brush customerBrush = Brushes.Black; 89 102 customerBrushes[i] = customerBrush; … … 91 104 lastCustomer = location; 92 105 } 93 106 94 graphics.DrawPolygon(pens[currentTour], tourPoints );107 graphics.DrawPolygon(pens[currentTour], tourPoints.ToArray()); 95 108 96 109 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); 98 114 } 99 115 100 116 graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10); … … 103 119 } 104 120 105 121 for (int i = 0; i < pens.Count; i++) 106 122 pens[i].Dispose(); 107 123 } else { 108 124 Point locationPoint; 109 125 //just draw customers … … 111 127 locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)), 112 128 bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep)))); 113 129 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); 115 134 } 116 135 117 136 locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)), -
HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs
20 20 #endregion 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Text; 24 25 using System.Windows.Forms; 25 26 using HeuristicLab.MainForm; 27 using HeuristicLab.MultiTripVRP; 26 28 27 29 namespace HeuristicLab.Problems.VehicleRouting.Views { 28 30 [View("VRPSolution View")] … … 89 91 StringBuilder sb = new StringBuilder(); 90 92 91 93 if (Content != null && Content.Solution != null) { 94 MultiTripEncoding mt = Content.Solution as MultiTripEncoding; 95 92 96 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]); 95 103 sb.Append(" "); 104 105 if (delimiters.Length > stop && delimiters[stop]) 106 sb.Append(" | "); 96 107 } 97 108 sb.AppendLine(); 98 109 }