Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3451 was 3418, checked in by abeham, 14 years ago

Moved TabuMaker from Optimization to Optimization.Operators (and updated references)
Added StochasticMultiBranch
Implemented MultiCrossover and PermutationMultiCrossover
#976, #840

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.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 LookupParameter<ItemList<IItem>> TabuListParameter {
34      get { return (LookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
35    }
36    public ValueLookupParameter<IntValue> TabuTenureParameter {
37      get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; }
38    }
39    public ILookupParameter<DoubleValue> MoveQualityParameter {
40      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
41    }
42    public ILookupParameter<DoubleValue> QualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
44    }
45    public IValueLookupParameter<BoolValue> MaximizationParameter {
46      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
47    }
48
49    protected TabuMaker()
50      : base() {
51      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
52      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
53      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
54      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
55      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
56    }
57
58    public override IOperation Apply() {
59      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
60      int tabuTenure = TabuTenureParameter.ActualValue.Value;
61
62      int overlength = tabuList.Count - tabuTenure;
63      if (overlength >= 0) {
64        for (int i = 0; i < tabuTenure - 1; i++)
65          tabuList[i] = tabuList[i + overlength + 1];
66        while (tabuList.Count >= tabuTenure)
67          tabuList.RemoveAt(tabuList.Count - 1);
68      }
69
70      tabuList.Add(GetTabuAttribute(MaximizationParameter.ActualValue.Value, QualityParameter.ActualValue.Value, MoveQualityParameter.ActualValue.Value));
71      return base.Apply();
72    }
73
74    protected abstract IItem GetTabuAttribute(bool maximization, double quality, double moveQuality);
75  }
76}
Note: See TracBrowser for help on using the repository browser.