Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveTabuCriterion.cs @ 9503

Last change on this file since 9503 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.VehicleRouting.Interfaces;
30
31namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
32  [Item("PotvinCustomerRelocationTabuCriterion", @"Checks if a certain customer relocation move is tabu.")]
33  [StorableClass]
34  public class PotvinCustomerRelocationMoveTabuCriterion : SingleSuccessorOperator, IPotvinCustomerRelocationMoveOperator, ITabuChecker, IPotvinOperator, IVRPMoveOperator {
35    public override bool CanChangeName {
36      get { return false; }
37    }
38
39    public ILookupParameter<PotvinCustomerRelocationMove> CustomerRelocationMoveParameter {
40      get { return (ILookupParameter<PotvinCustomerRelocationMove>)Parameters["PotvinCustomerRelocationMove"]; }
41    }
42    public ILookupParameter VRPMoveParameter {
43      get { return CustomerRelocationMoveParameter; }
44    }
45    public ILookupParameter<IVRPEncoding> VRPToursParameter {
46      get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
47    }
48    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
49      get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
50    }
51
52    public ILookupParameter<ItemList<IItem>> TabuListParameter {
53      get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
54    }
55    public ILookupParameter<BoolValue> MoveTabuParameter {
56      get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
57    }
58    public IValueLookupParameter<BoolValue> MaximizationParameter {
59      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
60    }
61    public ILookupParameter<DoubleValue> MoveQualityParameter {
62      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
63    }
64    public ValueParameter<BoolValue> UseAspirationCriterionParameter {
65      get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
66    }
67
68    public BoolValue UseAspirationCriterion {
69      get { return UseAspirationCriterionParameter.Value; }
70      set { UseAspirationCriterionParameter.Value = value; }
71    }
72
73    [StorableConstructor]
74    protected PotvinCustomerRelocationMoveTabuCriterion(bool deserializing) : base(deserializing) { }
75    protected PotvinCustomerRelocationMoveTabuCriterion(PotvinCustomerRelocationMoveTabuCriterion original, Cloner cloner) : base(original, cloner) { }
76    public PotvinCustomerRelocationMoveTabuCriterion()
77      : base() {
78      Parameters.Add(new LookupParameter<PotvinCustomerRelocationMove>("PotvinCustomerRelocationMove", "The moves that should be made."));
79      Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
80      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
81
82      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
83      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list."));
84      Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
85      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
86      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move."));
87    }
88
89    public override IDeepCloneable Clone(Cloner cloner) {
90      return new PotvinCustomerRelocationMoveTabuCriterion(this, cloner);
91    }
92
93    public override IOperation Apply() {
94      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
95      double moveQuality = MoveQualityParameter.ActualValue.Value;
96      bool useAspiration = UseAspirationCriterion.Value;
97      bool isTabu = false;
98      PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue;
99
100      foreach (IItem tabuMove in tabuList) {
101        PotvinCustomerRelocationMoveAttribute attribute = tabuMove as PotvinCustomerRelocationMoveAttribute;
102
103        if (!useAspiration || moveQuality >= attribute.MoveQuality) {
104          if (attribute.City == move.City && attribute.Tour == move.Tour) {
105            isTabu = true;
106            break;
107          }
108        }
109      }
110
111      MoveTabuParameter.ActualValue = new BoolValue(isTabu);
112      return base.Apply();
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.