Free cookie consent management tool by TermsFeed Policy Generator

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

 AllRules.ruleset False ..\..\bin\HeuristicLab.MultiTripVRP.dll False 3.5
• HeuristicLab.Problems.VehicleRouting.Views/3.4/SingleDepotVRPView.cs

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Windows.Forms; using HeuristicLab.Data; using HeuristicLab.MainForm; using HeuristicLab.MultiTripVRP; using HeuristicLab.Problems.VehicleRouting.ProblemInstances; using HeuristicLab.Data; namespace HeuristicLab.Problems.VehicleRouting.Views { [View("SingleDepotVRPProblemInstance View")] DoubleMatrix distanceMatrix = Content.DistanceMatrix; BoolValue useDistanceMatrix = Content.UseDistanceMatrix; MultiTripEncoding mt = Solution as MultiTripEncoding; if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) { double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue; for (int i = 0; i < coordinates.Rows; i++) { double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1; double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1; double maxDemand = Content.Demand.Max(); using (Graphics graphics = Graphics.FromImage(bitmap)) { if (Solution != null) { List tours = Solution.GetTours(); List pens = GetColors(tours.Count); List tours = Solution.GetTours(); List pens = GetColors(tours.Count); int currentTour = 0; foreach (Tour tour in tours) { Point[] tourPoints = new Point[tour.Stops.Count + 2]; var tourPoints = new List(tour.Stops.Count + 2); Brush[] customerBrushes = new Brush[tour.Stops.Count]; int lastCustomer = 0; bool[] delimiters = new bool[0]; if (mt != null) delimiters = mt.GetDelimiters(Solution.GetTourIndex(tour)); for (int i = -1; i <= tour.Stops.Count; i++) { int location = 0; else location = tour.Stops[i]; Point locationPoint = new Point(border + ((int)((coordinates[location, 0] - xMin) * xStep)), bitmap.Height - (border + ((int)((coordinates[location, 1] - yMin) * yStep)))); tourPoints[i + 1] = locationPoint; Point locationPoint = new Point(border + (int)((coordinates[location, 0] - xMin) * xStep), bitmap.Height - (border + (int)((coordinates[location, 1] - yMin) * yStep))); if (mt != null && i > 0 && delimiters.Length >= i && delimiters[i - 1]) { tourPoints.Add(new Point(border + (int)((coordinates[0, 0] - xMin) * xStep), bitmap.Height - (border + (int)((coordinates[0, 1] - yMin) * yStep)))); } tourPoints.Add(locationPoint); if (i != -1 && i != tour.Stops.Count) { Brush customerBrush = Brushes.Black; customerBrushes[i] = customerBrush; lastCustomer = location; } graphics.DrawPolygon(pens[currentTour], tourPoints); graphics.DrawPolygon(pens[currentTour], tourPoints.ToArray()); for (int i = 0; i < tour.Stops.Count; i++) { graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6); float size = (float)(10.0 * (Content.GetDemand(tour.Stops[i]) / maxDemand)); size = Math.Max(size, 2); graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - size / 2, tourPoints[i + 1].Y - size / 2, size, size); } graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10); } for (int i = 0; i < pens.Count; i++) pens[i].Dispose(); pens[i].Dispose(); } else { Point locationPoint; //just draw customers locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)), bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep)))); graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6); float size = (float)(10.0 * (Content.GetDemand(i) / maxDemand)); size = Math.Max(size, 2); graphics.FillRectangle(Brushes.Black, locationPoint.X - size / 2, locationPoint.Y - size / 2, size, size); } locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),
• HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs

 #endregion using System; using System.Linq; using System.Text; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.MultiTripVRP; namespace HeuristicLab.Problems.VehicleRouting.Views { [View("VRPSolution View")] StringBuilder sb = new StringBuilder(); if (Content != null && Content.Solution != null) { MultiTripEncoding mt = Content.Solution as MultiTripEncoding; foreach (Tour tour in Content.Solution.GetTours()) { foreach (int city in tour.Stops) { sb.Append(city); bool[] delimiters = new bool[0]; if (mt != null) delimiters = mt.GetDelimiters(Content.Solution.GetTourIndex(tour)); for (int stop = 0; stop < tour.Stops.Count; stop++) { sb.Append(tour.Stops[stop]); sb.Append(" "); if (delimiters.Length > stop && delimiters[stop]) sb.Append("     |      "); } sb.AppendLine(); }