- Timestamp:
- 03/26/10 00:04:24 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/ExhaustiveTwoOptMoveGenerator.cs
r3098 r3221 26 26 27 27 namespace HeuristicLab.Encodings.PermutationEncoding { 28 [Item("ExhaustiveTwoOptMoveGenerator", "Generates all possible 2-opt moves from a given permutation.")]28 [Item("ExhaustiveTwoOptMoveGenerator", "Generates all possible 2-opt moves (inversion) from a given permutation.")] 29 29 [StorableClass] 30 30 public class ExhaustiveTwoOptMoveGenerator : TwoOptMoveGenerator, IExhaustiveMoveGenerator { 31 31 public static TwoOptMove[] Apply(Permutation permutation) { 32 32 int length = permutation.Length; 33 int totalMoves = (length) * (length - 1) / 2 - 3;33 int totalMoves = (length) * (length - 1) / 2; // - 3; 34 34 TwoOptMove[] moves = new TwoOptMove[totalMoves]; 35 35 int count = 0; … … 37 37 for (int j = i + 1; j < length; j++) { 38 38 // doesn't make sense to inverse the whole permutation or the whole but one 39 if (i == 0 && j >= length - 2) continue;40 else if (i == 1 && j >= length - 1) continue; 39 /*if (i == 0 && j >= length - 2) continue; 40 else if (i == 1 && j >= length - 1) continue;*/ 41 41 moves[count++] = new TwoOptMove(i, j); 42 42 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/PreventReaddDeleteTwoOptTabuMoveEvaluator.cs
r3104 r3221 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" PreventReaddDeleteTwoOptTabuMoveEvaluator", "Prevents readding of previously deleted edges as well as deleting previously added edges.")]31 [Item("TwoOptPreventEdgeRemovalAndReadding", "Prevents readding of previously deleted edges as well as deleting previously added edges.")] 32 32 [StorableClass] 33 33 public class PreventReaddDeleteTwoOptTabuMoveEvaluator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, ITabuMoveEvaluator { 34 public override bool CanChangeName { 35 get { return false; } 36 } 34 37 public ILookupParameter<TwoOptMove> TwoOptMoveParameter { 35 38 get { return (LookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; } … … 66 69 int E2S = permutation[move.Index2]; 67 70 int E2T = permutation.GetCircular(move.Index2 + 1); 68 bool isTabu = false; 69 foreach (IItem tabuMove in tabuList) { 70 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute); 71 if (attribute != null) { 72 // if previously deleted Edge1Source-Target is readded 73 if (attribute.Edge1Source == E1S && attribute.Edge1Target == E2S || attribute.Edge1Source == E2S && attribute.Edge1Target == E1S 74 || attribute.Edge1Source == E1T && attribute.Edge1Target == E2T || attribute.Edge1Source == E2T && attribute.Edge1Target == E1T 75 // if previously deleted Edge2Source-Target is readded 76 || attribute.Edge2Source == E1T && attribute.Edge2Target == E2T || attribute.Edge2Source == E2T && attribute.Edge2Target == E1T 77 || attribute.Edge2Source == E1S && attribute.Edge2Target == E2S || attribute.Edge2Source == E2S && attribute.Edge2Target == E1S 78 // if previously added Edge1Source-Edge2Source is deleted 79 || attribute.Edge1Source == E1S && attribute.Edge2Source == E1T || attribute.Edge1Source == E1T && attribute.Edge2Source == E1S 80 || attribute.Edge1Source == E2S && attribute.Edge2Source == E2T || attribute.Edge1Source == E2T && attribute.Edge2Source == E2S 81 // if previously added Edge1Target-Edge2Target is deleted 82 || attribute.Edge1Target == E2S && attribute.Edge2Target == E2T || attribute.Edge1Target == E2T && attribute.Edge2Target == E2S 83 || attribute.Edge1Target == E1S && attribute.Edge2Target == E1T || attribute.Edge1Target == E1T && attribute.Edge2Target == E1S) { 84 isTabu = true; 85 break; 71 bool isTabu = (move.Index2 - move.Index1 >= length - 2); // doesn't change the solution; 72 if (!isTabu) { 73 foreach (IItem tabuMove in tabuList) { 74 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute); 75 if (attribute != null) { 76 // if previously deleted Edge1Source-Target is readded 77 if (attribute.Edge1Source == E1S && attribute.Edge1Target == E2S || attribute.Edge1Source == E2S && attribute.Edge1Target == E1S 78 || attribute.Edge1Source == E1T && attribute.Edge1Target == E2T || attribute.Edge1Source == E2T && attribute.Edge1Target == E1T 79 // if previously deleted Edge2Source-Target is readded 80 || attribute.Edge2Source == E1T && attribute.Edge2Target == E2T || attribute.Edge2Source == E2T && attribute.Edge2Target == E1T 81 || attribute.Edge2Source == E1S && attribute.Edge2Target == E2S || attribute.Edge2Source == E2S && attribute.Edge2Target == E1S 82 // if previously added Edge1Source-Edge2Source is deleted 83 || attribute.Edge1Source == E1S && attribute.Edge2Source == E1T || attribute.Edge1Source == E1T && attribute.Edge2Source == E1S 84 || attribute.Edge1Source == E2S && attribute.Edge2Source == E2T || attribute.Edge1Source == E2T && attribute.Edge2Source == E2S 85 // if previously added Edge1Target-Edge2Target is deleted 86 || attribute.Edge1Target == E2S && attribute.Edge2Target == E2T || attribute.Edge1Target == E2T && attribute.Edge2Target == E2S 87 || attribute.Edge1Target == E1S && attribute.Edge2Target == E1T || attribute.Edge1Target == E1T && attribute.Edge2Target == E1S) { 88 isTabu = true; 89 break; 90 } 86 91 } 87 92 } … … 90 95 return base.Apply(); 91 96 } 92 93 public override bool CanChangeName {94 get { return false; }95 }96 97 } 97 98 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/PreventReaddTwoOptTabuMoveEvaluator.cs
r3104 r3221 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" PreventReaddTwoOptTabuMoveEvaluator", "Prevents readding of previously deleted edges, but allows deleting previously added edges.")]31 [Item("TwoOptPreventEdgeReadding", "Prevents readding of previously deleted edges, but allows deleting previously added edges.")] 32 32 [StorableClass] 33 33 public class PreventReaddTwoOptTabuMoveEvaluator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, ITabuMoveEvaluator { 34 public override bool CanChangeName { 35 get { return false; } 36 } 34 37 public ILookupParameter<TwoOptMove> TwoOptMoveParameter { 35 38 get { return (LookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; } … … 66 69 int E2S = permutation[move.Index2]; 67 70 int E2T = permutation.GetCircular(move.Index2 + 1); 68 bool isTabu = false; 69 foreach (IItem tabuMove in tabuList) { 70 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute); 71 if (attribute != null) { 72 // if previously deleted Edge1Source-Target is readded 73 if (attribute.Edge1Source == E1S && attribute.Edge1Target == E2S || attribute.Edge1Source == E2S && attribute.Edge1Target == E1S 74 || attribute.Edge1Source == E1T && attribute.Edge1Target == E2T || attribute.Edge1Source == E2T && attribute.Edge1Target == E1T 75 // if previously deleted Edge2Source-Target is readded 76 || attribute.Edge2Source == E1T && attribute.Edge2Target == E2T || attribute.Edge2Source == E2T && attribute.Edge2Target == E1T 77 || attribute.Edge2Source == E1S && attribute.Edge2Target == E2S || attribute.Edge2Source == E2S && attribute.Edge2Target == E1S) { 78 isTabu = true; 79 break; 71 bool isTabu = (move.Index2 - move.Index1 >= length - 2); // doesn't change the solution; 72 if (!isTabu) { 73 foreach (IItem tabuMove in tabuList) { 74 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute); 75 if (attribute != null) { 76 // if previously deleted Edge1Source-Target is readded 77 if (attribute.Edge1Source == E1S && attribute.Edge1Target == E2S || attribute.Edge1Source == E2S && attribute.Edge1Target == E1S 78 || attribute.Edge1Source == E1T && attribute.Edge1Target == E2T || attribute.Edge1Source == E2T && attribute.Edge1Target == E1T 79 // if previously deleted Edge2Source-Target is readded 80 || attribute.Edge2Source == E1T && attribute.Edge2Target == E2T || attribute.Edge2Source == E2T && attribute.Edge2Target == E1T 81 || attribute.Edge2Source == E1S && attribute.Edge2Target == E2S || attribute.Edge2Source == E2S && attribute.Edge2Target == E1S) { 82 isTabu = true; 83 break; 84 } 80 85 } 81 86 } … … 84 89 return base.Apply(); 85 90 } 86 87 public override bool CanChangeName {88 get { return false; }89 }90 91 } 91 92 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticTwoOptMultiMoveGenerator.cs
r3101 r3221 28 28 29 29 namespace HeuristicLab.Encodings.PermutationEncoding { 30 [Item("StochasticTwoOptMultiMoveGenerator", "Randomly samples n from all possible 2-opt moves from a given permutation.")]30 [Item("StochasticTwoOptMultiMoveGenerator", "Randomly samples n from all possible 2-opt moves (inversion) from a given permutation.")] 31 31 [StorableClass] 32 public class StochasticTwoOptMultiMoveGenerator : StochasticTwoOptSingleMoveGenerator, IMultiMoveGenerator { 32 public class StochasticTwoOptMultiMoveGenerator : TwoOptMoveGenerator, IMultiMoveGenerator, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 35 } 33 36 public IValueLookupParameter<IntValue> SampleSizeParameter { 34 37 get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; } … … 42 45 public StochasticTwoOptMultiMoveGenerator() 43 46 : base() { 47 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); 44 48 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate.")); 45 49 } … … 49 53 TwoOptMove[] moves = new TwoOptMove[sampleSize]; 50 54 for (int i = 0; i < sampleSize; i++) { 51 moves[i] = Apply(permutation, random);55 moves[i] = StochasticTwoOptSingleMoveGenerator.Apply(permutation, random); 52 56 } 53 57 return moves; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticTwoOptSingleMoveGenerator.cs
r3098 r3221 28 28 29 29 namespace HeuristicLab.Encodings.PermutationEncoding { 30 [Item("StochasticTwoOptSingleMoveGenerator", "Randomly samples a single from all possible 2-opt moves from a given permutation.")]30 [Item("StochasticTwoOptSingleMoveGenerator", "Randomly samples a single from all possible 2-opt moves (inversion) from a given permutation.")] 31 31 [StorableClass] 32 32 public class StochasticTwoOptSingleMoveGenerator : TwoOptMoveGenerator, IStochasticOperator, ISingleMoveGenerator { … … 42 42 public static TwoOptMove Apply(Permutation permutation, IRandom random) { 43 43 int length = permutation.Length; 44 int index1 = random.Next(length - 1), index2; 45 if (index1 >= 2) 46 index2 = random.Next(index1 + 1, length); 47 else index2 = random.Next(index1 + 1, length - (2 - index1)); 44 int index1 = random.Next(length - 1); 45 int index2 = random.Next(index1 + 1, length); 48 46 return new TwoOptMove(index1, index2);; 49 47 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveGenerator.cs
r3074 r3221 31 31 [StorableClass] 32 32 public abstract class TwoOptMoveGenerator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveGenerator { 33 public override bool CanChangeName { 34 get { return false; } 35 } 33 36 public ILookupParameter<Permutation> PermutationParameter { 34 37 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } … … 61 64 62 65 protected abstract TwoOptMove[] GenerateMoves(Permutation permutation); 63 64 public override bool CanChangeName {65 get { return false; }66 }67 66 } 68 67 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveMaker.cs
r3074 r3221 32 32 [StorableClass] 33 33 public class TwoOptMoveMaker : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveMaker { 34 public override bool CanChangeName { 35 get { return false; } 36 } 34 37 public ILookupParameter<DoubleValue> QualityParameter { 35 38 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } … … 64 67 return base.Apply(); 65 68 } 66 67 public override bool CanChangeName {68 get { return false; }69 }70 69 } 71 70 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptTabuMoveMaker.cs
r3104 r3221 32 32 [StorableClass] 33 33 public class TwoOptTabuMoveMaker : TabuMoveMaker, ITwoOptPermutationMoveOperator { 34 public override bool CanChangeName { 35 get { return false; } 36 } 34 37 public ILookupParameter<Permutation> PermutationParameter { 35 38 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } … … 53 56 permutation.GetCircular(move.Index2 + 1)); 54 57 } 55 56 public override bool CanChangeName {57 get { return false; }58 }59 58 } 60 59 }
Note: See TracChangeset
for help on using the changeset viewer.