Changeset 6177 for branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix
- Timestamp:
- 05/10/11 17:25:35 (14 years ago)
- Location:
- branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix
- Files:
-
- 6 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMCrossover.cs
r6121 r6177 30 30 [Item("JSMCrossover", "An operator which crosses two JSM representations.")] 31 31 [StorableClass] 32 public abstract class JSMCrossover : JSSPCrossover, IStochasticOperator, IJSMOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 35 } 32 public abstract class JSMCrossover : JSSPCrossover, IJSMOperator { 36 33 37 34 [StorableConstructor] … … 40 37 public JSMCrossover() 41 38 : base() { 42 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));43 39 } 44 40 45 p rotected abstractJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);41 public abstract IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2); 46 42 47 43 public override IOperation Apply() { 48 ItemArray< JSSPEncoding> parents = ParentsParameter.ActualValue;44 ItemArray<IJSSPEncoding> parents = ParentsParameter.ActualValue; 49 45 50 46 ChildParameter.ActualValue = -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMSXXCrossover.cs
r6121 r6177 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Problems.Scheduling.Interfaces; 30 using HeuristicLab.Encodings.PermutationEncoding; 29 31 30 32 namespace HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Crossovers { 31 [Item("JSM Subsequence Exchange Crossover", "Represents a crossover operation swappingsubsequences of the parents to generate offspring.")]33 [Item("JSM Subsequence Exchange Crossover", "Represents a crossover operation identifiying and exchanging equal subsequences of the parents to generate offspring.")] 32 34 [StorableClass] 33 35 public class JSMSXXCrossover : JSMCrossover { … … 43 45 public JSMSXXCrossover () : base () {} 44 46 45 p rotected override JSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {46 JS SPEncoding result = parent1;47 public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 48 JSMEncoding result = new JSMEncoding(); 47 49 50 int subSequenceLength = 3; 51 52 for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) { 53 Permutation p1 = (Permutation)parent1.JobSequenceMatrix[i].Clone(); 54 Permutation p2 = (Permutation)parent2.JobSequenceMatrix[i].Clone(); 55 FindAndExchangeSubsequences(p1, p2, subSequenceLength); 56 //parent1.JobSequenceMatrix[i] = p1; 57 //parent2.JobSequenceMatrix[i] = p2; 58 59 result.JobSequenceMatrix.Add(p1); 60 } 48 61 49 62 return result; 50 63 } 64 65 private static void FindAndExchangeSubsequences(Permutation p1, Permutation p2, int subSequenceLength) { 66 for (int i = 0; i <= p1.Length - subSequenceLength; i++) { 67 for (int j = 0; j <= p2.Length - subSequenceLength; j++) { 68 int[] ss1 = GetSubSequenceAtPosition(p1, i, subSequenceLength); 69 int[] ss2 = GetSubSequenceAtPosition(p2, j, subSequenceLength); 70 if (AreEqualSubsequences(ss1, ss2)) { 71 ExchangeSubsequences(p1, i, p2, j, subSequenceLength); 72 break; 73 } 74 } 75 } 76 } 77 private static void ExchangeSubsequences(Permutation p1, int index1, Permutation p2, int index2, int subSequenceLength) { 78 Permutation aux = (Permutation)p1.Clone(); 79 for (int i = 0; i < subSequenceLength; i++) { 80 p1[i + index1] = p2[i + index2]; 81 p2[i + index2] = aux[i + index1]; 82 } 83 } 84 private static bool AreEqualSubsequences(int[] ss1, int[] ss2) { 85 int counter = 0; 86 for (int i = 0; i < ss1.Length; i++) { 87 for (int j = 0; j < ss2.Length; j++) { 88 if (ss1[i] == ss2[j]) 89 counter++; 90 } 91 } 92 return counter == ss1.Length; 93 } 94 private static int[] GetSubSequenceAtPosition(Permutation p1, int index, int subSequenceLength) { 95 int[] result = new int[subSequenceLength]; 96 for (int i = 0; i < subSequenceLength; i++) 97 result[i] = p1[i + index]; 98 99 return result; 100 } 101 102 103 104 public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 105 return Cross(random, parent1, parent2); 106 } 51 107 } 52 108 } -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMDecoder.cs
r6121 r6177 35 35 [Item("Job Sequencing Matrix Decoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")] 36 36 [StorableClass] 37 public class JSMDecoder : NamedItem{37 public class JSMDecoder : JSSPDecoder<JSMEncoding>, IStochasticOperator { 38 38 [StorableConstructor] 39 39 protected JSMDecoder(bool deserializing) : base(deserializing) { } … … 41 41 : base(original, cloner) { 42 42 this.resultingSchedule = cloner.Clone(original.resultingSchedule); 43 this.decodingErrorPolicy = original.decodingErrorPolicy; 44 this.forcingStrategy = original.forcingStrategy; 43 45 } 44 46 public override IDeepCloneable Clone(Cloner cloner) { … … 46 48 } 47 49 50 public ILookupParameter<IRandom> RandomParameter { 51 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 52 } 53 48 54 [Storable] 49 55 private Schedule resultingSchedule; 50 56 51 57 [Storable] 52 private IRandom random; 53 54 public JSMDecoder(IntValue nrOfResources, IRandom r) 58 private JSMDecodingErrorPolicyTypes decodingErrorPolicy = JSMDecodingErrorPolicyTypes.GuidedPolicy; 59 60 [Storable] 61 private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing; 62 63 public JSMDecoder() 55 64 : base() { 56 resultingSchedule = new Schedule(nrOfResources); 57 random = r; 58 } 59 60 61 public Schedule CreateScheduleFromJSM(ItemList<JSSPJob> jobs, ItemList<Permutation> jobSequenceMatrix) { 62 //Reset scheduled tasks in result 63 foreach (JSSPJob j in jobs) { 64 foreach (JSSPTask t in j.Tasks) { 65 t.IsScheduled.Value = false; 66 } 67 } 68 69 //GT-Algorithm 70 //STEP 0 - Compute a list of "earliest operations" 71 ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(jobs); 72 while (earliestTasksList.Count > 0) { 73 //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time 74 JSSPTask minimal = GetTaskWithMinimalEC(earliestTasksList); 75 76 //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on 77 ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList); 78 79 //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..) 80 JSSPTask selectedTask = SelectTaskFromConflictSet(minimal.ResourceNr, conflictSet, jobSequenceMatrix); 81 82 //STEP 4 - Adding the selected operation to the current schedule 83 AddTaskToSchedule(selectedTask); 84 85 //STEP 5 - Back to STEP 1 86 earliestTasksList = GetEarliestNotScheduledTasks(jobs); 87 } 88 89 return resultingSchedule; 90 } 65 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 66 } 67 91 68 private ItemList<JSSPTask> GetEarliestNotScheduledTasks(ItemList<JSSPJob> jobs) { 92 69 ItemList<JSSPTask> result = new ItemList<JSSPTask>(); … … 132 109 IntValue solutionCandidateJobNr = new IntValue(jsm[conflictedResource.Value][progressOnResource.Value]); 133 110 foreach (JSSPTask t in conflictSet) { 134 if (t.Job. JobIndex == solutionCandidateJobNr)111 if (t.Job.Index.Value == solutionCandidateJobNr.Value) 135 112 result = t; 136 113 } … … 141 118 //Repairing happens here 142 119 if (result == null) { 143 result = conflictSet[random.Next(conflictSet.Count - 1)]; 120 //Decoding Error Policy BEGIN 121 //CHOOSE OTHER RESOLUTION FOR CONFLICT SET 122 result = ApplyDecodingErrorPolicy(conflictSet); 123 //result = conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)]; 124 //Decoding Error Policy END 125 126 127 //Determine index of new resolution 144 128 int index = 0; 145 foreach (int jobAssignment in jsm[conflictedResource.Value]) { 146 if (jobAssignment == result.Job.JobIndex.Value) 147 break; 129 while (index < jsm[conflictedResource.Value].Length && 130 jsm[conflictedResource.Value][index] != result.Job.Index.Value) 148 131 index++; 149 } 150 jsm[conflictedResource.Value][index] = jsm[conflictedResource.Value][progressOnResource.Value]; 151 jsm[conflictedResource.Value][progressOnResource.Value] = result.Job.JobIndex.Value; 152 } 153 154 155 return result; 132 133 134 //Forcing Strategy BEGIN 135 ApplyForcingStrategy(jsm, conflictedResource.Value, index, progressOnResource.Value, result.Job.Index.Value); 136 137 //ForcingStrategy END 138 } 139 return result; 140 } 141 142 private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) { 143 //if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) { 144 //SwapForcing 145 jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource]; 146 jsm[conflictedResource][progressOnResource] = newResolution; 147 /*} else { 148 //ShiftForcing 149 150 } */ 151 } 152 153 private JSSPTask ApplyDecodingErrorPolicy(ItemList<JSSPTask> conflictSet) { 154 //if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) { 155 //Random 156 return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)]; 157 /*} else { 158 //Guided 159 160 } */ 156 161 } 157 162 private DoubleValue ComputeEarliestStartTime(JSSPTask t) { … … 174 179 affectedResource.Tasks.Add(selectedTask); 175 180 } 181 182 public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) { 183 ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix; 184 185 resultingSchedule = new Schedule(new IntValue(Jobs[0].Tasks.Count)); 186 187 //Reset scheduled tasks in result 188 foreach (JSSPJob j in Jobs) { 189 foreach (JSSPTask t in j.Tasks) { 190 t.IsScheduled.Value = false; 191 } 192 } 193 194 //GT-Algorithm 195 //STEP 0 - Compute a list of "earliest operations" 196 ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(Jobs); 197 while (earliestTasksList.Count > 0) { 198 //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time 199 JSSPTask minimal = GetTaskWithMinimalEC(earliestTasksList); 200 201 //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on 202 ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList); 203 204 //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..) 205 JSSPTask selectedTask = SelectTaskFromConflictSet(minimal.ResourceNr, conflictSet, jobSequenceMatrix); 206 207 //STEP 4 - Adding the selected operation to the current schedule 208 AddTaskToSchedule(selectedTask); 209 210 //STEP 5 - Back to STEP 1 211 earliestTasksList = GetEarliestNotScheduledTasks(Jobs); 212 } 213 214 return resultingSchedule; 215 } 216 217 public override IOperation Apply() { 218 return base.Apply(); 219 } 176 220 } 177 221 } -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMEncoding.cs
r6121 r6177 29 29 using HeuristicLab.Encodings.PermutationEncoding; 30 30 using HeuristicLab.Data; 31 using HeuristicLab.Problems.Scheduling.Encodings; 31 using HeuristicLab.Problems.Scheduling.Interfaces; 32 using HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Crossovers; 33 using HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Manipulators; 32 34 33 35 namespace HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix { 34 36 [Item("Job Sequencing Matrix Encoding", "Represents a solution for a standard JobShop Scheduling Problem.")] 35 37 [StorableClass] 36 public class JSMEncoding : JSSPEncoding{38 public class JSMEncoding : ParameterizedNamedItem, IJSSPEncoding{ 37 39 [StorableConstructor] 38 40 protected JSMEncoding(bool deserializing) : base(deserializing) { } … … 52 54 } 53 55 54 public override Schedule ToSchedule(IntValue nrOfResources, ItemList<JSSPJob> jobs, IRandom random) {55 JSMDecoder decoder = new JSMDecoder(nrOfResources, random);56 return decoder.CreateScheduleFromJSM (jobs, JobSequenceMatrix);57 }58 59 56 public override string ToString() { 60 57 StringBuilder sb = new StringBuilder(); -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMRandomCreator.cs
r6121 r6177 64 64 JSMEncoding solution = new JSMEncoding(); 65 65 IntValue nrOfJobs = new IntValue (Jobs.Count); 66 IntValue nrOfResources = NrOfResources;66 IntValue nrOfResources = new IntValue (Jobs[0].Tasks.Count); 67 67 68 68 for (int i = 0; i < nrOfResources.Value; i++) { -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Manipulators/JSMManipulator.cs
r6121 r6177 32 32 [Item("AlbaManipulator", "An operator which manipulates a VRP representation.")] 33 33 [StorableClass] 34 public abstract class JSMManipulator : JSSPManipulator, IStochasticOperator, IJSMOperator { 35 public ILookupParameter<IRandom> RandomParameter { 36 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 37 } 38 34 public abstract class JSMManipulator : JSSPManipulator, IJSMOperator { 39 35 [StorableConstructor] 40 36 protected JSMManipulator(bool deserializing) : base(deserializing) { } … … 42 38 public JSMManipulator() 43 39 : base() { 44 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));45 40 } 46 41 … … 49 44 50 45 public override IOperation Apply() { 51 JSSPEncoding solution = SchedulingSolutionParameter.ActualValue;46 IJSSPEncoding solution = SchedulingSolutionParameter.ActualValue; 52 47 53 48 SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding);
Note: See TracChangeset
for help on using the changeset viewer.