Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Operators/3.3/TabuMaker.cs @ 5637

Last change on this file since 5637 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Optimization.Operators {
30  [Item("TabuMaker", "Base class for all operators that set a move tabu.")]
31  [StorableClass]
32  public abstract class TabuMaker : SingleSuccessorOperator, ITabuMaker {
33    public override bool CanChangeName {
34      get { return false; }
35    }
36    public LookupParameter<ItemList<IItem>> TabuListParameter {
37      get { return (LookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
38    }
39    public ValueLookupParameter<IntValue> TabuTenureParameter {
40      get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; }
41    }
42    public ILookupParameter<DoubleValue> MoveQualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
44    }
45    public ILookupParameter<DoubleValue> QualityParameter {
46      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
47    }
48    public IValueLookupParameter<BoolValue> MaximizationParameter {
49      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
50    }
51
52    [StorableConstructor]
53    protected TabuMaker(bool deserializing) : base(deserializing) { }
54    protected TabuMaker(TabuMaker original, Cloner cloner) : base(original, cloner) { }
55    protected TabuMaker()
56      : base() {
57      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
58      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
59      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
60      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
61      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
62    }
63
64    public override IOperation Apply() {
65      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
66      int tabuTenure = TabuTenureParameter.ActualValue.Value;
67
68      int overlength = tabuList.Count - tabuTenure;
69      if (overlength >= 0) {
70        for (int i = 0; i < tabuTenure - 1; i++)
71          tabuList[i] = tabuList[i + overlength + 1];
72        while (tabuList.Count >= tabuTenure)
73          tabuList.RemoveAt(tabuList.Count - 1);
74      }
75
76      tabuList.Add(GetTabuAttribute(MaximizationParameter.ActualValue.Value, QualityParameter.ActualValue.Value, MoveQualityParameter.ActualValue.Value));
77      return base.Apply();
78    }
79
80    protected abstract IItem GetTabuAttribute(bool maximization, double quality, double moveQuality);
81  }
82}
Note: See TracBrowser for help on using the repository browser.