Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs @ 12214

Last change on this file since 12214 was 11185, checked in by pfleck, 10 years ago

#2208 merged trunk and updated version info

File size: 3.5 KB
RevLine 
[4362]1#region License Information
2/* HeuristicLab
[11185]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[4362]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]22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[4362]25using HeuristicLab.Problems.VehicleRouting.Interfaces;
26
[4363]27
28namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
[4362]29  [Item("SingleDepotVRPEvaluator", "Represents a single depot VRP evaluator.")]
30  [StorableClass]
[8053]31  public class SingleDepotVRPEvaluator : VRPEvaluator {
[6838]32    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
[6883]33      TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
[6752]34      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
[8053]35
[4363]36      double distance = 0.0;
37      double quality = 0.0;
[4362]38
[4363]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
[6851]49        double currentDistace = instance.GetDistance(start, end, solution);
[4363]50        distance += currentDistace;
[6752]51
52        StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
53        tourInfo.AddStopInsertionInfo(stopInfo);
[4363]54      }
55
56      //Fleet usage
57      quality += instance.FleetUsageFactor.Value;
58      //Distance
59      quality += instance.DistanceFactor.Value * distance;
60
[4378]61      eval.Distance += distance;
62      eval.VehicleUtilization += 1;
[4363]63
[7276]64      tourInfo.Quality = quality;
[4378]65      eval.Quality += quality;
[4362]66    }
[6752]67
[6851]68    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
[6752]69      out bool feasible) {
70      StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
[8053]71
[6752]72      double costs = 0;
73      feasible = true;
74
[6851]75      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
[6752]76      double newDistance =
[6851]77        instance.GetDistance(insertionInfo.Start, customer, solution) +
78        instance.GetDistance(customer, insertionInfo.End, solution);
[6752]79
80      costs += instance.DistanceFactor.Value * (newDistance - distance);
81
82      return costs;
83    }
[8053]84
[4362]85    [StorableConstructor]
86    protected SingleDepotVRPEvaluator(bool deserializing) : base(deserializing) { }
87
88    public SingleDepotVRPEvaluator() {
89    }
[4752]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    }
[4362]98  }
99}
Note: See TracBrowser for help on using the repository browser.