1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
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]
|
---|
31 | public class SingleDepotVRPEvaluator : VRPEvaluator {
|
---|
32 | protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
|
---|
33 | TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
|
---|
34 | eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
|
---|
35 |
|
---|
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 | tourInfo.Quality = quality;
|
---|
65 | eval.Quality += quality;
|
---|
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);
|
---|
71 |
|
---|
72 | double costs = 0;
|
---|
73 | feasible = true;
|
---|
74 |
|
---|
75 | double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
|
---|
76 | double newDistance =
|
---|
77 | instance.GetDistance(insertionInfo.Start, customer, solution) +
|
---|
78 | instance.GetDistance(customer, insertionInfo.End, solution);
|
---|
79 |
|
---|
80 | costs += instance.DistanceFactor.Value * (newDistance - distance);
|
---|
81 |
|
---|
82 | return costs;
|
---|
83 | }
|
---|
84 |
|
---|
85 | [StorableConstructor]
|
---|
86 | protected SingleDepotVRPEvaluator(bool deserializing) : base(deserializing) { }
|
---|
87 |
|
---|
88 | public SingleDepotVRPEvaluator() {
|
---|
89 | }
|
---|
90 |
|
---|
91 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
92 | return new SingleDepotVRPEvaluator(this, cloner);
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected SingleDepotVRPEvaluator(SingleDepotVRPEvaluator original, Cloner cloner)
|
---|
96 | : base(original, cloner) {
|
---|
97 | }
|
---|
98 | }
|
---|
99 | } |
---|