Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveEvaluator.cs @ 7080

Last change on this file since 7080 was 6751, checked in by svonolfe, 13 years ago

Fixed minor bugs in VRP operators (#1177)

File size: 4.6 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.Encodings.PermutationEncoding;
24using HeuristicLab.Parameters;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Data;
27using HeuristicLab.Common;
28using HeuristicLab.Optimization;
29
30namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
31  [Item("PotvinCustomerRelocationMoveEvaluator", "Evaluates a customer relocation move for a VRP representation. ")]
32  [StorableClass]
33  public sealed class PotvinCustomerRelocationMoveEvaluator : PotvinMoveEvaluator, IPotvinCustomerRelocationMoveOperator {
34    public ILookupParameter<PotvinCustomerRelocationMove> CustomerRelocationMoveParameter {
35      get { return (ILookupParameter<PotvinCustomerRelocationMove>)Parameters["PotvinCustomerRelocationMove"]; }
36    }
37
38    public override ILookupParameter VRPMoveParameter {
39      get { return CustomerRelocationMoveParameter; }
40    }
41
42    public ILookupParameter<VariableCollection> MemoriesParameter {
43      get { return (ILookupParameter<VariableCollection>)Parameters["Memories"]; }
44    }
45
46    public IValueParameter<StringValue> AdditionFrequencyMemoryKeyParameter {
47      get { return (IValueParameter<StringValue>)Parameters["AdditionFrequencyMemoryKey"]; }
48    }
49
50    public IValueParameter<DoubleValue> LambdaParameter {
51      get { return (IValueParameter<DoubleValue>)Parameters["Lambda"]; }
52    }
53
54    [StorableConstructor]
55    private PotvinCustomerRelocationMoveEvaluator(bool deserializing) : base(deserializing) { }
56
57    public PotvinCustomerRelocationMoveEvaluator()
58      : base() {
59       Parameters.Add(new LookupParameter<PotvinCustomerRelocationMove>("PotvinCustomerRelocationMove", "The move that should be evaluated."));
60
61       Parameters.Add(new LookupParameter<VariableCollection>("Memories", "The TS memory collection."));
62       Parameters.Add(new ValueParameter<StringValue>("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
63       Parameters.Add(new ValueParameter<DoubleValue>("Lambda", "The lambda parameter.", new DoubleValue(0.015)));
64    }
65
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new PotvinCustomerRelocationMoveEvaluator(this, cloner);
68    }
69
70    private PotvinCustomerRelocationMoveEvaluator(PotvinCustomerRelocationMoveEvaluator original, Cloner cloner)
71      : base(original, cloner) {
72    }
73
74    protected override void EvaluateMove() {
75      PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue;
76
77      PotvinEncoding newSolution = CustomerRelocationMoveParameter.ActualValue.Individual.Clone() as PotvinEncoding;
78      PotvinCustomerRelocationMoveMaker.Apply(newSolution, move, ProblemInstance);
79
80      UpdateEvaluation(newSolution);
81
82      //Apply memory, only if move is worse
83      if (MoveQualityParameter.ActualValue.Value >= QualityParameter.ActualValue.Value) {
84        VariableCollection memory = MemoriesParameter.ActualValue;
85        string key = AdditionFrequencyMemoryKeyParameter.Value.Value;
86
87        if (memory != null && memory.ContainsKey(key)) {
88          ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
89               memory[key].Value as ItemDictionary<PotvinCustomerRelocationMoveAttribute, IntValue>;
90          PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City);
91          if (additionFrequency.ContainsKey(attr)) {
92            int frequency = additionFrequency[attr].Value;
93            double quality = MoveQualityParameter.ActualValue.Value;
94
95            MoveQualityParameter.ActualValue.Value +=
96              LambdaParameter.Value.Value * quality * frequency;
97          }
98        }
99      }
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.