Changeset 3340 for trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveHardTabuCriterion.cs
- Timestamp:
- 04/14/10 03:52:07 (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveHardTabuCriterion.cs
r3307 r3340 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item("PreventRemovalInversionMoveTabuChecker", "Prevents deleting of previously added edges.")] 31 [Item("InversionMoveHardTabuCriterion", @"For relative postion encoded permutations it prevents readding of previously deleted edges as well as deleting previously added edges. 32 For absolute position encoded permutations it prevents moving a number if it was previously moved. 33 34 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 32 35 [StorableClass] 33 public class PreventRemovalInversionMoveTabuChecker: SingleSuccessorOperator, IPermutationInversionMoveOperator, ITabuChecker {36 public class InversionMoveHardTabuCriterion : SingleSuccessorOperator, IPermutationInversionMoveOperator, ITabuChecker { 34 37 public override bool CanChangeName { 35 38 get { return false; } … … 47 50 get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; } 48 51 } 49 private ScopeParameter CurrentScopeParameter { 50 get { return (ScopeParameter)Parameters["CurrentScope"]; } 52 public IValueLookupParameter<BoolValue> MaximizationParameter { 53 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 54 } 55 public ILookupParameter<DoubleValue> MoveQualityParameter { 56 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 57 } 58 public ValueParameter<BoolValue> UseAspirationCriterionParameter { 59 get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; } 51 60 } 52 61 53 public PreventRemovalInversionMoveTabuChecker() 62 public BoolValue UseAspirationCriterion { 63 get { return UseAspirationCriterionParameter.Value; } 64 set { UseAspirationCriterionParameter.Value = value; } 65 } 66 67 public InversionMoveHardTabuCriterion() 54 68 : base() { 55 69 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move to evaluate.")); … … 57 71 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); 58 72 Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list.")); 59 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope.")); 73 Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true))); 74 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem.")); 75 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move.")); 60 76 } 61 77 … … 65 81 Permutation permutation = PermutationParameter.ActualValue; 66 82 int length = permutation.Length; 83 double moveQuality = MoveQualityParameter.ActualValue.Value; 84 bool maximization = MaximizationParameter.ActualValue.Value; 85 bool useAspiration = UseAspirationCriterion.Value; 67 86 bool isTabu = false; 87 68 88 foreach (IItem tabuMove in tabuList) { 69 switch (permutation.PermutationType) { 70 case PermutationTypes.RelativeUndirected: { 71 int E1S = permutation.GetCircular(move.Index1 - 1); 72 int E1T = permutation[move.Index1]; 73 int E2S = permutation[move.Index2]; 74 int E2T = permutation.GetCircular(move.Index2 + 1); 75 InversionMoveRelativeAttribute relAttrib = (tabuMove as InversionMoveRelativeAttribute); 76 if (relAttrib != null) { 77 if (relAttrib.Edge1Source == E1S && relAttrib.Edge2Source == E1T || relAttrib.Edge1Source == E1T && relAttrib.Edge2Source == E1S 78 || relAttrib.Edge1Source == E2S && relAttrib.Edge2Source == E2T || relAttrib.Edge1Source == E2T && relAttrib.Edge2Source == E2S 79 // if previously added Edge1Target-Edge2Target is deleted 80 || relAttrib.Edge1Target == E2S && relAttrib.Edge2Target == E2T || relAttrib.Edge1Target == E2T && relAttrib.Edge2Target == E2S 81 || relAttrib.Edge1Target == E1S && relAttrib.Edge2Target == E1T || relAttrib.Edge1Target == E1T && relAttrib.Edge2Target == E1S) { 82 isTabu = true; 89 PermutationMoveAttribute attrib = (tabuMove as PermutationMoveAttribute); 90 if (!useAspiration 91 || maximization && moveQuality <= attrib.MoveQuality 92 || !maximization && moveQuality >= attrib.MoveQuality) { 93 switch (permutation.PermutationType) { 94 case PermutationTypes.RelativeUndirected: { 95 int E1S = permutation.GetCircular(move.Index1 - 1); 96 int E1T = permutation[move.Index1]; 97 int E2S = permutation[move.Index2]; 98 int E2T = permutation.GetCircular(move.Index2 + 1); 99 InversionMoveRelativeAttribute relAttrib = (attrib as InversionMoveRelativeAttribute); 100 if (relAttrib != null) { 101 if (relAttrib.Edge1Source == E1S && relAttrib.Edge2Source == E1T || relAttrib.Edge1Source == E1T && relAttrib.Edge2Source == E1S 102 || relAttrib.Edge1Source == E2S && relAttrib.Edge2Source == E2T || relAttrib.Edge1Source == E2T && relAttrib.Edge2Source == E2S 103 // if previously added Edge1Target-Edge2Target is deleted 104 || relAttrib.Edge1Target == E2S && relAttrib.Edge2Target == E2T || relAttrib.Edge1Target == E2T && relAttrib.Edge2Target == E2S 105 || relAttrib.Edge1Target == E1S && relAttrib.Edge2Target == E1T || relAttrib.Edge1Target == E1T && relAttrib.Edge2Target == E1S) { 106 isTabu = true; 107 } 83 108 } 84 109 } 85 }86 break;87 case PermutationTypes.RelativeDirected: {88 int E1S = permutation.GetCircular(move.Index1 - 1);89 int E1T = permutation[move.Index1];90 int E2S = permutation[move.Index2];91 int E2T = permutation.GetCircular(move.Index2 + 1);92 InversionMoveRelativeAttribute relAttrib = (tabuMove as InversionMoveRelativeAttribute);93 if (relAttrib != null) {94 if (relAttrib.Edge1Source == E1S && relAttrib.Edge2Source == E1T95 || relAttrib.Edge1Source == E2S && relAttrib.Edge2Source == E2T96 // if previously added Edge1Target-Edge2Target is deleted97 || relAttrib.Edge1Target == E2S && relAttrib.Edge2Target == E2T98 || relAttrib.Edge1Target == E1S && relAttrib.Edge2Target == E1T) {99 isTabu = true;110 break; 111 case PermutationTypes.RelativeDirected: { 112 int E1S = permutation.GetCircular(move.Index1 - 1); 113 int E1T = permutation[move.Index1]; 114 int E2S = permutation[move.Index2]; 115 int E2T = permutation.GetCircular(move.Index2 + 1); 116 InversionMoveRelativeAttribute relAttrib = (attrib as InversionMoveRelativeAttribute); 117 if (relAttrib != null) { 118 if (relAttrib.Edge1Source == E1S && relAttrib.Edge2Source == E1T 119 || relAttrib.Edge1Source == E2S && relAttrib.Edge2Source == E2T 120 // if previously added Edge1Target-Edge2Target is deleted 121 || relAttrib.Edge1Target == E2S && relAttrib.Edge2Target == E2T 122 || relAttrib.Edge1Target == E1S && relAttrib.Edge2Target == E1T) { 123 isTabu = true; 124 } 100 125 } 101 126 } 102 } 103 break; 104 case PermutationTypes.Absolute: { 105 int i1 = move.Index1; 106 int n1 = permutation[move.Index1]; 107 int i2 = move.Index2; 108 int n2 = permutation[move.Index2]; 109 InversionMoveAbsoluteAttribute absAttrib = (tabuMove as InversionMoveAbsoluteAttribute); 110 if (absAttrib != null) { 111 if (absAttrib.Number1 == n1 || absAttrib.Number1 == n2 112 || absAttrib.Number2 == n2 || absAttrib.Number2 == n1) 113 isTabu = true; 127 break; 128 case PermutationTypes.Absolute: { 129 int i1 = move.Index1; 130 int n1 = permutation[move.Index1]; 131 int i2 = move.Index2; 132 int n2 = permutation[move.Index2]; 133 InversionMoveAbsoluteAttribute absAttrib = (attrib as InversionMoveAbsoluteAttribute); 134 if (absAttrib != null) { 135 if (absAttrib.Number1 == n1 || absAttrib.Number1 == n2 136 || absAttrib.Number2 == n2 || absAttrib.Number2 == n1) 137 isTabu = true; 114 138 139 } 115 140 } 116 }117 break;118 default: {119 throw new InvalidOperationException(Name + ": Unknown permutation type.");120 141 break; 142 default: { 143 throw new InvalidOperationException(Name + ": Unknown permutation type."); 144 } 145 } 121 146 } 122 147 if (isTabu) break;
Note: See TracChangeset
for help on using the changeset viewer.