[8924] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 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;
|
---|
[6856] | 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("MDCVRPPDTWProblemInstance View")]
|
---|
| 35 | [Content(typeof(MDCVRPPDTWProblemInstance), true)]
|
---|
| 36 | public partial class MDCVRPPDTWView : VRPProblemInstanceView {
|
---|
| 37 | public new MDCVRPPDTWProblemInstance Content {
|
---|
| 38 | get { return (MDCVRPPDTWProblemInstance)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public MDCVRPPDTWView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private bool drawFlow = false;
|
---|
| 47 |
|
---|
| 48 | protected override void pictureBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
|
---|
| 49 | if (e.Button == System.Windows.Forms.MouseButtons.Right) {
|
---|
| 50 | drawFlow = !drawFlow;
|
---|
| 51 | GenerateImage();
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | protected override void DrawVisualization(Bitmap bitmap) {
|
---|
| 56 | DoubleMatrix coordinates = Content.Coordinates;
|
---|
| 57 | DoubleMatrix distanceMatrix = Content.DistanceMatrix;
|
---|
| 58 | BoolValue useDistanceMatrix = Content.UseDistanceMatrix;
|
---|
| 59 | DoubleArray dueTime = Content.DueTime;
|
---|
| 60 | DoubleArray serviceTime = Content.ServiceTime;
|
---|
| 61 | DoubleArray readyTime = Content.ReadyTime;
|
---|
| 62 | DoubleArray demand = Content.Demand;
|
---|
| 63 | IntArray pickupDeliveryLocation = Content.PickupDeliveryLocation;
|
---|
| 64 | IntArray vehicleAssignment = Content.VehicleDepotAssignment;
|
---|
| 65 |
|
---|
| 66 | int depots = Content.Depots.Value;
|
---|
| 67 | int cities = Content.Cities.Value;
|
---|
| 68 |
|
---|
| 69 | Pen flowPen = new Pen(Brushes.Red, 3);
|
---|
| 70 | flowPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
|
---|
| 71 | flowPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
|
---|
| 72 |
|
---|
| 73 | if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
|
---|
| 74 | double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
|
---|
| 75 | for (int i = 0; i < coordinates.Rows; i++) {
|
---|
| 76 | if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
|
---|
| 77 | if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
|
---|
| 78 | if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
|
---|
| 79 | if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | int border = 20;
|
---|
| 83 | double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
|
---|
| 84 | double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
|
---|
| 85 |
|
---|
| 86 | using (Graphics graphics = Graphics.FromImage(bitmap)) {
|
---|
| 87 | if (Solution != null) {
|
---|
| 88 | for (int i = 0; i < Content.Depots.Value; i++) {
|
---|
| 89 | Point locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 90 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 91 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | int currentTour = 0;
|
---|
[7858] | 95 |
|
---|
| 96 | List<Tour> tours = Solution.GetTours();
|
---|
| 97 | List<Pen> pens = GetColors(tours.Count);
|
---|
| 98 |
|
---|
| 99 | foreach (Tour tour in tours) {
|
---|
[6856] | 100 | int tourIndex = Solution.GetTourIndex(tour);
|
---|
| 101 | int vehicle = Solution.GetVehicleAssignment(tourIndex);
|
---|
| 102 | int depot = vehicleAssignment[vehicle];
|
---|
| 103 |
|
---|
| 104 | double t = 0.0;
|
---|
| 105 | Point[] tourPoints = new Point[tour.Stops.Count + 2];
|
---|
| 106 | Brush[] customerBrushes = new Brush[tour.Stops.Count];
|
---|
| 107 | Pen[] customerPens = new Pen[tour.Stops.Count];
|
---|
| 108 | bool[] validPickupDelivery = new bool[tour.Stops.Count];
|
---|
| 109 | int lastCustomer = 0;
|
---|
| 110 |
|
---|
| 111 | Dictionary<int, bool> stops = new Dictionary<int, bool>();
|
---|
| 112 | for (int i = -1; i <= tour.Stops.Count; i++) {
|
---|
| 113 | int location = 0;
|
---|
| 114 |
|
---|
| 115 | if (i == -1 || i == tour.Stops.Count)
|
---|
| 116 | location = 0; //depot
|
---|
| 117 | else
|
---|
| 118 | location = tour.Stops[i];
|
---|
| 119 |
|
---|
| 120 | Point locationPoint;
|
---|
| 121 | if (location == 0) {
|
---|
| 122 | locationPoint = new Point(border + ((int)((Content.Coordinates[depot, 0] - xMin) * xStep)),
|
---|
| 123 | bitmap.Height - (border + ((int)((Content.Coordinates[depot, 1] - yMin) * yStep))));
|
---|
| 124 | } else {
|
---|
| 125 | locationPoint = new Point(border + ((int)((Content.GetCoordinates(location)[0] - xMin) * xStep)),
|
---|
| 126 | bitmap.Height - (border + ((int)((Content.GetCoordinates(location)[1] - yMin) * yStep))));
|
---|
| 127 | }
|
---|
| 128 | tourPoints[i + 1] = locationPoint;
|
---|
| 129 |
|
---|
| 130 | if (i != -1 && i != tour.Stops.Count) {
|
---|
| 131 | Brush customerBrush = Brushes.Black;
|
---|
| 132 | Pen customerPen = Pens.Black;
|
---|
| 133 |
|
---|
| 134 | t += Content.GetDistance(
|
---|
| 135 | lastCustomer, location, Solution);
|
---|
| 136 |
|
---|
| 137 | int locationIndex;
|
---|
| 138 | if (location == 0)
|
---|
| 139 | locationIndex = depot;
|
---|
| 140 | else
|
---|
| 141 | locationIndex = location + depots - 1;
|
---|
| 142 |
|
---|
| 143 | if (t < readyTime[locationIndex]) {
|
---|
| 144 | t = readyTime[locationIndex];
|
---|
| 145 | customerBrush = Brushes.Orange;
|
---|
| 146 | customerPen = Pens.Orange;
|
---|
| 147 |
|
---|
| 148 | } else if (t > dueTime[locationIndex]) {
|
---|
| 149 | customerBrush = Brushes.Red;
|
---|
| 150 | customerPen = Pens.Red;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | t += serviceTime[location - 1];
|
---|
| 154 |
|
---|
| 155 | validPickupDelivery[i] =
|
---|
| 156 | ((demand[location - 1] >= 0) ||
|
---|
| 157 | (stops.ContainsKey(pickupDeliveryLocation[location - 1])));
|
---|
| 158 |
|
---|
| 159 | customerBrushes[i] = customerBrush;
|
---|
| 160 | customerPens[i] = customerPen;
|
---|
| 161 |
|
---|
| 162 | stops.Add(location, true);
|
---|
| 163 | }
|
---|
| 164 | lastCustomer = location;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | if (!drawFlow)
|
---|
[7858] | 168 | graphics.DrawPolygon(pens[currentTour], tourPoints);
|
---|
[6856] | 169 |
|
---|
| 170 | for (int i = 0; i < tour.Stops.Count; i++) {
|
---|
| 171 | if (validPickupDelivery[i]) {
|
---|
| 172 | graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
| 173 |
|
---|
| 174 | if (demand[tour.Stops[i] - 1] < 0 && drawFlow) {
|
---|
| 175 | int location = pickupDeliveryLocation[tour.Stops[i] - 1];
|
---|
| 176 | int source = tour.Stops.IndexOf(location);
|
---|
| 177 |
|
---|
| 178 | graphics.DrawLine(flowPen, tourPoints[source + 1], tourPoints[i + 1]);
|
---|
| 179 | }
|
---|
| 180 | } else
|
---|
| 181 | graphics.DrawRectangle(customerPens[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | graphics.FillEllipse(Brushes.DarkBlue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
|
---|
| 185 |
|
---|
| 186 | currentTour++;
|
---|
| 187 | }
|
---|
[7858] | 188 |
|
---|
| 189 | for (int i = 0; i < pens.Count; i++)
|
---|
| 190 | pens[i].Dispose();
|
---|
[6856] | 191 | } else {
|
---|
| 192 | {
|
---|
[6947] | 193 | Point[] locationPoints = new Point[cities];
|
---|
[6856] | 194 | //just draw customers
|
---|
[6947] | 195 | for (int i = 0; i < cities; i++) {
|
---|
| 196 | locationPoints[i] = new Point(border + ((int)((Content.GetCoordinates(i + 1)[0] - xMin) * xStep)),
|
---|
| 197 | bitmap.Height - (border + ((int)((Content.GetCoordinates(i + 1)[1] - yMin) * yStep))));
|
---|
[6856] | 198 |
|
---|
| 199 | graphics.FillRectangle(Brushes.Black, locationPoints[i].X - 3, locationPoints[i].Y - 3, 6, 6);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | if (drawFlow) {
|
---|
| 203 | for (int i = 0; i < cities; i++) {
|
---|
| 204 | if (demand[i] < 0) {
|
---|
[6947] | 205 | graphics.DrawLine(flowPen, locationPoints[pickupDeliveryLocation[i] - 1], locationPoints[i]);
|
---|
[6856] | 206 | }
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | for (int i = 0; i < Content.Depots.Value; i++) {
|
---|
| 211 | Point locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 212 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 213 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | flowPen.Dispose();
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | }
|
---|