[8924] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 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 |
|
---|
| 22 | using System;
|
---|
[6854] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
| 31 | using HeuristicLab.Data;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.VehicleRouting.Views {
|
---|
| 34 | [View("MDCVRPTWProblemInstance View")]
|
---|
| 35 | [Content(typeof(MDCVRPTWProblemInstance), true)]
|
---|
| 36 | public partial class MDCVRPTWView : VRPProblemInstanceView {
|
---|
| 37 | public new MDCVRPTWProblemInstance Content {
|
---|
| 38 | get { return (MDCVRPTWProblemInstance)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public MDCVRPTWView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void DrawVisualization(Bitmap bitmap) {
|
---|
| 47 | DoubleMatrix coordinates = Content.Coordinates;
|
---|
| 48 | DoubleMatrix distanceMatrix = Content.DistanceMatrix;
|
---|
| 49 | BoolValue useDistanceMatrix = Content.UseDistanceMatrix;
|
---|
| 50 | DoubleArray dueTime = Content.DueTime;
|
---|
| 51 | DoubleArray serviceTime = Content.ServiceTime;
|
---|
| 52 | DoubleArray readyTime = Content.ReadyTime;
|
---|
| 53 | IntArray vehicleAssignment = Content.VehicleDepotAssignment;
|
---|
| 54 |
|
---|
| 55 | int depots = Content.Depots.Value;
|
---|
| 56 |
|
---|
| 57 | if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
|
---|
| 58 | double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
|
---|
| 59 | for (int i = 0; i < coordinates.Rows; i++) {
|
---|
| 60 | if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
|
---|
| 61 | if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
|
---|
| 62 | if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
|
---|
| 63 | if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | int border = 20;
|
---|
| 67 | double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
|
---|
| 68 | double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
|
---|
| 69 |
|
---|
| 70 | using (Graphics graphics = Graphics.FromImage(bitmap)) {
|
---|
| 71 | if (Solution != null) {
|
---|
| 72 | for (int i = 0; i < Content.Depots.Value; i++) {
|
---|
| 73 | Point locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 74 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 75 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | int currentTour = 0;
|
---|
[7858] | 79 |
|
---|
| 80 | List<Tour> tours = Solution.GetTours();
|
---|
| 81 | List<Pen> pens = GetColors(tours.Count);
|
---|
| 82 |
|
---|
| 83 | foreach (Tour tour in tours) {
|
---|
[6854] | 84 | int tourIndex = Solution.GetTourIndex(tour);
|
---|
| 85 | int vehicle = Solution.GetVehicleAssignment(tourIndex);
|
---|
| 86 | int depot = vehicleAssignment[vehicle];
|
---|
| 87 |
|
---|
| 88 | double t = 0.0;
|
---|
| 89 | Point[] tourPoints = new Point[tour.Stops.Count + 2];
|
---|
| 90 | Brush[] customerBrushes = new Brush[tour.Stops.Count];
|
---|
| 91 | int lastCustomer = 0;
|
---|
| 92 |
|
---|
| 93 | for (int i = -1; i <= tour.Stops.Count; i++) {
|
---|
| 94 | int location = 0;
|
---|
| 95 |
|
---|
| 96 | if (i == -1 || i == tour.Stops.Count)
|
---|
| 97 | location = 0; //depot
|
---|
| 98 | else
|
---|
| 99 | location = tour.Stops[i];
|
---|
| 100 |
|
---|
| 101 | Point locationPoint;
|
---|
| 102 | if (location == 0) {
|
---|
| 103 | locationPoint = new Point(border + ((int)((Content.Coordinates[depot, 0] - xMin) * xStep)),
|
---|
| 104 | bitmap.Height - (border + ((int)((Content.Coordinates[depot, 1] - yMin) * yStep))));
|
---|
| 105 | } else {
|
---|
| 106 | locationPoint = new Point(border + ((int)((Content.GetCoordinates(location)[0] - xMin) * xStep)),
|
---|
| 107 | bitmap.Height - (border + ((int)((Content.GetCoordinates(location)[1] - yMin) * yStep))));
|
---|
| 108 | }
|
---|
| 109 | tourPoints[i + 1] = locationPoint;
|
---|
| 110 |
|
---|
| 111 | if (i != -1 && i != tour.Stops.Count) {
|
---|
| 112 | Brush customerBrush = Brushes.Black;
|
---|
| 113 |
|
---|
| 114 | t += Content.GetDistance(
|
---|
| 115 | lastCustomer, location, Solution);
|
---|
| 116 |
|
---|
| 117 | int locationIndex;
|
---|
| 118 | if (location == 0)
|
---|
| 119 | locationIndex = depot;
|
---|
| 120 | else
|
---|
| 121 | locationIndex = location + depots - 1;
|
---|
| 122 |
|
---|
| 123 | if (t < readyTime[locationIndex]) {
|
---|
| 124 | t = readyTime[locationIndex];
|
---|
| 125 | customerBrush = Brushes.Orange;
|
---|
| 126 | } else if (t > dueTime[locationIndex]) {
|
---|
| 127 | customerBrush = Brushes.Red;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | t += serviceTime[location - 1];
|
---|
| 131 | customerBrushes[i] = customerBrush;
|
---|
| 132 | }
|
---|
| 133 | lastCustomer = location;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[7858] | 136 | graphics.DrawPolygon(pens[currentTour], tourPoints);
|
---|
[6854] | 137 |
|
---|
| 138 | for (int i = 0; i < tour.Stops.Count; i++) {
|
---|
| 139 | graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | graphics.FillEllipse(Brushes.DarkBlue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
|
---|
| 143 |
|
---|
| 144 | currentTour++;
|
---|
| 145 | }
|
---|
[7858] | 146 |
|
---|
| 147 | for (int i = 0; i < pens.Count; i++)
|
---|
| 148 | pens[i].Dispose();
|
---|
[6854] | 149 | } else {
|
---|
| 150 | Point locationPoint;
|
---|
| 151 | //just draw customers
|
---|
| 152 | for (int i = 1; i < coordinates.Rows; i++) {
|
---|
| 153 | locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 154 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 155 |
|
---|
| 156 | graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | for (int i = 0; i < Content.Depots.Value; i++) {
|
---|
| 160 | locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 161 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 162 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | }
|
---|