Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18140 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.8 KB
RevLine 
[3418]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3418]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
[9001]22using System;
[4722]23using HeuristicLab.Common;
[3418]24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
[16565]28using HEAL.Attic;
[3418]29
30namespace HeuristicLab.Optimization.Operators {
31  [Item("TabuMaker", "Base class for all operators that set a move tabu.")]
[16565]32  [StorableType("1124A697-DDF1-442E-8CBB-FA0D51B4C736")]
[11970]33  public abstract class TabuMaker : SingleSuccessorOperator, ITabuMaker, ISingleObjectiveOperator {
[3520]34    public override bool CanChangeName {
35      get { return false; }
36    }
[3418]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
[4722]53    [StorableConstructor]
[16565]54    protected TabuMaker(StorableConstructorFlag _) : base(_) { }
[4722]55    protected TabuMaker(TabuMaker original, Cloner cloner) : base(original, cloner) { }
[3418]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;
[9001]68      if (tabuTenure == 0) return base.Apply();
69      if (tabuTenure < 0) throw new InvalidOperationException("A TabuTenure of less than 0 is not allowed.");
[3418]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.