[4454] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4454] | 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 |
|
---|
[4362] | 22 | using System.Collections.Generic;
|
---|
[14677] | 23 | using System.Globalization;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
[4362] | 26 |
|
---|
[4363] | 27 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
[8053] | 28 | public class StopInsertionInfo {
|
---|
[6752] | 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 | }
|
---|
[8053] | 38 |
|
---|
[14677] | 39 | private double distance;
|
---|
| 40 | public double Distance {
|
---|
| 41 | get { return distance; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public StopInsertionInfo(int start, int end, double distance)
|
---|
[6752] | 45 | : base() {
|
---|
[8053] | 46 | this.start = start;
|
---|
| 47 | this.end = end;
|
---|
[14677] | 48 | this.distance = distance;
|
---|
[6752] | 49 | }
|
---|
[14677] | 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 | }
|
---|
[6752] | 63 | }
|
---|
| 64 |
|
---|
| 65 | public class TourInsertionInfo {
|
---|
| 66 | public double Penalty { get; set; }
|
---|
[7276] | 67 | public double Quality { get; set; }
|
---|
[14677] | 68 | public double Distance { get { return stopInsertionInfos.Count > 0 ? stopInsertionInfos.Sum(x => x.Distance) : 0; } }
|
---|
[6752] | 69 |
|
---|
[6883] | 70 | public int Vehicle { get; set; }
|
---|
| 71 |
|
---|
[14677] | 72 | protected List<StopInsertionInfo> stopInsertionInfos;
|
---|
[6752] | 73 |
|
---|
[6883] | 74 | public TourInsertionInfo(int vehicle)
|
---|
[6752] | 75 | : base() {
|
---|
| 76 | stopInsertionInfos = new List<StopInsertionInfo>();
|
---|
[6883] | 77 | Vehicle = vehicle;
|
---|
[6752] | 78 | }
|
---|
| 79 |
|
---|
| 80 | public void AddStopInsertionInfo(StopInsertionInfo info) {
|
---|
| 81 | stopInsertionInfos.Add(info);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[8053] | 84 | public StopInsertionInfo GetStopInsertionInfo(int stop) {
|
---|
[6752] | 85 | return stopInsertionInfos[stop];
|
---|
[8053] | 86 | }
|
---|
[6752] | 87 |
|
---|
| 88 | public int GetStopCount() {
|
---|
| 89 | return stopInsertionInfos.Count;
|
---|
| 90 | }
|
---|
[14677] | 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 | }
|
---|
[6752] | 111 | }
|
---|
| 112 |
|
---|
| 113 | public class InsertionInfo {
|
---|
| 114 | private List<TourInsertionInfo> tourInsertionInfos;
|
---|
[8053] | 115 |
|
---|
[6752] | 116 | public InsertionInfo()
|
---|
| 117 | : base() {
|
---|
[8053] | 118 | tourInsertionInfos = new List<TourInsertionInfo>();
|
---|
[6752] | 119 | }
|
---|
| 120 |
|
---|
[8053] | 121 | public void AddTourInsertionInfo(TourInsertionInfo info) {
|
---|
[6752] | 122 | tourInsertionInfos.Add(info);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | public TourInsertionInfo GetTourInsertionInfo(int tour) {
|
---|
| 126 | return tourInsertionInfos[tour];
|
---|
| 127 | }
|
---|
[14677] | 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 | }
|
---|
[6752] | 139 | }
|
---|
[8053] | 140 |
|
---|
[4362] | 141 | public class VRPEvaluation {
|
---|
| 142 | public double Quality { get; set; }
|
---|
| 143 | public double Distance { get; set; }
|
---|
| 144 | public int VehicleUtilization { get; set; }
|
---|
[6752] | 145 | public InsertionInfo InsertionInfo { get; set; }
|
---|
[4362] | 146 |
|
---|
| 147 | public double Penalty { get; set; }
|
---|
[6752] | 148 |
|
---|
| 149 | public VRPEvaluation() {
|
---|
| 150 | InsertionInfo = new InsertionInfo();
|
---|
| 151 | }
|
---|
[14677] | 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 | }
|
---|
[4362] | 169 | }
|
---|
| 170 | }
|
---|