Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/MoveEvaluators/VRPMoveEvaluator.cs @ 4179

Last change on this file since 4179 was 4179, checked in by svonolfe, 12 years ago

Refactored VRP based on the code review (#1039)

File size: 5.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 HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.VehicleRouting.Encodings;
29
30namespace HeuristicLab.Problems.VehicleRouting {
31  [Item("VRPMoveEvaluator", "A base class for operators which evaluate VRP moves.")]
32  [StorableClass]
33  public abstract class VRPMoveEvaluator : VRPOperator, IVRPMoveEvaluator, IMoveOperator {
34    public override bool CanChangeName {
35      get { return false; }
36    }
37
38    public ILookupParameter<IVRPEncoding> VRPToursParameter {
39      get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
40    }
41   
42    public ILookupParameter<DoubleValue> FleetUsageFactor {
43      get { return (ILookupParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
44    }
45    public ILookupParameter<DoubleValue> TimeFactor {
46      get { return (ILookupParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
47    }
48    public ILookupParameter<DoubleValue> DistanceFactor {
49      get { return (ILookupParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
50    }
51    public ILookupParameter<DoubleValue> OverloadPenalty {
52      get { return (ILookupParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
53    }
54    public ILookupParameter<DoubleValue> TardinessPenalty {
55      get { return (ILookupParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
56    }
57
58    public ILookupParameter<DoubleValue> QualityParameter {
59      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
60    }
61    public ILookupParameter<DoubleValue> MoveQualityParameter {
62      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
63    }
64    public ILookupParameter<DoubleValue> MoveVehcilesUtilizedParameter {
65      get { return (ILookupParameter<DoubleValue>)Parameters["MoveVehiclesUtilized"]; }
66    }
67    public ILookupParameter<DoubleValue> MoveTravelTimeParameter {
68      get { return (ILookupParameter<DoubleValue>)Parameters["MoveTravelTime"]; }
69    }
70    public ILookupParameter<DoubleValue> MoveDistanceParameter {
71      get { return (ILookupParameter<DoubleValue>)Parameters["MoveDistance"]; }
72    }
73    public ILookupParameter<DoubleValue> MoveOverloadParameter {
74      get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverload"]; }
75    }
76    public ILookupParameter<DoubleValue> MoveTardinessParameter {
77      get { return (ILookupParameter<DoubleValue>)Parameters["MoveTardiness"]; }
78    }
79
80    [StorableConstructor]
81    protected VRPMoveEvaluator(bool deserializing) : base(deserializing) { }
82
83    protected VRPMoveEvaluator()
84      : base() {
85      Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours."));
86      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a VRP solution."));
87      Parameters.Add(new LookupParameter<DoubleValue>("MoveVehiclesUtilized", "The number of vehicles utilized."));
88      Parameters.Add(new LookupParameter<DoubleValue>("MoveTravelTime", "The total travel time."));
89      Parameters.Add(new LookupParameter<DoubleValue>("MoveDistance", "The distance."));
90      Parameters.Add(new LookupParameter<DoubleValue>("MoveOverload", "The overload."));
91      Parameters.Add(new LookupParameter<DoubleValue>("MoveTardiness", "The tardiness."));
92      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a VRP solution."));
93      Parameters.Add(new LookupParameter<DoubleValue>("EvalFleetUsageFactor", "The fleet usage factor considered in the evaluation."));
94      Parameters.Add(new LookupParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation."));
95      Parameters.Add(new LookupParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation."));
96      Parameters.Add(new LookupParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation."));
97      Parameters.Add(new LookupParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation."));
98    }
99
100    protected abstract TourEvaluation GetMoveQuality();
101
102    public override IOperation Apply() {
103      TourEvaluation tourEval = GetMoveQuality();
104
105      MoveQualityParameter.ActualValue = new DoubleValue(tourEval.Quality);
106      MoveDistanceParameter.ActualValue = new DoubleValue(tourEval.Distance);
107      MoveVehcilesUtilizedParameter.ActualValue = new DoubleValue(tourEval.VehcilesUtilized);
108      MoveOverloadParameter.ActualValue = new DoubleValue(tourEval.Overload);
109      MoveTardinessParameter.ActualValue = new DoubleValue(tourEval.Tardiness);
110      MoveTravelTimeParameter.ActualValue = new DoubleValue(tourEval.TravelTime);
111
112      return base.Apply();
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.