Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.VehicleRouting.Views/3.4/MultiDepotVRPView.cs @ 18190

Last change on this file since 18190 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 6.0 KB
RevLine 
[8924]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8924]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[6851]22using System.Collections.Generic;
23using System.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Problems.VehicleRouting.Views {
30  [View("MultiDepotVRPProblemInstance View")]
31  [Content(typeof(MultiDepotVRPProblemInstance), true)]
32  public partial class MultiDepotVRPView : VRPProblemInstanceView {
33    public new MultiDepotVRPProblemInstance Content {
34      get { return (MultiDepotVRPProblemInstance)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public MultiDepotVRPView() {
39      InitializeComponent();
40    }
41
42    protected override void DrawVisualization(Bitmap bitmap) {
43      DoubleMatrix coordinates = Content.Coordinates;
44      DoubleMatrix distanceMatrix = Content.DistanceMatrix;
45      BoolValue useDistanceMatrix = Content.UseDistanceMatrix;
46
47      if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
48        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
49        for (int i = 0; i < coordinates.Rows; i++) {
50          if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
51          if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
52          if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
53          if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
54        }
55
56        int border = 20;
57        double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
58        double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
59
60        using (Graphics graphics = Graphics.FromImage(bitmap)) {
61          if (Solution != null) {
62            for (int i = 0; i < Content.Depots.Value; i++) {
63              Point locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
64                                bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
65              graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
66            }
67
68            int currentTour = 0;
[7858]69
70            List<Tour> tours = Solution.GetTours();
71            List<Pen> pens = GetColors(tours.Count);
72
73            foreach (Tour tour in tours) {
[6851]74              Point[] tourPoints = new Point[tour.Stops.Count + 2];
75              Brush[] customerBrushes = new Brush[tour.Stops.Count];
76              int lastCustomer = 0;
77
78              for (int i = -1; i <= tour.Stops.Count; i++) {
79                int location = 0;
80
81                if (i == -1 || i == tour.Stops.Count)
82                  location = 0; //depot
83                else
84                  location = tour.Stops[i];
85
86                Point locationPoint;
87
88                if (location == 0) {
89                  int tourIndex = Solution.GetTourIndex(tour);
90                  int vehicle = Solution.GetVehicleAssignment(tourIndex);
91                  int depot = Content.VehicleDepotAssignment[vehicle];
92
93                  locationPoint = new Point(border + ((int)((Content.Coordinates[depot, 0] - xMin) * xStep)),
94                                  bitmap.Height - (border + ((int)((Content.Coordinates[depot, 1] - yMin) * yStep))));
95                } else {
96                  locationPoint = new Point(border + ((int)((Content.GetCoordinates(location)[0] - xMin) * xStep)),
97                                  bitmap.Height - (border + ((int)((Content.GetCoordinates(location)[1] - yMin) * yStep))));
98                }
99                tourPoints[i + 1] = locationPoint;
100
101                if (i != -1 && i != tour.Stops.Count) {
102                  Brush customerBrush = Brushes.Black;
103                  customerBrushes[i] = customerBrush;
104                }
105                lastCustomer = location;
106              }
107
[7858]108              graphics.DrawPolygon(pens[currentTour], tourPoints);
[6851]109
110              for (int i = 0; i < tour.Stops.Count; i++) {
111                graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
112              }
113
114              graphics.FillEllipse(Brushes.DarkBlue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
115
116              currentTour++;
117            }
[7858]118
119            for (int i = 0; i < pens.Count; i++)
120              pens[i].Dispose();
[6851]121          } else {
122            Point locationPoint;
123            //just draw customers
124            for (int i = 1; i <= Content.Cities.Value; i++) {
125              locationPoint = new Point(border + ((int)((Content.GetCoordinates(i)[0] - xMin) * xStep)),
126                              bitmap.Height - (border + ((int)((Content.GetCoordinates(i)[1] - yMin) * yStep))));
127
128              graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6);
129            }
130
131            for (int i = 0; i < Content.Depots.Value; i++) {
132              locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
133                                bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
134              graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
135            }
136          }
137        }
138      }
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.