Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4223 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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