Free cookie consent management tool by TermsFeed Policy Generator

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

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

Merged relevant changes from the trunk into the branch (cloning,...) (#1177)

File size: 4.0 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;
35using HeuristicLab.Common;
36
37namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
38  [Item("CVRPEvaluator", "Represents a single depot CVRP evaluator.")]
39  [StorableClass]
40  public class CVRPEvaluator: SingleDepotVRPEvaluator {
41    public ILookupParameter<DoubleValue> OverloadParameter {
42      get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
43    }
44
45    protected override VRPEvaluation CreateTourEvaluation() {
46      return new CVRPEvaluation();
47    }
48
49    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
50      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
51      DoubleArray demand = instance.Demand;
52
53      double delivered = 0.0;
54      double overweight = 0.0;
55      double distance = 0.0;
56
57      //simulate a tour, start and end at depot
58      for (int i = 0; i <= tour.Stops.Count; i++) {
59        int start = 0;
60        if (i > 0)
61          start = tour.Stops[i - 1];
62        int end = 0;
63        if (i < tour.Stops.Count)
64          end = tour.Stops[i];
65
66        //drive there
67        double currentDistace = instance.GetDistance(start, end);
68        distance += currentDistace;
69
70        delivered += demand[end];
71      }
72
73      eval.Quality += instance.FleetUsageFactor.Value;
74      eval.Quality += instance.DistanceFactor.Value * distance;
75
76      eval.Distance += distance;
77      eval.VehicleUtilization += 1;
78
79      double capacity = cvrpInstance.Capacity.Value;
80      if (delivered > capacity) {
81        overweight = delivered - capacity;
82      }
83
84      (eval as CVRPEvaluation).Overload += overweight;
85      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
86      eval.Penalty += penalty;
87      eval.Quality += penalty;
88    }
89
90    protected override void InitResultParameters() {
91      base.InitResultParameters();
92
93      OverloadParameter.ActualValue = new DoubleValue(0);
94    }
95
96    protected override void SetResultParameters(VRPEvaluation tourEvaluation) {
97      base.SetResultParameters(tourEvaluation);
98
99      OverloadParameter.ActualValue.Value = (tourEvaluation as CVRPEvaluation).Overload;
100    }
101   
102    [StorableConstructor]
103    protected CVRPEvaluator(bool deserializing) : base(deserializing) { }
104
105    public CVRPEvaluator() {
106      Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload."));
107    }
108
109    public override IDeepCloneable Clone(Cloner cloner) {
110      return new CVRPEvaluator(this, cloner);
111    }
112
113    protected CVRPEvaluator(CVRPEvaluator original, Cloner cloner)
114      : base(original, cloner) {
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.