- Timestamp:
- 11/11/12 22:57:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/JSMDecoder.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 34 35 [Item("JobSequenceMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequence Matrix.")] 35 36 [StorableClass] 36 public class JSMDecoder : ScheduleDecoder<JSMEncoding>, IStochasticOperator, IJSSPOperator { 37 public class JSMDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator { 38 37 39 public ILookupParameter<IRandom> RandomParameter { 38 40 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 41 43 get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; } 42 44 } 45 public IValueParameter<JSMDecodingErrorPolicy> DecodingErrorPolicyParameter { 46 get { return (IValueParameter<JSMDecodingErrorPolicy>)Parameters["DecodingErrorPolicy"]; } 47 } 48 public IValueParameter<JSMForcingStrategy> ForcingStrategyParameter { 49 get { return (IValueParameter<JSMForcingStrategy>)Parameters["ForcingStrategy"]; } 50 } 43 51 44 #region Private Members45 [Storable]46 private Schedule resultingSchedule;52 private JSMDecodingErrorPolicyTypes DecodingErrorPolicy { 53 get { return DecodingErrorPolicyParameter.Value.Value; } 54 } 47 55 48 [Storable] 49 private ItemList<Job> jobs; 50 51 [Storable] 52 private JSMDecodingErrorPolicyTypes decodingErrorPolicy = JSMDecodingErrorPolicyTypes.GuidedPolicy; 53 54 [Storable] 55 private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing; 56 #endregion 56 private JSMForcingStrategyTypes ForcingStrategy { 57 get { return ForcingStrategyParameter.Value.Value; } 58 } 57 59 58 60 [StorableConstructor] 59 61 protected JSMDecoder(bool deserializing) : base(deserializing) { } 60 protected JSMDecoder(JSMDecoder original, Cloner cloner) 61 : base(original, cloner) { 62 this.resultingSchedule = cloner.Clone(original.resultingSchedule); 63 this.jobs = cloner.Clone(original.jobs); 64 this.decodingErrorPolicy = original.decodingErrorPolicy; 65 this.forcingStrategy = original.forcingStrategy; 66 } 62 protected JSMDecoder(JSMDecoder original, Cloner cloner) : base(original, cloner) { } 67 63 public override IDeepCloneable Clone(Cloner cloner) { 68 64 return new JSMDecoder(this, cloner); … … 73 69 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 74 70 Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the Schedulingproblem - Instance.")); 71 Parameters.Add(new ValueParameter<JSMDecodingErrorPolicy>("DecodingErrorPolicy", "Specify the policy that should be used to handle decoding errors.", new JSMDecodingErrorPolicy(JSMDecodingErrorPolicyTypes.RandomPolicy))); 72 Parameters.Add(new ValueParameter<JSMForcingStrategy>("ForcingStrategy", "Specifies a forcing strategy.", new JSMForcingStrategy(JSMForcingStrategyTypes.SwapForcing))); 73 75 74 ScheduleEncodingParameter.ActualName = "JobSequenceMatrix"; 76 75 } 77 78 76 79 77 private Task SelectTaskFromConflictSet(int conflictedResourceNr, int progressOnConflictedResource, ItemList<Task> conflictSet, ItemList<Permutation> jsm) { … … 100 98 return result; 101 99 } 100 102 101 private Task ApplyDecodingErrorPolicy(ItemList<Task> conflictSet, Permutation resource, int progress) { 103 if ( decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {102 if (DecodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) { 104 103 //Random 105 104 return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)]; … … 117 116 } 118 117 } 118 119 119 private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) { 120 if ( forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {120 if (ForcingStrategy == JSMForcingStrategyTypes.SwapForcing) { 121 121 //SwapForcing 122 122 jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource]; … … 139 139 ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix; 140 140 141 jobs = (ItemList<Job>)jobData.Clone();142 resultingSchedule = new Schedule(jobs[0].Tasks.Count);141 var jobs = (ItemList<Job>)jobData.Clone(); 142 var resultingSchedule = new Schedule(jobs[0].Tasks.Count); 143 143 144 144 //Reset scheduled tasks in result … … 177 177 } 178 178 179 public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) { 179 public override Schedule CreateScheduleFromEncoding(IScheduleEncoding encoding) { 180 var solution = encoding as JSMEncoding; 181 if (solution == null) throw new InvalidOperationException("Encoding is not of type JSMEncoding"); 180 182 return CreateScheduleFromEncoding(solution, JobDataParameter.ActualValue); 181 }182 183 public override IOperation Apply() {184 return base.Apply();185 183 } 186 184 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/JSMDecodingErrorPolicyTypes.cs
r8603 r8887 19 19 */ 20 20 #endregion 21 21 22 namespace HeuristicLab.Problems.Scheduling { 22 23 public enum JSMDecodingErrorPolicyTypes { -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/PRVDecoder.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 31 32 [Item("JobSequencingMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")] 32 33 [StorableClass] 33 public class PRVDecoder : ScheduleDecoder<PRVEncoding>, IStochasticOperator, IJSSPOperator { 34 public class PRVDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator { 35 34 36 public ILookupParameter<IRandom> RandomParameter { 35 37 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 38 40 get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; } 39 41 } 40 41 #region Private Members42 [Storable]43 private Schedule resultingSchedule;44 45 [Storable]46 private ItemList<Job> jobs;47 #endregion48 42 49 43 #region Priority Rules … … 55 49 56 50 //earliest start time 57 private Task ESTRule(ItemList<Task> tasks ) {51 private Task ESTRule(ItemList<Task> tasks, Schedule schedule) { 58 52 Task currentResult = RandomRule(tasks); 59 53 double currentEST = double.MaxValue; 60 54 foreach (Task t in tasks) { 61 double est = GTAlgorithmUtils.ComputeEarliestStartTime(t, resultingSchedule);55 double est = GTAlgorithmUtils.ComputeEarliestStartTime(t, schedule); 62 56 if (est < currentEST) { 63 57 currentEST = est; … … 89 83 90 84 //most work remaining 91 private Task MWRRule(ItemList<Task> tasks ) {85 private Task MWRRule(ItemList<Task> tasks, ItemList<Job> jobs) { 92 86 Task currentResult = RandomRule(tasks); 93 87 double currentLargestRemainingProcessingTime = 0; … … 107 101 108 102 //least work remaining 109 private Task LWRRule(ItemList<Task> tasks ) {103 private Task LWRRule(ItemList<Task> tasks, ItemList<Job> jobs) { 110 104 Task currentResult = RandomRule(tasks); 111 105 double currentSmallestRemainingProcessingTime = double.MaxValue; … … 125 119 126 120 //most operations remaining 127 private Task MORRule(ItemList<Task> tasks ) {121 private Task MORRule(ItemList<Task> tasks, ItemList<Job> jobs) { 128 122 Task currentResult = RandomRule(tasks); 129 123 int currentLargestNrOfRemainingTasks = 0; … … 143 137 144 138 //least operationsremaining 145 private Task LORRule(ItemList<Task> tasks ) {139 private Task LORRule(ItemList<Task> tasks, ItemList<Job> jobs) { 146 140 Task currentResult = RandomRule(tasks); 147 141 int currentSmallestNrOfRemainingTasks = int.MaxValue; … … 176 170 [StorableConstructor] 177 171 protected PRVDecoder(bool deserializing) : base(deserializing) { } 178 protected PRVDecoder(PRVDecoder original, Cloner cloner) 179 : base(original, cloner) { 180 this.resultingSchedule = cloner.Clone(original.resultingSchedule); 181 } 182 public override IDeepCloneable Clone(Cloner cloner) { 183 return new PRVDecoder(this, cloner); 184 } 185 172 protected PRVDecoder(PRVDecoder original, Cloner cloner) : base(original, cloner) { } 186 173 public PRVDecoder() 187 174 : base() { … … 191 178 } 192 179 193 private Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, int ruleIndex, int nrOfRules) { 180 public override IDeepCloneable Clone(Cloner cloner) { 181 return new PRVDecoder(this, cloner); 182 } 183 184 private Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, int ruleIndex, int nrOfRules, Schedule schedule, ItemList<Job> jobs) { 194 185 if (conflictSet.Count == 1) 195 186 return conflictSet[0]; … … 198 189 switch (ruleIndex) { 199 190 case 0: return FILORule(conflictSet); 200 case 1: return ESTRule(conflictSet );191 case 1: return ESTRule(conflictSet, schedule); 201 192 case 2: return SPTRule(conflictSet); 202 193 case 3: return LPTRule(conflictSet); 203 case 4: return MWRRule(conflictSet );204 case 5: return LWRRule(conflictSet );205 case 6: return MORRule(conflictSet );206 case 7: return LORRule(conflictSet );194 case 4: return MWRRule(conflictSet, jobs); 195 case 5: return LWRRule(conflictSet, jobs); 196 case 6: return MORRule(conflictSet, jobs); 197 case 7: return LORRule(conflictSet, jobs); 207 198 case 8: return FIFORule(conflictSet); 208 199 case 9: return RandomRule(conflictSet); … … 211 202 } 212 203 213 public override Schedule CreateScheduleFromEncoding(PRVEncoding solution) { 214 jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 215 resultingSchedule = new Schedule(jobs[0].Tasks.Count); 204 public override Schedule CreateScheduleFromEncoding(IScheduleEncoding encoding) { 205 var solution = encoding as PRVEncoding; 206 if (solution == null) throw new InvalidOperationException("Encoding is not of type PWREncoding"); 207 208 var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 209 var resultingSchedule = new Schedule(jobs[0].Tasks.Count); 216 210 217 211 //Reset scheduled tasks in result … … 235 229 //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..) 236 230 //Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector [currentDecisionIndex++], solution.NrOfRules.Value); 237 Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector[minimal.JobNr], solution.NrOfRules.Value );231 Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector[minimal.JobNr], solution.NrOfRules.Value, resultingSchedule, jobs); 238 232 239 233 //STEP 4 - Adding the selected operation to the current schedule … … 248 242 return resultingSchedule; 249 243 } 250 251 public override IOperation Apply() {252 return base.Apply();253 }254 244 } 255 245 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/PWRDecoder.cs
r8603 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 31 32 [Item("PWRDecoder", "An item used to convert a PWR-individual into a generalized schedule.")] 32 33 [StorableClass] 33 public class PWRDecoder : ScheduleDecoder<PWREncoding>, IStochasticOperator, IJSSPOperator { 34 public class PWRDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator { 35 34 36 public ILookupParameter<IRandom> RandomParameter { 35 37 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 41 43 [StorableConstructor] 42 44 protected PWRDecoder(bool deserializing) : base(deserializing) { } 43 protected PWRDecoder(PWRDecoder original, Cloner cloner) 44 : base(original, cloner) { 45 } 46 public override IDeepCloneable Clone(Cloner cloner) { 47 return new PWRDecoder(this, cloner); 48 } 49 45 protected PWRDecoder(PWRDecoder original, Cloner cloner) : base(original, cloner) { } 50 46 public PWRDecoder() 51 47 : base() { … … 55 51 } 56 52 57 public override Schedule CreateScheduleFromEncoding(PWREncoding solution) { 58 ItemList<Job> jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 59 Schedule resultingSchedule = new Schedule(jobs[0].Tasks.Count); 53 public override IDeepCloneable Clone(Cloner cloner) { 54 return new PWRDecoder(this, cloner); 55 } 56 57 public override Schedule CreateScheduleFromEncoding(IScheduleEncoding encoding) { 58 var solution = encoding as PWREncoding; 59 if (solution == null) throw new InvalidOperationException("Encoding is not of type PWREncoding"); 60 61 var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 62 var resultingSchedule = new Schedule(jobs[0].Tasks.Count); 60 63 foreach (int jobNr in solution.PermutationWithRepetition) { 61 64 int i = 0; … … 68 71 return resultingSchedule; 69 72 } 70 71 public override IOperation Apply() {72 return base.Apply();73 }74 73 } 75 74 }
Note: See TracChangeset
for help on using the changeset viewer.