Changeset 8887 for trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition
- Timestamp:
- 11/11/12 22:57:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/Crossovers/PWRCrossover.cs
r8603 r8887 27 27 [Item("PWRCrossover", "An operator which crosses two JSM representations.")] 28 28 [StorableClass] 29 public abstract class PWRCrossover : ScheduleCrossover <PWREncoding>, IPWROperator {29 public abstract class PWRCrossover : ScheduleCrossover, IPWROperator { 30 30 31 31 [StorableConstructor] … … 41 41 42 42 public override IOperation Apply() { 43 ItemArray<PWREncoding>parents = ParentsParameter.ActualValue;43 var parents = ParentsParameter.ActualValue; 44 44 45 45 ChildParameter.ActualValue = -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/Crossovers/PWRGOXCrossover.cs
r8603 r8887 31 31 [StorableClass] 32 32 public class PWRGOXCrossover : PWRCrossover { 33 33 34 [StorableConstructor] 34 35 protected PWRGOXCrossover(bool deserializing) : base(deserializing) { } 35 protected PWRGOXCrossover(PWRGOXCrossover original, Cloner cloner) 36 : base(original, cloner) {37 } 36 protected PWRGOXCrossover(PWRGOXCrossover original, Cloner cloner) : base(original, cloner) { } 37 public PWRGOXCrossover() : base() { } 38 38 39 public override IDeepCloneable Clone(Cloner cloner) { 39 40 return new PWRGOXCrossover(this, cloner); 40 41 } 41 public PWRGOXCrossover() : base() { }42 42 43 43 private static int[] GetLookUpForIndividual(List<int> p) { 44 int[]result = new int[p.Count];45 Dictionary<int, int>lookUpTable = new Dictionary<int, int>();44 var result = new int[p.Count]; 45 var lookUpTable = new Dictionary<int, int>(); 46 46 47 47 for (int i = 0; i < p.Count; i++) { … … 54 54 return result; 55 55 } 56 56 57 public static PWREncoding Apply(IRandom random, PWREncoding parent1, PWREncoding parent2) { 57 PWREncodingresult = new PWREncoding();58 var result = new PWREncoding(); 58 59 59 List<int> p1 = ((IntegerVector)(parent1.PermutationWithRepetition.Clone())).ToList<int>();60 List<int> p2 = ((IntegerVector)(parent2.PermutationWithRepetition.Clone())).ToList<int>();61 List<int>child = new List<int>();60 var p1 = ((IntegerVector)(parent1.PermutationWithRepetition.Clone())).ToList(); 61 var p2 = ((IntegerVector)(parent2.PermutationWithRepetition.Clone())).ToList(); 62 var child = new List<int>(); 62 63 63 64 int[] lookUpArrayP1 = GetLookUpForIndividual(p1); … … 90 91 } 91 92 92 93 94 95 93 } 96 94 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/Crossovers/PWRPPXCrossover.cs
r8603 r8887 31 31 [StorableClass] 32 32 public class PWRPPXCrossover : PWRCrossover { 33 33 34 [StorableConstructor] 34 35 protected PWRPPXCrossover(bool deserializing) : base(deserializing) { } 35 protected PWRPPXCrossover(PWRPPXCrossover original, Cloner cloner) 36 : base(original, cloner) {37 } 36 protected PWRPPXCrossover(PWRPPXCrossover original, Cloner cloner) : base(original, cloner) { } 37 public PWRPPXCrossover() : base() { } 38 38 39 public override IDeepCloneable Clone(Cloner cloner) { 39 40 return new PWRPPXCrossover(this, cloner); 40 41 } 41 public PWRPPXCrossover() : base() { }42 42 43 43 public static PWREncoding Apply(IRandom random, PWREncoding parent1, PWREncoding parent2) { 44 PWREncodingresult = new PWREncoding();45 List<int> p1 = ((IntegerVector)(parent1.PermutationWithRepetition.Clone())).ToList<int>();46 List<int> p2 = ((IntegerVector)(parent2.PermutationWithRepetition.Clone())).ToList<int>();47 List<int>child = new List<int>();44 var result = new PWREncoding(); 45 var p1 = ((IntegerVector)(parent1.PermutationWithRepetition.Clone())).ToList(); 46 var p2 = ((IntegerVector)(parent2.PermutationWithRepetition.Clone())).ToList(); 47 var child = new List<int>(); 48 48 49 bool[]lookUpTable = new bool[parent1.PermutationWithRepetition.Length];49 var lookUpTable = new bool[parent1.PermutationWithRepetition.Length]; 50 50 for (int i = 0; i < lookUpTable.Length; i++) { 51 51 lookUpTable[i] = random.Next(2) == 1; … … 73 73 } 74 74 75 76 75 } 77 76 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/Manipulators/PWRInsertionManipulator.cs
r8603 r8887 28 28 29 29 namespace HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition { 30 31 30 [Item("PWRInsertionManipulator", "Represents a manipulation operation inserting parts of the individual at another position.")] 32 31 [StorableClass] … … 34 33 [StorableConstructor] 35 34 protected PWRInsertionManipulator(bool deserializing) : base(deserializing) { } 36 protected PWRInsertionManipulator(PWRInsertionManipulator original, Cloner cloner) 37 : base(original, cloner) {38 } 35 protected PWRInsertionManipulator(PWRInsertionManipulator original, Cloner cloner) : base(original, cloner) { } 36 public PWRInsertionManipulator() : base() { } 37 39 38 public override IDeepCloneable Clone(Cloner cloner) { 40 39 return new PWRInsertionManipulator(this, cloner); 41 40 } 42 public PWRInsertionManipulator() : base() { }43 41 44 42 public static void Apply(IRandom random, PWREncoding individual) { -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/Manipulators/PWRManipulator.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 [Item("PWRManipulator", "An operator which manipulates a PWR representation.")] 28 29 [StorableClass] 29 public abstract class PWRManipulator : ScheduleManipulator<PWREncoding>, IPWROperator { 30 public abstract class PWRManipulator : ScheduleManipulator, IPWROperator { 31 30 32 [StorableConstructor] 31 33 protected PWRManipulator(bool deserializing) : base(deserializing) { } … … 38 40 protected abstract void Manipulate(IRandom random, PWREncoding individual); 39 41 40 41 42 public override IOperation Apply() { 42 PWREncoding solution = ScheduleEncodingParameter.ActualValue; 43 var solution = ScheduleEncodingParameter.ActualValue as PWREncoding; 44 if (solution == null) throw new InvalidOperationException("ScheduleEncoding was not found or is not of type PWREncoding."); 43 45 Manipulate(RandomParameter.ActualValue, solution); 44 46 return base.Apply(); -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/PWREncoding.cs
r8603 r8887 30 30 [StorableClass] 31 31 public class PWREncoding : Item, IScheduleEncoding { 32 32 33 [Storable] 33 34 public IntegerVector PermutationWithRepetition { get; set; } 34 35 35 36 36 [StorableConstructor] … … 40 40 this.PermutationWithRepetition = cloner.Clone(original.PermutationWithRepetition); 41 41 } 42 public override IDeepCloneable Clone(Cloner cloner) {43 return new PWREncoding(this, cloner);44 }45 42 public PWREncoding() 46 43 : base() { 47 44 PermutationWithRepetition = new IntegerVector(); 45 } 46 47 public override IDeepCloneable Clone(Cloner cloner) { 48 return new PWREncoding(this, cloner); 48 49 } 49 50 … … 81 82 return base.Equals(obj); 82 83 } 84 83 85 public override int GetHashCode() { 84 86 if (PermutationWithRepetition.Length == 1) … … 88 90 return 0; 89 91 } 92 90 93 private bool AreEqual(PWREncoding pWREncoding1, PWREncoding pWREncoding2) { 91 94 if (pWREncoding1.PermutationWithRepetition.Length != pWREncoding2.PermutationWithRepetition.Length) … … 97 100 return true; 98 101 } 99 100 101 102 } 102 103 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/PWRRandomCreator.cs
r8603 r8887 30 30 [Item("PermutationWithRepetitionRandomCreator", "Creates PWR-individuals at random.")] 31 31 [StorableClass] 32 public class PWRRandomCreator : ScheduleCreator<PWREncoding>, IStochasticOperator { 33 public IRandom Random { 34 get { return RandomParameter.ActualValue; } 35 } 32 public class PWRRandomCreator : ScheduleCreator, IStochasticOperator { 36 33 37 34 public ILookupParameter<IRandom> RandomParameter { … … 47 44 [StorableConstructor] 48 45 protected PWRRandomCreator(bool deserializing) : base(deserializing) { } 49 protected PWRRandomCreator(PWRRandomCreator original, Cloner cloner) 50 : base(original, cloner) { 51 } 52 public override IDeepCloneable Clone(Cloner cloner) { 53 return new PWRRandomCreator(this, cloner); 54 } 55 46 protected PWRRandomCreator(PWRRandomCreator original, Cloner cloner) : base(original, cloner) { } 56 47 public PWRRandomCreator() 57 48 : base() { … … 63 54 } 64 55 56 public override IDeepCloneable Clone(Cloner cloner) { 57 return new PWRRandomCreator(this, cloner); 58 } 59 65 60 public static PWREncoding Apply(int jobs, int resources, IRandom random) { 66 61 return new PWREncoding(jobs, resources, random); 67 62 } 68 63 69 70 protected override PWREncoding CreateSolution() { 71 return Apply(JobsParameter.ActualValue.Value, ResourcesParameter.ActualValue.Value, Random); 64 protected override IScheduleEncoding CreateSolution() { 65 return Apply(JobsParameter.ActualValue.Value, ResourcesParameter.ActualValue.Value, RandomParameter.ActualValue); 72 66 } 73 67 }
Note: See TracChangeset
for help on using the changeset viewer.