- Timestamp:
- 03/29/10 18:49:55 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt
- Files:
-
- 11 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/ExhaustiveInversionMoveGenerator.cs
r3229 r3232 26 26 27 27 namespace HeuristicLab.Encodings.PermutationEncoding { 28 [Item("Exhaustive TwoOptMoveGenerator", "Generates all possible 2-opt moves (inversion) from a given permutation.")]28 [Item("ExhaustiveInversionMoveGenerator", "Generates all possible inversion moves (2-opt) from a given permutation.")] 29 29 [StorableClass] 30 public class Exhaustive TwoOptMoveGenerator : TwoOptMoveGenerator, IExhaustiveMoveGenerator {31 public static TwoOptMove[] Apply(Permutation permutation) {30 public class ExhaustiveInversionMoveGenerator : InversionMoveGenerator, IExhaustiveMoveGenerator { 31 public static InversionMove[] Apply(Permutation permutation) { 32 32 int length = permutation.Length; 33 33 int totalMoves = (length) * (length - 1) / 2; // - 3; 34 TwoOptMove[] moves = new TwoOptMove[totalMoves];34 InversionMove[] moves = new InversionMove[totalMoves]; 35 35 int count = 0; 36 36 for (int i = 0; i < length - 1; i++) … … 39 39 /*if (i == 0 && j >= length - 2) continue; 40 40 else if (i == 1 && j >= length - 1) continue;*/ 41 moves[count++] = new TwoOptMove(i, j);41 moves[count++] = new InversionMove(i, j); 42 42 } 43 43 return moves; 44 44 } 45 45 46 protected override TwoOptMove[] GenerateMoves(Permutation permutation) {46 protected override InversionMove[] GenerateMoves(Permutation permutation) { 47 47 return Apply(permutation); 48 48 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMove.cs
r3229 r3232 24 24 25 25 namespace HeuristicLab.Encodings.PermutationEncoding { 26 [Item(" TwoOptMove", "Item that describes a 2-Opt move.")]26 [Item("InversionMove", "Item that describes an inversion move (2-opt).")] 27 27 [StorableClass] 28 public class TwoOptMove : TwoIndexMove {29 public TwoOptMove()28 public class InversionMove : TwoIndexMove { 29 public InversionMove() 30 30 : base() { 31 31 } 32 32 33 public TwoOptMove(int index1, int index2)33 public InversionMove(int index1, int index2) 34 34 : base(index1, index2, null) { 35 35 } 36 36 37 public TwoOptMove(int index1, int index2, Permutation permutation)37 public InversionMove(int index1, int index2, Permutation permutation) 38 38 : base(index1, index2, permutation) { 39 39 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveAttribute.cs
r3229 r3232 24 24 25 25 namespace HeuristicLab.Encodings.PermutationEncoding { 26 [Item(" TwoOptTabuMoveAttribute", "Specifies the tabu attributes for a 2-opt move.")]26 [Item("InversionMoveAttribute", "Specifies the tabu attributes for an inversion move (2-opt).")] 27 27 [StorableClass] 28 public class TwoOptTabuMoveAttribute : Item {28 public class InversionMoveAttribute : Item { 29 29 [Storable] 30 30 public int Edge1Source { get; private set; } … … 37 37 38 38 [StorableConstructor] 39 private TwoOptTabuMoveAttribute(bool deserializing)39 private InversionMoveAttribute(bool deserializing) 40 40 : base() { 41 41 } 42 42 43 public TwoOptTabuMoveAttribute()43 public InversionMoveAttribute() 44 44 : this(-1, -1, -1, -1) { } 45 45 46 public TwoOptTabuMoveAttribute(int edge1Source, int edge1Target, int edge2Source, int edge2Target)46 public InversionMoveAttribute(int edge1Source, int edge1Target, int edge2Source, int edge2Target) 47 47 : base() { 48 48 Edge1Source = edge1Source; … … 53 53 54 54 public override IDeepCloneable Clone(Cloner cloner) { 55 TwoOptTabuMoveAttribute clone = (TwoOptTabuMoveAttribute)base.Clone(cloner);55 InversionMoveAttribute clone = (InversionMoveAttribute)base.Clone(cloner); 56 56 clone.Edge1Source = Edge1Source; 57 57 clone.Edge1Target = Edge1Target; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveGenerator.cs
r3229 r3232 28 28 29 29 namespace HeuristicLab.Encodings.PermutationEncoding { 30 [Item(" TwoOptMoveGenerator", "Base class for all 2-optmove generators.")]30 [Item("InversionMoveGenerator", "Base class for all inversion (2-opt) move generators.")] 31 31 [StorableClass] 32 public abstract class TwoOptMoveGenerator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveGenerator {32 public abstract class InversionMoveGenerator : SingleSuccessorOperator, IPermutationInversionMoveOperator, IMoveGenerator { 33 33 public override bool CanChangeName { 34 34 get { return false; } … … 37 37 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 38 38 } 39 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {40 get { return (LookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }39 public ILookupParameter<InversionMove> InversionMoveParameter { 40 get { return (LookupParameter<InversionMove>)Parameters["InversionMove"]; } 41 41 } 42 42 protected ScopeParameter CurrentScopeParameter { … … 44 44 } 45 45 46 public TwoOptMoveGenerator()46 public InversionMoveGenerator() 47 47 : base() { 48 48 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation for which moves should be generated.")); 49 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The moves that should be generated in subscopes."));49 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The moves that should be generated in subscopes.")); 50 50 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 51 51 } … … 53 53 public override IOperation Apply() { 54 54 Permutation p = PermutationParameter.ActualValue; 55 TwoOptMove[] moves = GenerateMoves(p);55 InversionMove[] moves = GenerateMoves(p); 56 56 Scope[] moveScopes = new Scope[moves.Length]; 57 57 for (int i = 0; i < moveScopes.Length; i++) { 58 58 moveScopes[i] = new Scope(i.ToString()); 59 moveScopes[i].Variables.Add(new Variable( TwoOptMoveParameter.ActualName, moves[i]));59 moveScopes[i].Variables.Add(new Variable(InversionMoveParameter.ActualName, moves[i])); 60 60 } 61 61 CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes); … … 63 63 } 64 64 65 protected abstract TwoOptMove[] GenerateMoves(Permutation permutation);65 protected abstract InversionMove[] GenerateMoves(Permutation permutation); 66 66 } 67 67 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveMaker.cs
r3229 r3232 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" TwoOptMoveMaker", "Peforms a 2-opt moveon a given permutation and updates the quality.")]31 [Item("InversionMoveMaker", "Peforms an inversion move (2-opt) on a given permutation and updates the quality.")] 32 32 [StorableClass] 33 public class TwoOptMoveMaker : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveMaker {33 public class InversionMoveMaker : SingleSuccessorOperator, IPermutationInversionMoveOperator, IMoveMaker { 34 34 public override bool CanChangeName { 35 35 get { return false; } … … 41 41 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 42 42 } 43 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {44 get { return (ILookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }43 public ILookupParameter<InversionMove> InversionMoveParameter { 44 get { return (ILookupParameter<InversionMove>)Parameters["InversionMove"]; } 45 45 } 46 46 public ILookupParameter<Permutation> PermutationParameter { … … 48 48 } 49 49 50 public TwoOptMoveMaker()50 public InversionMoveMaker() 51 51 : base() { 52 52 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 53 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The move to evaluate."));53 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move to evaluate.")); 54 54 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 55 55 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); … … 57 57 58 58 public override IOperation Apply() { 59 TwoOptMove move = TwoOptMoveParameter.ActualValue;59 InversionMove move = InversionMoveParameter.ActualValue; 60 60 Permutation permutation = PermutationParameter.ActualValue; 61 61 DoubleValue moveQuality = MoveQualityParameter.ActualValue; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveTabuMaker.cs
r3229 r3232 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" TwoOptTabuMoveMaker", "Declares a given 2-opt move as tabu, by adding its attributes to the tabu list. It also removes the oldest entry in the tabu list when its size is greater than tenure.")]31 [Item("InversionMoveTabuMaker", "Declares a given inversion move (2-opt) as tabu, by adding its attributes to the tabu list.")] 32 32 [StorableClass] 33 public class TwoOptTabuMoveMaker : TabuMoveMaker, ITwoOptPermutationMoveOperator {33 public class InversionMoveTabuMaker : TabuMaker, IPermutationInversionMoveOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } … … 38 38 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 39 39 } 40 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {41 get { return (LookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }40 public ILookupParameter<InversionMove> InversionMoveParameter { 41 get { return (LookupParameter<InversionMove>)Parameters["InversionMove"]; } 42 42 } 43 43 44 public TwoOptTabuMoveMaker()44 public InversionMoveTabuMaker() 45 45 : base() { 46 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The move that was made."));46 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move that was made.")); 47 47 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); 48 48 } 49 49 50 50 protected override IItem GetTabuAttribute() { 51 TwoOptMove move = TwoOptMoveParameter.ActualValue;51 InversionMove move = InversionMoveParameter.ActualValue; 52 52 Permutation permutation = PermutationParameter.ActualValue; 53 return new TwoOptTabuMoveAttribute( permutation.GetCircular(move.Index1 - 1),53 return new InversionMoveAttribute( permutation.GetCircular(move.Index1 - 1), 54 54 permutation[move.Index1], 55 55 permutation[move.Index2], -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/PreventReaddAndRemovalInversionMoveTabuChecker.cs
r3229 r3232 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" TwoOptPreventEdgeRemovalAndReadding", "Prevents readding of previously deleted edges as well as deleting previously added edges.")]31 [Item("PreventReaddAndRemovalInversionMoveTabuChecker", "Prevents readding of previously deleted edges as well as deleting previously added edges.")] 32 32 [StorableClass] 33 public class PreventReadd DeleteTwoOptTabuMoveEvaluator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, ITabuMoveEvaluator {33 public class PreventReaddAndRemovalInversionMoveTabuChecker : SingleSuccessorOperator, IPermutationInversionMoveOperator, ITabuChecker { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {38 get { return (LookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }37 public ILookupParameter<InversionMove> InversionMoveParameter { 38 get { return (LookupParameter<InversionMove>)Parameters["InversionMove"]; } 39 39 } 40 40 public ILookupParameter<Permutation> PermutationParameter { … … 51 51 } 52 52 53 public PreventReadd DeleteTwoOptTabuMoveEvaluator()53 public PreventReaddAndRemovalInversionMoveTabuChecker() 54 54 : base() { 55 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The move to evaluate."));55 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move to evaluate.")); 56 56 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); 57 57 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); … … 62 62 public override IOperation Apply() { 63 63 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 64 TwoOptMove move = TwoOptMoveParameter.ActualValue;64 InversionMove move = InversionMoveParameter.ActualValue; 65 65 Permutation permutation = PermutationParameter.ActualValue; 66 66 int length = permutation.Length; … … 72 72 if (!isTabu) { 73 73 foreach (IItem tabuMove in tabuList) { 74 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute);74 InversionMoveAttribute attribute = (tabuMove as InversionMoveAttribute); 75 75 if (attribute != null) { 76 76 // if previously deleted Edge1Source-Target is readded -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/PreventReaddInversionMoveTabuChecker.cs
r3229 r3232 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" TwoOptPreventEdgeReadding", "Prevents readding of previously deleted edges, but allows deleting previously added edges.")]31 [Item("PreventReaddInversionMoveTabuChecker", "Prevents readding of previously deleted edges, but allows deleting previously added edges.")] 32 32 [StorableClass] 33 public class PreventReadd TwoOptTabuMoveEvaluator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, ITabuMoveEvaluator {33 public class PreventReaddInversionMoveTabuChecker : SingleSuccessorOperator, IPermutationInversionMoveOperator, ITabuChecker { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {38 get { return (LookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }37 public ILookupParameter<InversionMove> InversionMoveParameter { 38 get { return (LookupParameter<InversionMove>)Parameters["InversionMove"]; } 39 39 } 40 40 public ILookupParameter<Permutation> PermutationParameter { … … 51 51 } 52 52 53 public PreventReadd TwoOptTabuMoveEvaluator()53 public PreventReaddInversionMoveTabuChecker() 54 54 : base() { 55 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The move to evaluate."));55 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move to evaluate.")); 56 56 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); 57 57 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); … … 62 62 public override IOperation Apply() { 63 63 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 64 TwoOptMove move = TwoOptMoveParameter.ActualValue;64 InversionMove move = InversionMoveParameter.ActualValue; 65 65 Permutation permutation = PermutationParameter.ActualValue; 66 66 int length = permutation.Length; … … 72 72 if (!isTabu) { 73 73 foreach (IItem tabuMove in tabuList) { 74 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute);74 InversionMoveAttribute attribute = (tabuMove as InversionMoveAttribute); 75 75 if (attribute != null) { 76 76 // if previously deleted Edge1Source-Target is readded -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/PreventRemovalInversionMoveTabuChecker.cs
r3229 r3232 29 29 30 30 namespace HeuristicLab.Encodings.PermutationEncoding { 31 [Item(" TwoOptPreventEdgeRemoval", "Prevents deleting of previously added edges.")]31 [Item("PreventRemovalInversionMoveTabuChecker", "Prevents deleting of previously added edges.")] 32 32 [StorableClass] 33 public class Prevent DeleteTwoOptTabuMoveEvaluator : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, ITabuMoveEvaluator {33 public class PreventRemovalInversionMoveTabuChecker : SingleSuccessorOperator, IPermutationInversionMoveOperator, ITabuChecker { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 public ILookupParameter< TwoOptMove> TwoOptMoveParameter {38 get { return (LookupParameter< TwoOptMove>)Parameters["TwoOptMove"]; }37 public ILookupParameter<InversionMove> InversionMoveParameter { 38 get { return (LookupParameter<InversionMove>)Parameters["InversionMove"]; } 39 39 } 40 40 public ILookupParameter<Permutation> PermutationParameter { … … 51 51 } 52 52 53 public Prevent DeleteTwoOptTabuMoveEvaluator()53 public PreventRemovalInversionMoveTabuChecker() 54 54 : base() { 55 Parameters.Add(new LookupParameter< TwoOptMove>("TwoOptMove", "The move to evaluate."));55 Parameters.Add(new LookupParameter<InversionMove>("InversionMove", "The move to evaluate.")); 56 56 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); 57 57 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); … … 62 62 public override IOperation Apply() { 63 63 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 64 TwoOptMove move = TwoOptMoveParameter.ActualValue;64 InversionMove move = InversionMoveParameter.ActualValue; 65 65 Permutation permutation = PermutationParameter.ActualValue; 66 66 int length = permutation.Length; … … 72 72 if (!isTabu) { 73 73 foreach (IItem tabuMove in tabuList) { 74 TwoOptTabuMoveAttribute attribute = (tabuMove as TwoOptTabuMoveAttribute);74 InversionMoveAttribute attribute = (tabuMove as InversionMoveAttribute); 75 75 if (attribute != null) { 76 76 // if previously added Edge1Source-Edge2Source is deleted -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticInversionMultiMoveGenerator.cs
r3229 r3232 28 28 29 29 namespace HeuristicLab.Encodings.PermutationEncoding { 30 [Item("Stochastic TwoOptMultiMoveGenerator", "Randomly samples n from all possible 2-opt moves (inversion) from a given permutation.")]30 [Item("StochasticInversionMultiMoveGenerator", "Randomly samples n from all possible inversion moves (2-opt) from a given permutation.")] 31 31 [StorableClass] 32 public class Stochastic TwoOptMultiMoveGenerator : TwoOptMoveGenerator, IMultiMoveGenerator, IStochasticOperator {32 public class StochasticInversionMultiMoveGenerator : InversionMoveGenerator, IMultiMoveGenerator, IStochasticOperator { 33 33 public ILookupParameter<IRandom> RandomParameter { 34 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 43 43 } 44 44 45 public Stochastic TwoOptMultiMoveGenerator()45 public StochasticInversionMultiMoveGenerator() 46 46 : base() { 47 47 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); … … 49 49 } 50 50 51 public static TwoOptMove[] Apply(Permutation permutation, IRandom random, int sampleSize) {51 public static InversionMove[] Apply(Permutation permutation, IRandom random, int sampleSize) { 52 52 int length = permutation.Length; 53 TwoOptMove[] moves = new TwoOptMove[sampleSize];53 InversionMove[] moves = new InversionMove[sampleSize]; 54 54 for (int i = 0; i < sampleSize; i++) { 55 moves[i] = Stochastic TwoOptSingleMoveGenerator.Apply(permutation, random);55 moves[i] = StochasticInversionSingleMoveGenerator.Apply(permutation, random); 56 56 } 57 57 return moves; 58 58 } 59 59 60 protected override TwoOptMove[] GenerateMoves(Permutation permutation) {60 protected override InversionMove[] GenerateMoves(Permutation permutation) { 61 61 IRandom random = RandomParameter.ActualValue; 62 62 return Apply(permutation, random, SampleSizeParameter.ActualValue.Value); -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticInversionSingleMoveGenerator.cs
r3229 r3232 28 28 29 29 namespace HeuristicLab.Encodings.PermutationEncoding { 30 [Item("Stochastic TwoOptSingleMoveGenerator", "Randomly samples a single from all possible 2-opt moves (inversion) from a given permutation.")]30 [Item("StochasticInversionSingleMoveGenerator", "Randomly samples a single from all possible inversion moves (2-opt) from a given permutation.")] 31 31 [StorableClass] 32 public class Stochastic TwoOptSingleMoveGenerator : TwoOptMoveGenerator, IStochasticOperator, ISingleMoveGenerator {32 public class StochasticInversionSingleMoveGenerator : InversionMoveGenerator, IStochasticOperator, ISingleMoveGenerator { 33 33 public ILookupParameter<IRandom> RandomParameter { 34 34 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 35 35 } 36 36 37 public Stochastic TwoOptSingleMoveGenerator()37 public StochasticInversionSingleMoveGenerator() 38 38 : base() { 39 39 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator.")); 40 40 } 41 41 42 public static TwoOptMove Apply(Permutation permutation, IRandom random) {42 public static InversionMove Apply(Permutation permutation, IRandom random) { 43 43 int length = permutation.Length; 44 44 int index1 = random.Next(length - 1); 45 45 int index2 = random.Next(index1 + 1, length); 46 return new TwoOptMove(index1, index2);;46 return new InversionMove(index1, index2);; 47 47 } 48 48 49 protected override TwoOptMove[] GenerateMoves(Permutation permutation) {49 protected override InversionMove[] GenerateMoves(Permutation permutation) { 50 50 IRandom random = RandomParameter.ActualValue; 51 return new TwoOptMove[] { Apply(permutation, random) };51 return new InversionMove[] { Apply(permutation, random) }; 52 52 } 53 53 }
Note: See TracChangeset
for help on using the changeset viewer.