1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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.Collections.Generic;
|
---|
23 | using System.Globalization;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
28 | public class StopInsertionInfo {
|
---|
29 | private int start;
|
---|
30 | public int Start {
|
---|
31 | get { return start; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | private int end;
|
---|
35 | public int End {
|
---|
36 | get { return end; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | private double distance;
|
---|
40 | public double Distance {
|
---|
41 | get { return distance; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public StopInsertionInfo(int start, int end, double distance)
|
---|
45 | : base() {
|
---|
46 | this.start = start;
|
---|
47 | this.end = end;
|
---|
48 | this.distance = distance;
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected virtual void GetStopInsertionReport(StringBuilder builder) {
|
---|
52 | builder.Append("From\t");
|
---|
53 | builder.Append(Start.ToString(CultureInfo.CurrentCulture));
|
---|
54 | builder.Append("\tto\t");
|
---|
55 | builder.AppendLine(End.ToString(CultureInfo.CurrentCulture));
|
---|
56 | builder.Append("Distance:\t");
|
---|
57 | builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
|
---|
58 | }
|
---|
59 |
|
---|
60 | public virtual void GetReport(StringBuilder builder) {
|
---|
61 | GetStopInsertionReport(builder);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | public class TourInsertionInfo {
|
---|
66 | public double Penalty { get; set; }
|
---|
67 | public double Quality { get; set; }
|
---|
68 | public double Distance { get { return stopInsertionInfos.Count > 0 ? stopInsertionInfos.Sum(x => x.Distance) : 0; } }
|
---|
69 |
|
---|
70 | public int Vehicle { get; set; }
|
---|
71 |
|
---|
72 | protected List<StopInsertionInfo> stopInsertionInfos;
|
---|
73 |
|
---|
74 | public TourInsertionInfo(int vehicle)
|
---|
75 | : base() {
|
---|
76 | stopInsertionInfos = new List<StopInsertionInfo>();
|
---|
77 | Vehicle = vehicle;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public void AddStopInsertionInfo(StopInsertionInfo info) {
|
---|
81 | stopInsertionInfos.Add(info);
|
---|
82 | }
|
---|
83 |
|
---|
84 | public StopInsertionInfo GetStopInsertionInfo(int stop) {
|
---|
85 | return stopInsertionInfos[stop];
|
---|
86 | }
|
---|
87 |
|
---|
88 | public int GetStopCount() {
|
---|
89 | return stopInsertionInfos.Count;
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected virtual void GetTourInsertionReport(StringBuilder builder) {
|
---|
93 | builder.AppendLine("=== Tour ===");
|
---|
94 | builder.Append("Vehicle:\t");
|
---|
95 | builder.AppendLine(Vehicle.ToString(CultureInfo.CurrentCulture));
|
---|
96 | builder.Append("Distance:\t");
|
---|
97 | builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
|
---|
98 | builder.Append("Quality:\t");
|
---|
99 | builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
|
---|
100 | builder.Append("Penalty:\t");
|
---|
101 | builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
|
---|
102 | }
|
---|
103 |
|
---|
104 | public virtual void GetReport(StringBuilder builder) {
|
---|
105 | GetTourInsertionReport(builder);
|
---|
106 | builder.AppendLine("==== Stops ====");
|
---|
107 | for (var i = 0; i < stopInsertionInfos.Count; i++) {
|
---|
108 | stopInsertionInfos[i].GetReport(builder);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | public class InsertionInfo {
|
---|
114 | private List<TourInsertionInfo> tourInsertionInfos;
|
---|
115 |
|
---|
116 | public InsertionInfo()
|
---|
117 | : base() {
|
---|
118 | tourInsertionInfos = new List<TourInsertionInfo>();
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void AddTourInsertionInfo(TourInsertionInfo info) {
|
---|
122 | tourInsertionInfos.Add(info);
|
---|
123 | }
|
---|
124 |
|
---|
125 | public TourInsertionInfo GetTourInsertionInfo(int tour) {
|
---|
126 | return tourInsertionInfos[tour];
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected virtual void GetInsertionReport(StringBuilder builder) {
|
---|
130 | builder.AppendLine("== VRP Route Report ==");
|
---|
131 | }
|
---|
132 |
|
---|
133 | public virtual void GetReport(StringBuilder builder) {
|
---|
134 | GetInsertionReport(builder);
|
---|
135 | for (var i = 0; i < tourInsertionInfos.Count; i++) {
|
---|
136 | tourInsertionInfos[i].GetReport(builder);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | public class VRPEvaluation {
|
---|
142 | public double Quality { get; set; }
|
---|
143 | public double Distance { get; set; }
|
---|
144 | public int VehicleUtilization { get; set; }
|
---|
145 | public InsertionInfo InsertionInfo { get; set; }
|
---|
146 |
|
---|
147 | public double Penalty { get; set; }
|
---|
148 |
|
---|
149 | public VRPEvaluation() {
|
---|
150 | InsertionInfo = new InsertionInfo();
|
---|
151 | }
|
---|
152 |
|
---|
153 | protected virtual void GetEvaluationReport(StringBuilder builder) {
|
---|
154 | builder.AppendLine("= VRP Solution Report =");
|
---|
155 | builder.Append("Quality:\t");
|
---|
156 | builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
|
---|
157 | builder.Append("Penalty:\t");
|
---|
158 | builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
|
---|
159 | builder.Append("Distance:\t");
|
---|
160 | builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
|
---|
161 | builder.Append("Vehicles used:\t");
|
---|
162 | builder.AppendLine(VehicleUtilization.ToString(CultureInfo.CurrentCulture));
|
---|
163 | }
|
---|
164 |
|
---|
165 | public virtual void GetReport(StringBuilder builder) {
|
---|
166 | GetEvaluationReport(builder);
|
---|
167 | InsertionInfo.GetReport(builder);
|
---|
168 | }
|
---|
169 | }
|
---|
170 | }
|
---|