Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs @ 11171

Last change on this file since 11171 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 3.5 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Problems.VehicleRouting.Interfaces;
26
27
28namespace 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}
Note: See TracBrowser for help on using the repository browser.