Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14192 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

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