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