[6710] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Data;
|
---|
| 5 | using System.Drawing;
|
---|
| 6 | using System.Text;
|
---|
| 7 | using System.Windows.Forms;
|
---|
| 8 | using HeuristicLab.MainForm;
|
---|
| 9 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
| 10 | using HeuristicLab.Data;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.Problems.VehicleRouting.Views {
|
---|
| 13 | [View("CVRPPDTWProblemInstance View")]
|
---|
| 14 | [Content(typeof(CVRPPDTWProblemInstance), true)]
|
---|
| 15 | public partial class CVRPPDTWView : VRPProblemInstanceView {
|
---|
| 16 | public new CVRPPDTWProblemInstance Content {
|
---|
| 17 | get { return (CVRPPDTWProblemInstance)base.Content; }
|
---|
| 18 | set { base.Content = value; }
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public CVRPPDTWView() {
|
---|
| 22 | InitializeComponent();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[6715] | 25 | private bool drawFlow = false;
|
---|
| 26 |
|
---|
| 27 | protected override void pictureBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
|
---|
| 28 | if (e.Button == System.Windows.Forms.MouseButtons.Right) {
|
---|
| 29 | drawFlow = !drawFlow;
|
---|
| 30 | GenerateImage();
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[6710] | 34 | protected override void DrawVisualization(Bitmap bitmap) {
|
---|
| 35 | DoubleMatrix coordinates = Content.Coordinates;
|
---|
| 36 | DoubleMatrix distanceMatrix = Content.DistanceMatrix;
|
---|
| 37 | BoolValue useDistanceMatrix = Content.UseDistanceMatrix;
|
---|
| 38 | DoubleArray dueTime = Content.DueTime;
|
---|
| 39 | DoubleArray serviceTime = Content.ServiceTime;
|
---|
| 40 | DoubleArray readyTime = Content.ReadyTime;
|
---|
| 41 | DoubleArray demand = Content.Demand;
|
---|
| 42 | IntArray pickupDeliveryLocation = Content.PickupDeliveryLocation;
|
---|
| 43 |
|
---|
[6715] | 44 | Pen flowPen = new Pen(Brushes.Red, 3);
|
---|
| 45 | flowPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
|
---|
| 46 | flowPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
|
---|
| 47 |
|
---|
[6710] | 48 | if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
|
---|
| 49 | double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
|
---|
| 50 | for (int i = 0; i < coordinates.Rows; i++) {
|
---|
| 51 | if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
|
---|
| 52 | if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
|
---|
| 53 | if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
|
---|
| 54 | if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | int border = 20;
|
---|
| 58 | double xStep = xMax != xMin ? (bitmap.Width - 2 * border) / (xMax - xMin) : 1;
|
---|
| 59 | double yStep = yMax != yMin ? (bitmap.Height - 2 * border) / (yMax - yMin) : 1;
|
---|
| 60 |
|
---|
| 61 | using (Graphics graphics = Graphics.FromImage(bitmap)) {
|
---|
| 62 | if (Solution != null) {
|
---|
| 63 | int currentTour = 0;
|
---|
[7858] | 64 |
|
---|
| 65 | List<Tour> tours = Solution.GetTours();
|
---|
| 66 | List<Pen> pens = GetColors(tours.Count);
|
---|
| 67 |
|
---|
| 68 | foreach (Tour tour in tours) {
|
---|
[6710] | 69 | double t = 0.0;
|
---|
| 70 | Point[] tourPoints = new Point[tour.Stops.Count + 2];
|
---|
| 71 | Brush[] customerBrushes = new Brush[tour.Stops.Count];
|
---|
| 72 | Pen[] customerPens = new Pen[tour.Stops.Count];
|
---|
| 73 | bool[] validPickupDelivery = new bool[tour.Stops.Count];
|
---|
| 74 | int lastCustomer = 0;
|
---|
| 75 |
|
---|
| 76 | Dictionary<int, bool> stops = new Dictionary<int, bool>();
|
---|
| 77 | for (int i = -1; i <= tour.Stops.Count; i++) {
|
---|
| 78 | int location = 0;
|
---|
| 79 |
|
---|
| 80 | if (i == -1 || i == tour.Stops.Count)
|
---|
| 81 | location = 0; //depot
|
---|
| 82 | else
|
---|
| 83 | location = tour.Stops[i];
|
---|
| 84 |
|
---|
| 85 | Point locationPoint = new Point(border + ((int)((coordinates[location, 0] - xMin) * xStep)),
|
---|
| 86 | bitmap.Height - (border + ((int)((coordinates[location, 1] - yMin) * yStep))));
|
---|
| 87 | tourPoints[i + 1] = locationPoint;
|
---|
| 88 |
|
---|
| 89 | if (i != -1 && i != tour.Stops.Count) {
|
---|
| 90 | Brush customerBrush = Brushes.Black;
|
---|
| 91 | Pen customerPen = Pens.Black;
|
---|
| 92 |
|
---|
| 93 | t += Content.GetDistance(
|
---|
[6851] | 94 | lastCustomer, location, Solution);
|
---|
[6710] | 95 |
|
---|
| 96 | if (t < readyTime[location]) {
|
---|
| 97 | t = readyTime[location];
|
---|
| 98 | customerBrush = Brushes.Orange;
|
---|
| 99 | customerPen = Pens.Orange;
|
---|
[6715] | 100 |
|
---|
[6710] | 101 | } else if (t > dueTime[location]) {
|
---|
| 102 | customerBrush = Brushes.Red;
|
---|
| 103 | customerPen = Pens.Red;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | t += serviceTime[location];
|
---|
| 107 |
|
---|
| 108 | validPickupDelivery[i] =
|
---|
| 109 | ((demand[location] >= 0) ||
|
---|
| 110 | (stops.ContainsKey(pickupDeliveryLocation[location])));
|
---|
| 111 |
|
---|
| 112 | customerBrushes[i] = customerBrush;
|
---|
| 113 | customerPens[i] = customerPen;
|
---|
| 114 |
|
---|
| 115 | stops.Add(location, true);
|
---|
| 116 | }
|
---|
| 117 | lastCustomer = location;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[6715] | 120 | if (!drawFlow)
|
---|
[7858] | 121 | graphics.DrawPolygon(pens[currentTour], tourPoints);
|
---|
[6710] | 122 |
|
---|
| 123 | for (int i = 0; i < tour.Stops.Count; i++) {
|
---|
[6715] | 124 | if (validPickupDelivery[i]) {
|
---|
[6710] | 125 | graphics.FillRectangle(customerBrushes[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
[6715] | 126 |
|
---|
| 127 | if (demand[tour.Stops[i]] < 0 && drawFlow) {
|
---|
| 128 | int location = pickupDeliveryLocation[tour.Stops[i]];
|
---|
| 129 | int source = tour.Stops.IndexOf(location);
|
---|
| 130 |
|
---|
| 131 | graphics.DrawLine(flowPen, tourPoints[source + 1], tourPoints[i + 1]);
|
---|
| 132 | }
|
---|
| 133 | } else
|
---|
[6710] | 134 | graphics.DrawRectangle(customerPens[i], tourPoints[i + 1].X - 3, tourPoints[i + 1].Y - 3, 6, 6);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | graphics.FillEllipse(Brushes.Blue, tourPoints[0].X - 5, tourPoints[0].Y - 5, 10, 10);
|
---|
| 138 |
|
---|
| 139 | currentTour++;
|
---|
| 140 | }
|
---|
[7858] | 141 |
|
---|
| 142 | for (int i = 0; i < pens.Count; i++)
|
---|
| 143 | pens[i].Dispose();
|
---|
[6710] | 144 | } else {
|
---|
[6715] | 145 | {
|
---|
[6789] | 146 | Point[] locationPoints = new Point[coordinates.Rows];
|
---|
[6715] | 147 | //just draw customers
|
---|
| 148 | for (int i = 1; i < coordinates.Rows; i++) {
|
---|
[6789] | 149 | locationPoints[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
|
---|
[6715] | 150 | bitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
|
---|
[6710] | 151 |
|
---|
[6789] | 152 | graphics.FillRectangle(Brushes.Black, locationPoints[i].X - 3, locationPoints[i].Y - 3, 6, 6);
|
---|
[6715] | 153 | }
|
---|
| 154 |
|
---|
[6789] | 155 | if (drawFlow) {
|
---|
| 156 | for (int i = 1; i < coordinates.Rows; i++) {
|
---|
| 157 | if (demand[i] < 0) {
|
---|
| 158 |
|
---|
| 159 | graphics.DrawLine(flowPen, locationPoints[pickupDeliveryLocation[i]], locationPoints[i]);
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | Point locationPoint = new Point(border + ((int)((coordinates[0, 0] - xMin) * xStep)),
|
---|
[6715] | 165 | bitmap.Height - (border + ((int)((coordinates[0, 1] - yMin) * yStep))));
|
---|
| 166 | graphics.FillEllipse(Brushes.Blue, locationPoint.X - 5, locationPoint.Y - 5, 10, 10);
|
---|
[6710] | 167 | }
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[6715] | 172 | flowPen.Dispose();
|
---|
[6710] | 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|