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 |
|
---|
22 | using HeuristicLab.Core;
|
---|
23 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
24 | using HeuristicLab.Parameters;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 |
|
---|
30 | namespace 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 | }
|
---|