1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Optimization.Operators {
|
---|
31 | [Item("TabuMaker", "Base class for all operators that set a move tabu.")]
|
---|
32 | [StorableType("48B51064-F803-4DEC-BAE6-66F651723677")]
|
---|
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 | }
|
---|