[8924] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 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;
|
---|
[4374] | 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("CVRPTWProblemInstance View")]
|
---|
| 35 | [Content(typeof(CVRPTWProblemInstance), true)]
|
---|
| 36 | public partial class CVRPTWView : VRPProblemInstanceView {
|
---|
| 37 | public new CVRPTWProblemInstance Content {
|
---|
| 38 | get { return (CVRPTWProblemInstance)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public CVRPTWView() {
|
---|
| 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 |
|
---|
| 54 | if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
|
---|
| 55 | double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
|
---|
| 56 | for (int i = 0; i < coordinates.Rows; i++) {
|
---|
| 57 | if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
|
---|
| 58 | if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
|
---|
| 59 | if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
|
---|
| 60 | if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | int border = 20;
|
---|
| 64 | double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
|
---|
| 65 | double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
|
---|
| 66 |
|
---|
| 67 | using (Graphics graphics = Graphics.FromImage(bitmap)) {
|
---|
| 68 | if (Solution != null) {
|
---|
| 69 | int currentTour = 0;
|
---|
[7858] | 70 |
|
---|
| 71 | List<Tour> tours = Solution.GetTours();
|
---|
| 72 | List<Pen> pens = GetColors(tours.Count);
|
---|
| 73 |
|
---|
| 74 | foreach (Tour tour in tours) {
|
---|
[4374] | 75 | double t = 0.0;
|
---|
| 76 | Point[] tourPoints = new Point[tour.Stops.Count + 2];
|
---|
| 77 | Brush[] customerBrushes = new Brush[tour.Stops.Count];
|
---|
| 78 | int lastCustomer = 0;
|
---|
| 79 |
|
---|
| 80 | for (int i = -1; i <= tour.Stops.Count; i++) {
|
---|
| 81 | int location = 0;
|
---|
| 82 |
|
---|
| 83 | if (i == -1 || i == tour.Stops.Count)
|
---|
| 84 | location = 0; //depot
|
---|
| 85 | else
|
---|
| 86 | location = tour.Stops[i];
|
---|
| 87 |
|
---|
| 88 | Point locationPoint = new Point(border + ((int)((coordinates[location, 0] - xMin) * xStep)),
|
---|
| 89 | bitmap.Height - (border + ((int)((coordinates[location, 1] - yMin) * yStep))));
|
---|
| 90 | tourPoints[i + 1] = locationPoint;
|
---|
| 91 |
|
---|
| 92 | if (i != -1 && i != tour.Stops.Count) {
|
---|
| 93 | Brush customerBrush = Brushes.Black;
|
---|
| 94 |
|
---|
| 95 | t += Content.GetDistance(
|
---|
[6851] | 96 | lastCustomer, location, Solution);
|
---|
[4374] | 97 |
|
---|
| 98 | if (t < readyTime[location]) {
|
---|
| 99 | t = readyTime[location];
|
---|
| 100 | customerBrush = Brushes.Orange;
|
---|
| 101 | } else if (t > dueTime[location]) {
|
---|
| 102 | customerBrush = Brushes.Red;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | t += serviceTime[location];
|
---|
| 106 | customerBrushes[i] = customerBrush;
|
---|
| 107 | }
|
---|
| 108 | lastCustomer = location;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[7858] | 111 | graphics.DrawPolygon(pens[currentTour], tourPoints);
|
---|
[4374] | 112 |
|
---|
| 113 | for (int i = 0; i < tour.Stops.Count; i++) {
|
---|
| 114 | graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
|
---|
| 118 |
|
---|
| 119 | currentTour++;
|
---|
| 120 | }
|
---|
[7858] | 121 |
|
---|
| 122 | for (int i = 0; i < pens.Count; i++)
|
---|
| 123 | pens[i].Dispose();
|
---|
[4374] | 124 | } else {
|
---|
| 125 | Point locationPoint;
|
---|
| 126 | //just draw customers
|
---|
| 127 | for (int i = 1; i < coordinates.Rows; i++) {
|
---|
| 128 | locationPoint = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
| 129 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
| 130 |
|
---|
| 131 | graphics.FillRectangle(Brushes.Black, locationPoint.X - 3, locationPoint.Y - 3, 6, 6);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),
|
---|
| 135 | bitmap.Height - (border + ((int)((coordinates[0, 1] - yMin) * yStep))));
|
---|
| 136 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | }
|
---|