[6851] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6851] | 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 |
|
---|
[8053] | 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[6851] | 25 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 29 | [Item("SingleDepotVRPEvaluator", "Represents a single depot VRP evaluator.")]
|
---|
| 30 | [StorableClass]
|
---|
[8053] | 31 | public class MultiDepotVRPEvaluator : VRPEvaluator {
|
---|
[6851] | 32 | protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
|
---|
[6883] | 33 | TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
|
---|
[6851] | 34 | eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
|
---|
[8053] | 35 |
|
---|
[6851] | 36 | double distance = 0.0;
|
---|
| 37 | double quality = 0.0;
|
---|
| 38 |
|
---|
| 39 | //simulate a tour, start and end at depot
|
---|
| 40 | for (int i = 0; i <= tour.Stops.Count; i++) {
|
---|
| 41 | int start = 0;
|
---|
| 42 | if (i > 0)
|
---|
| 43 | start = tour.Stops[i - 1];
|
---|
| 44 | int end = 0;
|
---|
| 45 | if (i < tour.Stops.Count)
|
---|
| 46 | end = tour.Stops[i];
|
---|
| 47 |
|
---|
| 48 | //drive there
|
---|
| 49 | double currentDistace = instance.GetDistance(start, end, solution);
|
---|
| 50 | distance += currentDistace;
|
---|
| 51 |
|
---|
| 52 | StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
|
---|
| 53 | tourInfo.AddStopInsertionInfo(stopInfo);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | //Fleet usage
|
---|
| 57 | quality += instance.FleetUsageFactor.Value;
|
---|
| 58 | //Distance
|
---|
| 59 | quality += instance.DistanceFactor.Value * distance;
|
---|
| 60 |
|
---|
| 61 | eval.Distance += distance;
|
---|
| 62 | eval.VehicleUtilization += 1;
|
---|
| 63 |
|
---|
| 64 | eval.Quality += quality;
|
---|
[7276] | 65 | tourInfo.Quality = quality;
|
---|
[6851] | 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
|
---|
| 69 | out bool feasible) {
|
---|
| 70 | StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
|
---|
[8053] | 71 |
|
---|
[6851] | 72 | double costs = 0;
|
---|
| 73 | feasible = true;
|
---|
[6854] | 74 | double startDistance, endDistance;
|
---|
[6851] | 75 |
|
---|
[6854] | 76 | costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
|
---|
[6851] | 77 |
|
---|
| 78 | return costs;
|
---|
| 79 | }
|
---|
[8053] | 80 |
|
---|
[6851] | 81 | [StorableConstructor]
|
---|
| 82 | protected MultiDepotVRPEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 83 |
|
---|
| 84 | public MultiDepotVRPEvaluator() {
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 88 | return new MultiDepotVRPEvaluator(this, cloner);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | protected MultiDepotVRPEvaluator(MultiDepotVRPEvaluator original, Cloner cloner)
|
---|
| 92 | : base(original, cloner) {
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | } |
---|