Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs @ 4501

Last change on this file since 4501 was 4378, checked in by svonolfe, 14 years ago

Improved performance of PotvinEncoding(#1177)

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Problems.VehicleRouting.Interfaces;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Core;
29using HeuristicLab.Parameters;
30using HeuristicLab.Data;
31using HeuristicLab.Optimization;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Problems.VehicleRouting.Variants;
34using HeuristicLab.Problems.VehicleRouting.Encodings;
35
36namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
37  [Item("CVRPEvaluator", "Represents a single depot CVRP evaluator.")]
38  [StorableClass]
39  public class CVRPEvaluator: SingleDepotVRPEvaluator {
40    public ILookupParameter<DoubleValue> OverloadParameter {
41      get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
42    }
43
44    protected override VRPEvaluation CreateTourEvaluation() {
45      return new CVRPEvaluation();
46    }
47
48    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
49      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
50      DoubleArray demand = instance.Demand;
51
52      double delivered = 0.0;
53      double overweight = 0.0;
54      double distance = 0.0;
55
56      //simulate a tour, start and end at depot
57      for (int i = 0; i <= tour.Stops.Count; i++) {
58        int start = 0;
59        if (i > 0)
60          start = tour.Stops[i - 1];
61        int end = 0;
62        if (i < tour.Stops.Count)
63          end = tour.Stops[i];
64
65        //drive there
66        double currentDistace = instance.GetDistance(start, end);
67        distance += currentDistace;
68
69        delivered += demand[end];
70      }
71
72      eval.Quality += instance.FleetUsageFactor.Value;
73      eval.Quality += instance.DistanceFactor.Value * distance;
74
75      eval.Distance += distance;
76      eval.VehicleUtilization += 1;
77
78      double capacity = cvrpInstance.Capacity.Value;
79      if (delivered > capacity) {
80        overweight = delivered - capacity;
81      }
82
83      (eval as CVRPEvaluation).Overload += overweight;
84      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
85      eval.Penalty += penalty;
86      eval.Quality += penalty;
87    }
88
89    protected override void InitResultParameters() {
90      base.InitResultParameters();
91
92      OverloadParameter.ActualValue = new DoubleValue(0);
93    }
94
95    protected override void UpdateResultParameters(VRPEvaluation tourEvaluation) {
96      base.UpdateResultParameters(tourEvaluation);
97
98      OverloadParameter.ActualValue.Value += (tourEvaluation as CVRPEvaluation).Overload;
99    }
100   
101    [StorableConstructor]
102    protected CVRPEvaluator(bool deserializing) : base(deserializing) { }
103
104    public CVRPEvaluator() {
105      Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload."));
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.