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 System;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Encodings.BinaryVectorEncoding {
|
---|
31 | [Item("OneBitflipMoveTabuChecker", "Prevents peforming a one bitflip move again.")]
|
---|
32 | [StorableClass]
|
---|
33 | public class OneBitflipMoveTabuChecker : SingleSuccessorOperator, IOneBitflipMoveOperator, ITabuChecker {
|
---|
34 | public ILookupParameter<OneBitflipMove> OneBitflipMoveParameter {
|
---|
35 | get { return (LookupParameter<OneBitflipMove>)Parameters["OneBitflipMove"]; }
|
---|
36 | }
|
---|
37 | public ILookupParameter<BinaryVector> BinaryVectorParameter {
|
---|
38 | get { return (LookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
|
---|
39 | }
|
---|
40 | public ILookupParameter<ItemList<IItem>> TabuListParameter {
|
---|
41 | get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
|
---|
42 | }
|
---|
43 | public ILookupParameter<BoolValue> MoveTabuParameter {
|
---|
44 | get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
|
---|
45 | }
|
---|
46 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
47 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
48 | }
|
---|
49 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
50 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
51 | }
|
---|
52 | public ValueParameter<BoolValue> UseAspirationCriterionParameter {
|
---|
53 | get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public BoolValue UseAspirationCriterion {
|
---|
57 | get { return UseAspirationCriterionParameter.Value; }
|
---|
58 | set { UseAspirationCriterionParameter.Value = value; }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public OneBitflipMoveTabuChecker()
|
---|
62 | : base() {
|
---|
63 | Parameters.Add(new LookupParameter<OneBitflipMove>("OneBitflipMove", "The move to evaluate."));
|
---|
64 | Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
|
---|
65 | Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The solution as permutation."));
|
---|
66 | Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list."));
|
---|
67 | Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
|
---|
68 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
|
---|
69 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move."));
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override IOperation Apply() {
|
---|
73 | ItemList<IItem> tabuList = TabuListParameter.ActualValue;
|
---|
74 | OneBitflipMove move = OneBitflipMoveParameter.ActualValue;
|
---|
75 | double moveQuality = MoveQualityParameter.ActualValue.Value;
|
---|
76 | bool maximization = MaximizationParameter.ActualValue.Value;
|
---|
77 | bool useAspiration = UseAspirationCriterion.Value;
|
---|
78 | bool isTabu = false;
|
---|
79 | foreach (IItem tabuMove in tabuList) {
|
---|
80 | OneBitflipMoveAttribute attribute = (tabuMove as OneBitflipMoveAttribute);
|
---|
81 | if (attribute != null) {
|
---|
82 | if (!useAspiration
|
---|
83 | || maximization && moveQuality <= attribute.MoveQuality
|
---|
84 | || !maximization && moveQuality >= attribute.MoveQuality) {
|
---|
85 | if (attribute.Index == move.Index) {
|
---|
86 | isTabu = true;
|
---|
87 | break;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|
92 | MoveTabuParameter.ActualValue = new BoolValue(isTabu);
|
---|
93 | return base.Apply();
|
---|
94 | }
|
---|
95 |
|
---|
96 | public override bool CanChangeName {
|
---|
97 | get { return false; }
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|