Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveTabuChecker.cs @ 9844

Last change on this file since 9844 was 7505, checked in by abeham, 13 years ago

#1614

  • added instances of Cordeau et al. as given by L. Moccia
  • added operators for tabu search
File size: 6.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Moves {
32  [Item("N-Move TabuChecker", "Checks if a certain N-Move is tabu.")]
33  [StorableClass]
34  public class NMoveTabuChecker : SingleSuccessorOperator, ITabuChecker,
35    IAssignmentAwareGQAPOperator, IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator {
36    public override bool CanChangeName {
37      get { return false; }
38    }
39    public ILookupParameter<NMove> MoveParameter {
40      get { return (ILookupParameter<NMove>)Parameters["Move"]; }
41    }
42    public ILookupParameter<IntegerVector> AssignmentParameter {
43      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
44    }
45    public ILookupParameter<ItemList<IItem>> TabuListParameter {
46      get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
47    }
48    public ILookupParameter<BoolValue> MoveTabuParameter {
49      get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
50    }
51    public IValueLookupParameter<BoolValue> MaximizationParameter {
52      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
53    }
54    ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {
55      get { return MaximizationParameter; }
56    }
57    public ILookupParameter<DoubleValue> MoveQualityParameter {
58      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
59    }
60    public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter {
61      get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; }
62    }
63    public ILookupParameter<DoubleValue> MoveInstallationQualityParameter {
64      get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; }
65    }
66    public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter {
67      get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; }
68    }
69    public IValueParameter<BoolValue> UseAspirationCriterionParameter {
70      get { return (IValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
71    }
72
73    public BoolValue UseAspirationCriterion {
74      get { return UseAspirationCriterionParameter.Value; }
75      set { UseAspirationCriterionParameter.Value = value; }
76    }
77
78    [StorableConstructor]
79    protected NMoveTabuChecker(bool deserializing) : base(deserializing) { }
80    protected NMoveTabuChecker(NMoveTabuChecker original, Cloner cloner) : base(original, cloner) { }
81    public NMoveTabuChecker()
82      : base() {
83      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
84      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
85      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list contains previous move attributes."));
86      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "Declares if a move is tabu or not."));
87      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
88      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
89      Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription));
90      Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription));
91      Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription));
92      Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether moves can be aspired.", new BoolValue(true)));
93    }
94
95    public override IDeepCloneable Clone(Cloner cloner) {
96      return new NMoveTabuChecker(this, cloner);
97    }
98
99    public override IOperation Apply() {
100      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
101      var move = MoveParameter.ActualValue;
102      var assignment = AssignmentParameter.ActualValue;
103      int length = assignment.Length;
104      double moveQuality = MoveQualityParameter.ActualValue.Value;
105      bool maximization = MaximizationParameter.ActualValue.Value;
106      bool useAspiration = UseAspirationCriterion.Value;
107     
108      bool isTabu = EvaluateTabuState(tabuList, move, assignment, moveQuality, maximization, useAspiration);
109
110      MoveTabuParameter.ActualValue = new BoolValue(isTabu);
111      return base.Apply();
112    }
113
114    private bool EvaluateTabuState(ItemList<IItem> tabuList, NMove move, IntegerVector assignment, double moveQuality, bool maximization, bool useAspiration) {
115      bool isTabu = false;
116      foreach (var t in tabuList) {
117        var attribute = (t as NMoveAbsoluteTabuAttribute);
118        if (attribute == null) continue;
119        if (!useAspiration
120          || maximization && moveQuality <= attribute.MoveQuality
121          || !maximization && moveQuality >= attribute.MoveQuality) {
122          isTabu = true;
123          foreach (var kvp in attribute.OldAssignments) {
124            if (move.NewAssignments.ContainsKey(kvp.Key)) {
125              if (move.NewAssignments[kvp.Key] != kvp.Value) {
126                isTabu = false;
127                break;
128              }
129            }
130          }
131        }
132        if (isTabu) break;
133      }
134      return isTabu;
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.