- Timestamp:
- 11/11/12 22:57:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Crossovers/JSMCrossover.cs
r8603 r8887 27 27 [Item("JSMCrossover", "An operator which crosses two JSM representations.")] 28 28 [StorableClass] 29 public abstract class JSMCrossover : ScheduleCrossover <JSMEncoding>, IJSMOperator {29 public abstract class JSMCrossover : ScheduleCrossover, IJSMOperator { 30 30 31 31 [StorableConstructor] … … 41 41 42 42 public override IOperation Apply() { 43 ItemArray<JSMEncoding>parents = ParentsParameter.ActualValue;43 var parents = ParentsParameter.ActualValue; 44 44 45 45 ChildParameter.ActualValue = -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Crossovers/JSMJOXCrossover.cs
r8603 r8887 30 30 [StorableClass] 31 31 public class JSMJOXCrossover : JSMCrossover { 32 32 33 [StorableConstructor] 33 34 protected JSMJOXCrossover(bool deserializing) : base(deserializing) { } 34 protected JSMJOXCrossover(JSMJOXCrossover original, Cloner cloner) 35 : base(original, cloner) {36 } 35 protected JSMJOXCrossover(JSMJOXCrossover original, Cloner cloner) : base(original, cloner) { } 36 public JSMJOXCrossover() : base() { } 37 37 38 public override IDeepCloneable Clone(Cloner cloner) { 38 39 return new JSMJOXCrossover(this, cloner); 39 40 } 40 public JSMJOXCrossover() : base() { }41 42 41 43 42 public static JSMEncoding Apply(IRandom random, JSMEncoding p1, JSMEncoding p2) { 44 JSMEncodingresult = new JSMEncoding();43 var result = new JSMEncoding(); 45 44 46 45 int nrOfResources = p1.JobSequenceMatrix.Count; … … 48 47 49 48 //Determine randomly which jobindexes persist 50 BoolArraypersist = new BoolArray(nrOfJobs);49 var persist = new BoolArray(nrOfJobs); 51 50 for (int i = 0; i < persist.Length; i++) { 52 51 persist[i] = random.Next(2) == 1; -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Crossovers/JSMOXCrossover.cs
r8603 r8887 28 28 [StorableClass] 29 29 public class JSMOXCrossover : JSMCrossover { 30 30 31 [StorableConstructor] 31 32 protected JSMOXCrossover(bool deserializing) : base(deserializing) { } 32 protected JSMOXCrossover(JSMOXCrossover original, Cloner cloner) 33 : base(original, cloner) {34 } 33 protected JSMOXCrossover(JSMOXCrossover original, Cloner cloner) : base(original, cloner) { } 34 public JSMOXCrossover() : base() { } 35 35 36 public override IDeepCloneable Clone(Cloner cloner) { 36 37 return new JSMOXCrossover(this, cloner); 37 38 } 38 public JSMOXCrossover() : base() { }39 40 39 41 40 public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 42 JSMEncodingresult = new JSMEncoding();41 var result = new JSMEncoding(); 43 42 44 43 for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) { -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Crossovers/JSMSXXCrossover.cs
r8603 r8887 29 29 [StorableClass] 30 30 public class JSMSXXCrossover : JSMCrossover { 31 31 32 [StorableConstructor] 32 33 protected JSMSXXCrossover(bool deserializing) : base(deserializing) { } 33 protected JSMSXXCrossover(JSMSXXCrossover original, Cloner cloner) 34 : base(original, cloner) {35 } 34 protected JSMSXXCrossover(JSMSXXCrossover original, Cloner cloner) : base(original, cloner) { } 35 public JSMSXXCrossover() : base() { } 36 36 37 public override IDeepCloneable Clone(Cloner cloner) { 37 38 return new JSMSXXCrossover(this, cloner); 38 39 } 39 public JSMSXXCrossover() : base() { }40 41 40 42 41 public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 43 JSMEncodingresult = new JSMEncoding();42 var result = new JSMEncoding(); 44 43 int subSequenceLength = random.Next(parent1.JobSequenceMatrix[0].Length); 45 44 for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) { 46 Permutationp1 = (Permutation)parent1.JobSequenceMatrix[i].Clone();47 Permutationp2 = (Permutation)parent2.JobSequenceMatrix[i].Clone();45 var p1 = (Permutation)parent1.JobSequenceMatrix[i].Clone(); 46 var p2 = (Permutation)parent2.JobSequenceMatrix[i].Clone(); 48 47 FindAndExchangeSubsequences(p1, p2, subSequenceLength); 49 48 result.JobSequenceMatrix.Add(p1); … … 51 50 return result; 52 51 } 52 53 53 private static void FindAndExchangeSubsequences(Permutation p1, Permutation p2, int subSequenceLength) { 54 54 for (int i = 0; i <= p1.Length - subSequenceLength; i++) { … … 63 63 } 64 64 } 65 65 66 private static void ExchangeSubsequences(Permutation p1, int index1, Permutation p2, int index2, int subSequenceLength) { 66 Permutationaux = (Permutation)p1.Clone();67 var aux = (Permutation)p1.Clone(); 67 68 for (int i = 0; i < subSequenceLength; i++) { 68 69 p1[i + index1] = p2[i + index2]; … … 70 71 } 71 72 } 73 72 74 private static bool AreEqualSubsequences(int[] ss1, int[] ss2) { 73 75 int counter = 0; … … 80 82 return counter == ss1.Length; 81 83 } 84 82 85 private static int[] GetSubSequenceAtPosition(Permutation p1, int index, int subSequenceLength) { 83 int[]result = new int[subSequenceLength];86 var result = new int[subSequenceLength]; 84 87 for (int i = 0; i < subSequenceLength; i++) 85 88 result[i] = p1[i + index]; -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JSMEncoding.cs
r8603 r8887 30 30 [StorableClass] 31 31 public class JSMEncoding : Item, IScheduleEncoding { 32 32 33 [Storable] 33 34 public ItemList<Permutation> JobSequenceMatrix { get; set; } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JSMRandomCreator.cs
r8603 r8887 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 31 30 namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix { 32 31 [Item("JobSequenceMatrixCreator", "Creator class used to create Job Sequence Matrix solutions for standard JobShop scheduling problems.")] 33 32 [StorableClass] 34 public class JSMRandomCreator : ScheduleCreator <JSMEncoding>, IStochasticOperator {35 #region Parameter Properties 33 public class JSMRandomCreator : ScheduleCreator, IStochasticOperator { 34 36 35 public ILookupParameter<IRandom> RandomParameter { 37 36 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 43 42 get { return (IValueLookupParameter<IntValue>)Parameters["Resources"]; } 44 43 } 45 #endregion46 47 44 48 45 [StorableConstructor] 49 46 protected JSMRandomCreator(bool deserializing) : base(deserializing) { } 50 protected JSMRandomCreator(JSMRandomCreator original, Cloner cloner) 51 : base(original, cloner) { 52 } 53 public override IDeepCloneable Clone(Cloner cloner) { 54 return new JSMRandomCreator(this, cloner); 55 } 47 protected JSMRandomCreator(JSMRandomCreator original, Cloner cloner) : base(original, cloner) { } 56 48 public JSMRandomCreator() 57 49 : base() { … … 63 55 } 64 56 57 public override IDeepCloneable Clone(Cloner cloner) { 58 return new JSMRandomCreator(this, cloner); 59 } 65 60 66 61 public static JSMEncoding Apply(int jobs, int resources, IRandom random) { 67 JSMEncoding solution = new JSMEncoding(); 68 62 var solution = new JSMEncoding(); 69 63 for (int i = 0; i < resources; i++) { 70 64 solution.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, jobs, random)); 71 65 } 72 73 66 return solution; 74 67 } 75 68 76 77 protected override JSMEncoding CreateSolution() { 69 protected override IScheduleEncoding CreateSolution() { 78 70 return Apply(JobsParameter.ActualValue.Value, ResourcesParameter.ActualValue.Value, RandomParameter.ActualValue); 79 71 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMManipulator.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 [Item("JSMManipulator", "An operator which manipulates a JSM representation.")] 28 29 [StorableClass] 29 public abstract class JSMManipulator : ScheduleManipulator <JSMEncoding>, IJSMOperator {30 public abstract class JSMManipulator : ScheduleManipulator, IJSMOperator { 30 31 [StorableConstructor] 31 32 protected JSMManipulator(bool deserializing) : base(deserializing) { } … … 36 37 } 37 38 38 protected abstract void Manipulate(IRandom random, JSMEncoding individual); 39 39 protected abstract void Manipulate(IRandom random, IScheduleEncoding individual); 40 40 41 41 public override IOperation Apply() { 42 JSMEncoding solution = ScheduleEncodingParameter.ActualValue; 42 var solution = ScheduleEncodingParameter.ActualValue as JSMEncoding; 43 if (solution == null) throw new InvalidOperationException("ScheduleEncoding was not found or is not of type JSMEncoding."); 43 44 Manipulate(RandomParameter.ActualValue, solution); 44 45 return base.Apply(); -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMShiftChangeManipulator.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 28 29 29 30 namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix { 30 31 31 [Item("JSMShiftChangeManipulator", "Represents a manipulation operation where the operations of a randomly determined job are shifted in one direction for all resources.")] 32 32 [StorableClass] 33 33 public class JSMShiftChangeManipulator : JSMManipulator { 34 34 35 [StorableConstructor] 35 36 protected JSMShiftChangeManipulator(bool deserializing) : base(deserializing) { } 36 protected JSMShiftChangeManipulator(JSMShiftChangeManipulator original, Cloner cloner) 37 : base(original, cloner) {38 } 37 protected JSMShiftChangeManipulator(JSMShiftChangeManipulator original, Cloner cloner) : base(original, cloner) { } 38 public JSMShiftChangeManipulator() : base() { } 39 39 40 public override IDeepCloneable Clone(Cloner cloner) { 40 41 return new JSMShiftChangeManipulator(this, cloner); 41 42 } 42 43 public JSMShiftChangeManipulator() : base() { }44 45 43 46 44 public static void Apply(IRandom random, JSMEncoding individual) { … … 65 63 } 66 64 67 protected override void Manipulate(IRandom random, JSMEncoding individual) { 68 Apply(random, individual); 65 protected override void Manipulate(IRandom random, IScheduleEncoding encoding) { 66 var solution = encoding as JSMEncoding; 67 if (solution == null) throw new InvalidOperationException("Encoding is not of type JSMEncoding"); 68 Apply(random, solution); 69 69 } 70 70 } -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMSwapManipulator.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 26 27 27 28 namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix { 28 29 29 [Item("JSMSwapManipulator", "Represents a manipulation operation swapping parts of the individual.")] 30 30 [StorableClass] 31 31 public class JSMSwapManipulator : JSMManipulator { 32 32 33 [StorableConstructor] 33 34 protected JSMSwapManipulator(bool deserializing) : base(deserializing) { } 34 protected JSMSwapManipulator(JSMSwapManipulator original, Cloner cloner) 35 : base(original, cloner) {36 } 35 protected JSMSwapManipulator(JSMSwapManipulator original, Cloner cloner) : base(original, cloner) { } 36 public JSMSwapManipulator() : base() { } 37 37 38 public override IDeepCloneable Clone(Cloner cloner) { 38 39 return new JSMSwapManipulator(this, cloner); 39 40 } 40 41 public JSMSwapManipulator() : base() { }42 43 41 44 42 public static void Apply(IRandom random, JSMEncoding individual) { … … 52 50 } 53 51 54 protected override void Manipulate(IRandom random, JSMEncoding individual) { 55 Apply(random, individual); 52 protected override void Manipulate(IRandom random, IScheduleEncoding individual) { 53 var solution = individual as JSMEncoding; 54 if (solution == null) throw new InvalidOperationException("Encoding is not of type JSMEncoding"); 55 Apply(random, solution); 56 56 } 57 57 }
Note: See TracChangeset
for help on using the changeset viewer.