#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
public class StopInsertionInfo {
private int start;
public int Start {
get { return start; }
}
private int end;
public int End {
get { return end; }
}
private double distance;
public double Distance {
get { return distance; }
}
public StopInsertionInfo(int start, int end, double distance)
: base() {
this.start = start;
this.end = end;
this.distance = distance;
}
protected virtual void GetStopInsertionReport(StringBuilder builder) {
builder.Append("From\t");
builder.Append(Start.ToString(CultureInfo.CurrentCulture));
builder.Append("\tto\t");
builder.AppendLine(End.ToString(CultureInfo.CurrentCulture));
builder.Append("Distance:\t");
builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
}
public virtual void GetReport(StringBuilder builder) {
GetStopInsertionReport(builder);
}
}
public class TourInsertionInfo {
public double Penalty { get; set; }
public double Quality { get; set; }
public double Distance { get { return stopInsertionInfos.Count > 0 ? stopInsertionInfos.Sum(x => x.Distance) : 0; } }
public int Vehicle { get; set; }
protected List stopInsertionInfos;
public TourInsertionInfo(int vehicle)
: base() {
stopInsertionInfos = new List();
Vehicle = vehicle;
}
public void AddStopInsertionInfo(StopInsertionInfo info) {
stopInsertionInfos.Add(info);
}
public StopInsertionInfo GetStopInsertionInfo(int stop) {
return stopInsertionInfos[stop];
}
public int GetStopCount() {
return stopInsertionInfos.Count;
}
protected virtual void GetTourInsertionReport(StringBuilder builder) {
builder.AppendLine("=== Tour ===");
builder.Append("Vehicle:\t");
builder.AppendLine(Vehicle.ToString(CultureInfo.CurrentCulture));
builder.Append("Distance:\t");
builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
builder.Append("Quality:\t");
builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
builder.Append("Penalty:\t");
builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
}
public virtual void GetReport(StringBuilder builder) {
GetTourInsertionReport(builder);
builder.AppendLine("==== Stops ====");
for (var i = 0; i < stopInsertionInfos.Count; i++) {
stopInsertionInfos[i].GetReport(builder);
}
}
}
public class InsertionInfo {
private List tourInsertionInfos;
public InsertionInfo()
: base() {
tourInsertionInfos = new List();
}
public void AddTourInsertionInfo(TourInsertionInfo info) {
tourInsertionInfos.Add(info);
}
public TourInsertionInfo GetTourInsertionInfo(int tour) {
return tourInsertionInfos[tour];
}
protected virtual void GetInsertionReport(StringBuilder builder) {
builder.AppendLine("== VRP Route Report ==");
}
public virtual void GetReport(StringBuilder builder) {
GetInsertionReport(builder);
for (var i = 0; i < tourInsertionInfos.Count; i++) {
tourInsertionInfos[i].GetReport(builder);
}
}
}
public class VRPEvaluation {
public double Quality { get; set; }
public double Distance { get; set; }
public int VehicleUtilization { get; set; }
public InsertionInfo InsertionInfo { get; set; }
public double Penalty { get; set; }
public VRPEvaluation() {
InsertionInfo = new InsertionInfo();
}
protected virtual void GetEvaluationReport(StringBuilder builder) {
builder.AppendLine("= VRP Solution Report =");
builder.Append("Quality:\t");
builder.AppendLine(Quality.ToString(CultureInfo.CurrentCulture));
builder.Append("Penalty:\t");
builder.AppendLine(Penalty.ToString(CultureInfo.CurrentCulture));
builder.Append("Distance:\t");
builder.AppendLine(Distance.ToString(CultureInfo.CurrentCulture));
builder.Append("Vehicles used:\t");
builder.AppendLine(VehicleUtilization.ToString(CultureInfo.CurrentCulture));
}
public virtual void GetReport(StringBuilder builder) {
GetEvaluationReport(builder);
InsertionInfo.GetReport(builder);
}
}
}