- Timestamp:
- 11/11/12 22:57:09 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.