Changeset 13443 for branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/Decoder
- Timestamp:
- 12/08/15 14:31:05 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/Decoder
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/Decoder/PRVDecoder.cs
r13437 r13443 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.ScheduleEncoding; 26 using HeuristicLab.Optimization;27 using HeuristicLab.Parameters;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 namespace HeuristicLab.Problems.Scheduling { 28 using HeuristicLab.Random; 29 30 namespace HeuristicLab.Encodings.ScheduleEncoding { 31 31 [Item("JobSequencingMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")] 32 32 [StorableClass] 33 public class PRVDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator { 34 35 public ILookupParameter<IRandom> RandomParameter { 36 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 37 } 38 public ILookupParameter<ItemList<Job>> JobDataParameter { 39 get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; } 40 } 41 33 public class PRVDecoder : ScheduleDecoder { 42 34 #region Priority Rules 43 35 //smallest number of remaining tasks 44 private Task FILORule(ItemList<Task> tasks) {36 private static Task FILORule(ItemList<Task> tasks) { 45 37 Task currentResult = tasks[tasks.Count - 1]; 46 38 return currentResult; … … 48 40 49 41 //earliest start time 50 private Task ESTRule(ItemList<Task> tasks, Schedule schedule) {51 Task currentResult = RandomRule(tasks);42 private static Task ESTRule(ItemList<Task> tasks, Schedule schedule) { 43 Task currentResult = tasks.First(); 52 44 double currentEST = double.MaxValue; 53 45 foreach (Task t in tasks) { … … 62 54 63 55 //shortest processingtime 64 private Task SPTRule(ItemList<Task> tasks) {65 Task currentResult = RandomRule(tasks);56 private static Task SPTRule(ItemList<Task> tasks) { 57 Task currentResult = tasks.First(); 66 58 foreach (Task t in tasks) { 67 59 if (t.Duration < currentResult.Duration) … … 72 64 73 65 //longest processing time 74 private Task LPTRule(ItemList<Task> tasks) {75 Task currentResult = RandomRule(tasks);66 private static Task LPTRule(ItemList<Task> tasks) { 67 Task currentResult = tasks.First(); 76 68 foreach (Task t in tasks) { 77 69 if (t.Duration > currentResult.Duration) … … 82 74 83 75 //most work remaining 84 private Task MWRRule(ItemList<Task> tasks, ItemList<Job> jobs) {85 Task currentResult = RandomRule(tasks);76 private static Task MWRRule(ItemList<Task> tasks, ItemList<Job> jobs) { 77 Task currentResult = tasks.First(); 86 78 double currentLargestRemainingProcessingTime = 0; 87 79 foreach (Task t in tasks) { … … 100 92 101 93 //least work remaining 102 private Task LWRRule(ItemList<Task> tasks, ItemList<Job> jobs) {103 Task currentResult = RandomRule(tasks);94 private static Task LWRRule(ItemList<Task> tasks, ItemList<Job> jobs) { 95 Task currentResult = tasks.First(); 104 96 double currentSmallestRemainingProcessingTime = double.MaxValue; 105 97 foreach (Task t in tasks) { … … 118 110 119 111 //most operations remaining 120 private Task MORRule(ItemList<Task> tasks, ItemList<Job> jobs) {121 Task currentResult = RandomRule(tasks);112 private static Task MORRule(ItemList<Task> tasks, ItemList<Job> jobs) { 113 Task currentResult = tasks.First(); 122 114 int currentLargestNrOfRemainingTasks = 0; 123 115 foreach (Task t in tasks) { … … 136 128 137 129 //least operationsremaining 138 private Task LORRule(ItemList<Task> tasks, ItemList<Job> jobs) {139 Task currentResult = RandomRule(tasks);130 private static Task LORRule(ItemList<Task> tasks, ItemList<Job> jobs) { 131 Task currentResult = tasks.First(); 140 132 int currentSmallestNrOfRemainingTasks = int.MaxValue; 141 133 foreach (Task t in tasks) { … … 154 146 155 147 //first operation in Queue 156 private Task FIFORule(ItemList<Task> tasks) {148 private static Task FIFORule(ItemList<Task> tasks) { 157 149 Task currentResult = tasks[0]; 158 150 return currentResult; … … 160 152 161 153 //random 162 private Task RandomRule(ItemList<Task> tasks) {163 Task currentResult = tasks[ RandomParameter.ActualValue.Next(tasks.Count)];154 private static Task RandomRule(ItemList<Task> tasks, IRandom random) { 155 Task currentResult = tasks[random.Next(tasks.Count)]; 164 156 return currentResult; 165 157 } … … 170 162 protected PRVDecoder(bool deserializing) : base(deserializing) { } 171 163 protected PRVDecoder(PRVDecoder original, Cloner cloner) : base(original, cloner) { } 172 public PRVDecoder() 173 : base() { 174 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 175 Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the SchedulingProblem - Instance.")); 176 ScheduleEncodingParameter.ActualName = "PriorityRulesVector"; 177 } 164 public PRVDecoder() : base() { } 178 165 179 166 public override IDeepCloneable Clone(Cloner cloner) { … … 181 168 } 182 169 183 private Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, int ruleIndex, int nrOfRules, Schedule schedule, ItemList<Job> jobs) {170 private static Task SelectTaskFromConflictSet(ItemList<Task> conflictSet, int ruleIndex, Schedule schedule, ItemList<Job> jobs, IRandom random) { 184 171 if (conflictSet.Count == 1) 185 172 return conflictSet[0]; 186 173 187 ruleIndex = ruleIndex % nrOfRules; 174 //TODO change to property, Encoding parameter? 175 ruleIndex = ruleIndex % 10; 188 176 switch (ruleIndex) { 189 177 case 0: return FILORule(conflictSet); … … 196 184 case 7: return LORRule(conflictSet, jobs); 197 185 case 8: return FIFORule(conflictSet); 198 case 9: return RandomRule(conflictSet );199 default: return RandomRule(conflictSet );200 } 201 } 202 203 public override Schedule CreateScheduleFromEncoding(ISchedule encoding) {186 case 9: return RandomRule(conflictSet, random); 187 default: return RandomRule(conflictSet, random); 188 } 189 } 190 191 public override Schedule DecodeSchedule(ISchedule encoding, ItemList<Job> jobData) { 204 192 var solution = encoding as PRVEncoding; 205 193 if (solution == null) throw new InvalidOperationException("Encoding is not of type PRVEncoding"); 206 207 var jobs = (ItemList<Job>)JobDataParameter.ActualValue.Clone(); 194 return DecodeSchedule(solution, jobData); 195 } 196 197 public static Schedule DecodeSchedule(PRVEncoding solution, ItemList<Job> jobData) { 198 var random = new FastRandom(solution.RandomSeed); 199 var jobs = (ItemList<Job>)jobData.Clone(); 208 200 var resultingSchedule = new Schedule(jobs[0].Tasks.Count); 209 201 … … 228 220 //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..) 229 221 //Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector [currentDecisionIndex++], solution.NrOfRules.Value); 230 Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector[minimal.JobNr], solution.NrOfRules, resultingSchedule, jobs);222 Task selectedTask = SelectTaskFromConflictSet(conflictSet, solution.PriorityRulesVector[minimal.JobNr], resultingSchedule, jobs, random); 231 223 232 224 //STEP 4 - Adding the selected operation to the current schedule
Note: See TracChangeset
for help on using the changeset viewer.