[3418] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace 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 {
|
---|
[3520] | 33 | public override bool CanChangeName {
|
---|
| 34 | get { return false; }
|
---|
| 35 | }
|
---|
[3418] | 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 | protected TabuMaker()
|
---|
| 53 | : base() {
|
---|
| 54 | Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
|
---|
| 55 | Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
|
---|
| 56 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
|
---|
| 57 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
|
---|
| 58 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public override IOperation Apply() {
|
---|
| 62 | ItemList<IItem> tabuList = TabuListParameter.ActualValue;
|
---|
| 63 | int tabuTenure = TabuTenureParameter.ActualValue.Value;
|
---|
| 64 |
|
---|
| 65 | int overlength = tabuList.Count - tabuTenure;
|
---|
| 66 | if (overlength >= 0) {
|
---|
| 67 | for (int i = 0; i < tabuTenure - 1; i++)
|
---|
| 68 | tabuList[i] = tabuList[i + overlength + 1];
|
---|
| 69 | while (tabuList.Count >= tabuTenure)
|
---|
| 70 | tabuList.RemoveAt(tabuList.Count - 1);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | tabuList.Add(GetTabuAttribute(MaximizationParameter.ActualValue.Value, QualityParameter.ActualValue.Value, MoveQualityParameter.ActualValue.Value));
|
---|
| 74 | return base.Apply();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | protected abstract IItem GetTabuAttribute(bool maximization, double quality, double moveQuality);
|
---|
| 78 | }
|
---|
| 79 | }
|
---|