1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 MultiDepotVRPEvaluator : 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 | eval.Quality += quality;
|
---|
65 | tourInfo.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 | double startDistance, endDistance;
|
---|
75 |
|
---|
76 | costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
|
---|
77 |
|
---|
78 | return costs;
|
---|
79 | }
|
---|
80 |
|
---|
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 | } |
---|