Changeset 6260 for branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix
- Timestamp:
- 05/24/11 09:47:24 (14 years ago)
- Location:
- branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix
- Files:
-
- 2 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMCrossover.cs
r6177 r6260 30 30 [Item("JSMCrossover", "An operator which crosses two JSM representations.")] 31 31 [StorableClass] 32 public abstract class JSMCrossover : JSSPCrossover , IJSMOperator {32 public abstract class JSMCrossover : JSSPCrossover<JSMEncoding>, IJSMOperator { 33 33 34 34 [StorableConstructor] … … 39 39 } 40 40 41 public abstract IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);41 public abstract JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2); 42 42 43 43 public override IOperation Apply() { 44 ItemArray< IJSSPEncoding> parents = ParentsParameter.ActualValue;44 ItemArray<JSMEncoding> parents = ParentsParameter.ActualValue; 45 45 46 46 ChildParameter.ActualValue = -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMJOXCrossover.cs
r6177 r6260 46 46 public JSMJOXCrossover() : base() { } 47 47 48 public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {48 public static JSMEncoding Cross(IRandom random, JSMEncoding p1, JSMEncoding p2) { 49 49 JSMEncoding result = new JSMEncoding(); 50 50 51 int nrOfResources = p arent1.JobSequenceMatrix.Count;52 int nrOfJobs = p arent1.JobSequenceMatrix[0].Length;51 int nrOfResources = p1.JobSequenceMatrix.Count; 52 int nrOfJobs = p1.JobSequenceMatrix[0].Length; 53 53 54 54 //Determine randomly which jobindexes persist … … 56 56 for (int i = 0; i < persist.Length; i++) { 57 57 persist[i] = random.Next(2) == 1; 58 } 58 } 59 60 bool dominantParent = random.Next(2) == 1; 61 JSMEncoding parent1 = dominantParent ? p1 : p2; 62 JSMEncoding parent2 = dominantParent ? p2 : p1; 59 63 60 64 //Fill childmatrix with values … … 77 81 } 78 82 79 public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {83 public override JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 80 84 return Cross(random, parent1, parent2); 81 85 } -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMSXXCrossover.cs
r6177 r6260 45 45 public JSMSXXCrossover () : base () {} 46 46 47 public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {47 public static JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 48 48 JSMEncoding result = new JSMEncoding(); 49 49 50 int subSequenceLength = 3;50 int subSequenceLength = random.Next (parent1.JobSequenceMatrix[0].Length); 51 51 52 52 for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) { … … 102 102 103 103 104 public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {104 public override JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) { 105 105 return Cross(random, parent1, parent2); 106 106 } -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMDecoder.cs
r6177 r6260 41 41 : base(original, cloner) { 42 42 this.resultingSchedule = cloner.Clone(original.resultingSchedule); 43 this.jobs = cloner.Clone(original.jobs); 43 44 this.decodingErrorPolicy = original.decodingErrorPolicy; 44 45 this.forcingStrategy = original.forcingStrategy; … … 52 53 } 53 54 55 #region Private Members 54 56 [Storable] 55 57 private Schedule resultingSchedule; 56 58 57 59 [Storable] 60 private ItemList<JSSPJob> jobs; 61 62 [Storable] 58 63 private JSMDecodingErrorPolicyTypes decodingErrorPolicy = JSMDecodingErrorPolicyTypes.GuidedPolicy; 59 64 60 65 [Storable] 61 private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing; 66 private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing; 67 #endregion 62 68 63 69 public JSMDecoder() … … 66 72 } 67 73 68 private ItemList<JSSPTask> GetEarliestNotScheduledTasks( ItemList<JSSPJob> jobs) {74 private ItemList<JSSPTask> GetEarliestNotScheduledTasks() { 69 75 ItemList<JSSPTask> result = new ItemList<JSSPTask>(); 70 76 foreach (JSSPJob j in jobs) { … … 79 85 } 80 86 private JSSPTask GetTaskWithMinimalEC(ItemList<JSSPTask> earliestTasksList) { 81 DoubleValue minEct = new DoubleValue(Double.MaxValue);87 double minEct = double.MaxValue; 82 88 JSSPTask result = null; 83 89 foreach (JSSPTask t in earliestTasksList) { 84 DoubleValue ect = ComputeEarliestCompletionTime(t);85 if (ect .Value < minEct.Value) {90 double ect = resultingSchedule.ComputeEarliestCompletionTime(t, jobs[t.JobNr.Value]); 91 if (ect < minEct) { 86 92 result = t; 87 93 minEct = ect; … … 92 98 private ItemList<JSSPTask> GetConflictSetForTask(JSSPTask conflictedTask, ItemList<JSSPTask> earliestTasksList) { 93 99 ItemList<JSSPTask> result = new ItemList<JSSPTask>(); 94 DoubleValue conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask);100 double conflictedCompletionTime = resultingSchedule.ComputeEarliestCompletionTime(conflictedTask, jobs[conflictedTask.JobNr.Value]); 95 101 result.Add(conflictedTask); 96 102 foreach (JSSPTask t in earliestTasksList) { 97 103 if (t.ResourceNr.Value == conflictedTask.ResourceNr.Value) { 98 if ( ComputeEarliestStartTime(t).Value < conflictedCompletionTime.Value)104 if (resultingSchedule.ComputeEarliestStartTime(t, jobs[t.JobNr.Value]) < conflictedCompletionTime) 99 105 result.Add(t); 100 106 } … … 102 108 return result; 103 109 } 104 private JSSPTask SelectTaskFromConflictSet(IntValue conflictedResource, ItemList<JSSPTask> conflictSet, ItemList<Permutation> jsm) { 105 JSSPTask result = null; 106 IntValue progressOnResource = new IntValue (resultingSchedule.Resources[conflictedResource.Value].Tasks.Count); 107 108 if (progressOnResource.Value < jsm[conflictedResource.Value].Length) { 109 IntValue solutionCandidateJobNr = new IntValue(jsm[conflictedResource.Value][progressOnResource.Value]); 110 foreach (JSSPTask t in conflictSet) { 111 if (t.Job.Index.Value == solutionCandidateJobNr.Value) 112 result = t; 113 } 110 private JSSPTask SelectTaskFromConflictSet(int conflictedResourceNr, int progressOnConflictedResource, ItemList<JSSPTask> conflictSet, ItemList<Permutation> jsm) { 111 if (conflictSet.Count == 1) 112 return conflictSet[0]; 113 114 //get solutionCandidate from jobSequencingMatrix 115 int solutionCandidateJobNr = jsm[conflictedResourceNr][progressOnConflictedResource]; 116 117 //scan conflictSet for given solutionCandidate, and return if found 118 foreach (JSSPTask t in conflictSet) { 119 if (t.JobNr.Value == solutionCandidateJobNr) 120 return t; 121 } 122 123 //if solutionCandidate wasn't found in conflictSet apply DecodingErrorPolicy and ForcingPolicy 124 JSSPTask result = ApplyDecodingErrorPolicy(conflictSet, jsm[conflictedResourceNr], progressOnConflictedResource); 125 int newResolutionIndex = 0; 126 127 while (newResolutionIndex < jsm[conflictedResourceNr].Length && jsm[conflictedResourceNr][newResolutionIndex] != result.JobNr.Value) 128 newResolutionIndex++; 129 ApplyForcingStrategy(jsm, conflictedResourceNr, newResolutionIndex, progressOnConflictedResource, result.JobNr.Value); 130 131 return result; 132 } 133 private JSSPTask ApplyDecodingErrorPolicy(ItemList<JSSPTask> conflictSet, Permutation resource, int progress) { 134 if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) { 135 //Random 136 return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)]; 114 137 } else { 115 return null; 116 } 117 118 //Repairing happens here 119 if (result == null) { 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 128 int index = 0; 129 while (index < jsm[conflictedResource.Value].Length && 130 jsm[conflictedResource.Value][index] != result.Job.Index.Value) 131 index++; 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 138 //Guided 139 for (int i = progress; i < resource.Length; i++) { 140 int j = 0; 141 while (j < conflictSet.Count && conflictSet[j].JobNr.Value != resource[i]) 142 j++; 143 144 if (j < conflictSet.Count) 145 return (conflictSet[j]); 146 } 147 return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)]; 148 } 149 } 142 150 private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) { 143 //if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {151 if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) { 144 152 //SwapForcing 145 153 jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource]; 146 154 jsm[conflictedResource][progressOnResource] = newResolution; 147 /*} else {155 } else { 148 156 //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 } */ 161 } 162 private DoubleValue ComputeEarliestStartTime(JSSPTask t) { 163 Resource affectedResource = resultingSchedule.Resources[t.ResourceNr.Value]; 164 165 DoubleValue lastMachineEndTime = affectedResource.TotalDuration; 166 DoubleValue previousJoboperationEndTime = new DoubleValue(double.MinValue); 167 if (t.PreviousTask != null) 168 previousJoboperationEndTime = t.PreviousTask.EndTime; 169 170 return new DoubleValue(Math.Max(previousJoboperationEndTime.Value, lastMachineEndTime.Value)); 171 } 172 private DoubleValue ComputeEarliestCompletionTime(JSSPTask t) { 173 return new DoubleValue(ComputeEarliestStartTime(t).Value + t.Duration.Value); 174 } 175 private void AddTaskToSchedule(JSSPTask selectedTask) { 176 Resource affectedResource = resultingSchedule.Resources[selectedTask.ResourceNr.Value]; 177 selectedTask.StartTime = ComputeEarliestStartTime(selectedTask); 178 selectedTask.IsScheduled.Value = true; 179 affectedResource.Tasks.Add(selectedTask); 180 } 181 182 public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) { 157 List<int> asList = jsm[conflictedResource].ToList<int>(); 158 if (newResolutionIndex > progressOnResource) { 159 asList.RemoveAt(newResolutionIndex); 160 asList.Insert(progressOnResource, newResolution); 161 } else { 162 asList.Insert(progressOnResource, newResolution); 163 asList.RemoveAt(newResolutionIndex); 164 } 165 jsm[conflictedResource] = new Permutation (PermutationTypes.Absolute, asList.ToArray<int>()); 166 } 167 } 168 169 public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList<JSSPJob> jobData) { 183 170 ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix; 184 171 185 resultingSchedule = new Schedule(new IntValue(Jobs[0].Tasks.Count)); 172 jobs = (ItemList<JSSPJob>)jobData.Clone(); 173 resultingSchedule = new Schedule(new IntValue(jobs[0].Tasks.Count)); 186 174 187 175 //Reset scheduled tasks in result 188 foreach (JSSPJob j in Jobs) {176 foreach (JSSPJob j in jobs) { 189 177 foreach (JSSPTask t in j.Tasks) { 190 178 t.IsScheduled.Value = false; … … 194 182 //GT-Algorithm 195 183 //STEP 0 - Compute a list of "earliest operations" 196 ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks( Jobs);184 ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(); 197 185 while (earliestTasksList.Count > 0) { 198 186 //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time 199 187 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 188 int conflictedResourceNr = minimal.ResourceNr.Value; 189 Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr]; 190 191 //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource 202 192 ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList); 203 193 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); 194 //STEP 3 - Select a task from the conflict set 195 int progressOnResource = conflictedResource.Tasks.Count; 196 JSSPTask selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix); 197 198 //STEP 4 - Add the selected task to the current schedule 199 selectedTask.IsScheduled.Value = true; 200 resultingSchedule.AddTask(selectedTask, jobs[selectedTask.JobNr.Value]); 209 201 210 202 //STEP 5 - Back to STEP 1 211 earliestTasksList = GetEarliestNotScheduledTasks( Jobs);203 earliestTasksList = GetEarliestNotScheduledTasks(); 212 204 } 213 205 214 206 return resultingSchedule; 207 } 208 209 public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) { 210 return CreateScheduleFromEncoding(solution, Jobs); 215 211 } 216 212 -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMEncoding.cs
r6177 r6260 36 36 [Item("Job Sequencing Matrix Encoding", "Represents a solution for a standard JobShop Scheduling Problem.")] 37 37 [StorableClass] 38 public class JSMEncoding : ParameterizedNamedItem, I JSSPEncoding{38 public class JSMEncoding : ParameterizedNamedItem, ISchedulingEncoding{ 39 39 [StorableConstructor] 40 40 protected JSMEncoding(bool deserializing) : base(deserializing) { } -
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Manipulators/JSMManipulator.cs
r6177 r6260 32 32 [Item("AlbaManipulator", "An operator which manipulates a VRP representation.")] 33 33 [StorableClass] 34 public abstract class JSMManipulator : JSSPManipulator , IJSMOperator {34 public abstract class JSMManipulator : JSSPManipulator<JSMEncoding>, IJSMOperator { 35 35 [StorableConstructor] 36 36 protected JSMManipulator(bool deserializing) : base(deserializing) { } … … 44 44 45 45 public override IOperation Apply() { 46 IJSSPEncoding solution = SchedulingSolutionParameter.ActualValue;46 JSMEncoding solution = SchedulingSolutionParameter.ActualValue; 47 47 48 SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding); 48 int nrOfMutations = RandomParameter.ActualValue.Next(5) + 1; 49 50 for (int i = 0; i < nrOfMutations; i++ ) 51 SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding); 49 52 50 53 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.