Changeset 8887 for trunk/sources/HeuristicLab.Problems.Scheduling
- Timestamp:
- 11/11/12 22:57:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Scheduling/3.3
- Files:
-
- 7 added
- 1 deleted
- 13 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 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/MakespanEvaluator.cs
r8882 r8887 30 30 [Item("Makespan Evaluator", "Represents an evaluator using the maximum makespan of a schedule.")] 31 31 [StorableClass] 32 public class MakespanEvaluator : SchedulingEvaluator { 32 public class MakespanEvaluator : ScheduleEvaluator { 33 33 34 [StorableConstructor] 34 35 protected MakespanEvaluator(bool deserializing) : base(deserializing) { } 35 protected MakespanEvaluator(MakespanEvaluator original, Cloner cloner) 36 : base(original, cloner) { 36 protected MakespanEvaluator(MakespanEvaluator original, Cloner cloner) : base(original, cloner) {} 37 public MakespanEvaluator() 38 : base() { 39 QualityParameter.ActualName = "Makespan"; 37 40 } 41 38 42 public override IDeepCloneable Clone(Cloner cloner) { 39 43 return new MakespanEvaluator(this, cloner); 40 44 } 41 42 public MakespanEvaluator() : base() { }43 45 44 46 public static double GetMakespan(Schedule schedule) { … … 46 48 } 47 49 48 protected override DoubleValue Evaluate(Schedule schedule) { 49 return new DoubleValue(GetMakespan(schedule)); 50 } 51 52 public override IOperation Apply() { 53 return base.Apply(); 50 protected override double Evaluate(Schedule schedule) { 51 return GetMakespan(schedule); 54 52 } 55 53 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/MeanTardinessEvaluator.cs
r8882 r8887 32 32 [Item("Mean tardiness Evaluator", "Represents an evaluator using the mean tardiness of a schedule.")] 33 33 [StorableClass] 34 public class MeanTardinessEvaluator : Schedul ingEvaluator, IJSSPOperator {34 public class MeanTardinessEvaluator : ScheduleEvaluator, IJSSPOperator { 35 35 36 36 [StorableConstructor] … … 50 50 : base() { 51 51 Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.")); 52 QualityParameter.ActualName = "MeanTardiness"; 52 53 } 53 54 … … 58 59 } 59 60 60 protected override DoubleValue Evaluate(Schedule schedule) {61 return new DoubleValue(GetMeanTardiness(schedule, JobDataParameter.ActualValue));61 protected override double Evaluate(Schedule schedule) { 62 return GetMeanTardiness(schedule, JobDataParameter.ActualValue); 62 63 } 63 64 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Evaluators/SchedulingEvaluator.cs
r8882 r8887 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 31 namespace HeuristicLab.Problems.Scheduling { 32 [Item("SchedulingEvaluator", "First applies the decoder operator to obtain a schedule from an encoding and then applies the evaluator to obtain a quality.")] 33 [StorableClass] 34 public class SchedulingEvaluator : SingleSuccessorOperator, ISchedulingEvaluator { 30 35 31 namespace HeuristicLab.Problems.Scheduling { 32 [Item("Scheduling Evaluator", "Represents a evaluator class for standard scheduling problems.")] 33 [StorableClass] 34 public abstract class SchedulingEvaluator : SingleSuccessorOperator, IScheduleEvaluator { 36 public IValueLookupParameter<IScheduleDecoder> ScheduleDecoderParameter { 37 get { return (IValueLookupParameter<IScheduleDecoder>) Parameters["ScheduleDecoder"]; } 38 } 39 ILookupParameter<IScheduleDecoder> ISchedulingEvaluator.ScheduleDecoderParameter { 40 get { return ScheduleDecoderParameter; } 41 } 42 public IValueLookupParameter<IScheduleEvaluator> ScheduleEvaluatorParameter { 43 get { return (IValueLookupParameter<IScheduleEvaluator>) Parameters["ScheduleEvaluator"]; } 44 } 45 ILookupParameter<IScheduleEvaluator> ISchedulingEvaluator.ScheduleEvaluatorParameter { 46 get { return ScheduleEvaluatorParameter; } 47 } 48 public ILookupParameter<DoubleValue> QualityParameter { 49 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 50 } 51 35 52 [StorableConstructor] 36 53 protected SchedulingEvaluator(bool deserializing) : base(deserializing) { } 37 protected SchedulingEvaluator(SchedulingEvaluator original, Cloner cloner) 38 : base(original, cloner) { 54 protected SchedulingEvaluator(SchedulingEvaluator original, Cloner cloner) : base(original, cloner) { } 55 public SchedulingEvaluator() 56 : base() { 57 Parameters.Add(new ValueLookupParameter<IScheduleDecoder>("ScheduleDecoder", "The decoding operator that is used to calculate a schedule from the used representation.")); 58 Parameters.Add(new ValueLookupParameter<IScheduleEvaluator>("ScheduleEvaluator", "The actual schedule evaluation operator.")); 59 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution.")); 60 QualityParameter.Hidden = true; 39 61 } 40 62 41 public ILookupParameter<IRandom> RandomParameter { 42 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 43 } 44 public ILookupParameter<DoubleValue> QualityParameter { 45 get { 46 if (Parameters.ContainsKey("Quality")) 47 return (ILookupParameter<DoubleValue>)Parameters["Quality"]; 48 else 49 return null; 50 } 51 } 52 public ILookupParameter<Schedule> ScheduleParameter { 53 get { return (ILookupParameter<Schedule>)Parameters["Schedule"]; } 63 public override IDeepCloneable Clone(Cloner cloner) { 64 return new SchedulingEvaluator(this, cloner); 54 65 } 55 66 56 public SchedulingEvaluator() 57 : base() { 58 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution.")); 59 Parameters.Add(new LookupParameter<Schedule>("Schedule", "The decoded scheduling solution represented as generalized schedule.")); 60 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator.")); 61 } 67 public override IOperation Apply() { 68 var decoder = ScheduleDecoderParameter.ActualValue; 69 var evaluator = ScheduleEvaluatorParameter.ActualValue; 70 if (evaluator == null) throw new InvalidOperationException("A ScheduleEvaluator could not be found."); 62 71 63 protected abstract DoubleValue Evaluate(Schedule schedule); 64 65 public override IOperation Apply() { 66 Schedule schedule = ScheduleParameter.ActualValue; 67 QualityParameter.ActualValue = Evaluate(schedule); 68 return base.Apply(); 72 var operations = new OperationCollection(base.Apply()); 73 operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator)); 74 if (decoder != null) // decode before evaluating 75 operations.Insert(0, ExecutionContext.CreateChildOperation(decoder)); 76 return operations; 69 77 } 70 78 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/HeuristicLab.Problems.Scheduling-3.3.csproj
r8882 r8887 107 107 <Compile Include="Analyzers\BestSchedulingSolutionAnalyzer.cs" /> 108 108 <Compile Include="Analyzers\SchedulingAnalyzer.cs" /> 109 <Compile Include="Decoders\JSMForcingStrategy.cs" /> 109 110 <Compile Include="Decoders\JSMDecoder.cs" /> 111 <Compile Include="Decoders\JSMDecodingErrorPolicy.cs" /> 110 112 <Compile Include="Decoders\JSMDecodingErrorPolicyTypes.cs" /> 111 113 <Compile Include="Decoders\JSMForcingStrategyTypes.cs" /> 112 114 <Compile Include="Decoders\PRVDecoder.cs" /> 113 115 <Compile Include="Decoders\PWRDecoder.cs" /> 116 <Compile Include="Decoders\ScheduleDecoder.cs" /> 114 117 <Compile Include="Evaluators\MeanTardinessEvaluator.cs" /> 115 118 <Compile Include="Evaluators\MakespanEvaluator.cs" /> 119 <Compile Include="Evaluators\ScheduleEvaluator.cs" /> 120 <Compile Include="Interfaces\IJSSPOperator.cs" /> 121 <Compile Include="Interfaces\IScheduleDecoder.cs" /> 122 <Compile Include="Interfaces\ISchedulingEvaluator.cs" /> 123 <Compile Include="Interfaces\IScheduleEvaluator.cs" /> 124 <Compile Include="JobShopSchedulingProblem.cs" /> 116 125 <Compile Include="Evaluators\SchedulingEvaluator.cs" /> 117 <Compile Include="Interfaces\IJSSPOperator.cs" />118 <Compile Include="JobShopSchedulingProblem.cs" />119 <Compile Include="Evaluators\SchedulingEvaluationAlgorithm.cs" />120 126 <Compile Include="SchedulingProblem.cs" /> 121 127 <Compile Include="Plugin.cs" /> -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Interfaces/IJSSPOperator.cs
r6475 r8887 1 using HeuristicLab.Core; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HeuristicLab.Core; 2 23 using HeuristicLab.Encodings.ScheduleEncoding; 3 24 -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
r8886 r8887 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 71 73 #endregion 72 74 75 public string Filename { get; set; } 76 public override Image ItemImage { 77 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 78 } 79 73 80 #region Parameter Properties 74 public ValueParameter<ItemList<Job>> JobDataParameter {75 get { return ( ValueParameter<ItemList<Job>>)Parameters["JobData"]; }81 public IValueParameter<ItemList<Job>> JobDataParameter { 82 get { return (IValueParameter<ItemList<Job>>)Parameters["JobData"]; } 76 83 } 77 84 public OptionalValueParameter<Schedule> BestKnownSolutionParameter { … … 85 92 get { return (IFixedValueParameter<IntValue>)Parameters["Resources"]; } 86 93 } 87 public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter { 88 get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; } 94 public IValueParameter<IScheduleEvaluator> ScheduleEvaluatorParameter { 95 get { return (IValueParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; } 96 } 97 public OptionalValueParameter<IScheduleDecoder> ScheduleDecoderParameter { 98 get { return (OptionalValueParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; } 89 99 } 90 100 #endregion … … 107 117 set { ResourcesParameter.Value.Value = value; } 108 118 } 109 public SchedulingEvaluator SolutionEvaluator { 110 get { return SolutionEvaluatorParameter.Value; } 111 set { SolutionEvaluatorParameter.Value = value; } 112 } 113 public override Image ItemImage { 114 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 115 } 116 public string Filename { get; set; } 117 #endregion 118 119 public JobShopSchedulingProblem() 120 : base(new SchedulingEvaluationAlgorithm(), new JSMRandomCreator()) { 121 Parameters.Add(new ValueParameter<ItemList<Job>>("JobData", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.", new ItemList<Job>())); 122 Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance.")); 123 124 Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 125 Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue())); 126 Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator())); 127 128 InitializeOperators(); 129 Load(DefaultInstance); 130 } 119 public IScheduleEvaluator ScheduleEvaluator { 120 get { return ScheduleEvaluatorParameter.Value; } 121 set { ScheduleEvaluatorParameter.Value = value; } 122 } 123 public IScheduleDecoder ScheduleDecoder { 124 get { return ScheduleDecoderParameter.Value; } 125 set { ScheduleDecoderParameter.Value = value; } 126 } 127 #endregion 131 128 132 129 [StorableConstructor] … … 134 131 private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner) 135 132 : base(original, cloner) { 136 } 133 RegisterEventHandlers(); 134 } 135 public JobShopSchedulingProblem() 136 : base(new SchedulingEvaluator(), new JSMRandomCreator()) { 137 Parameters.Add(new ValueParameter<ItemList<Job>>("JobData", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.", new ItemList<Job>())); 138 Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance.")); 139 140 Parameters.Add(new FixedValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue())); 141 Parameters.Add(new FixedValueParameter<IntValue>("Resources", "The number of resources used in this JSSP instance.", new IntValue())); 142 Parameters.Add(new ValueParameter<IScheduleEvaluator>("ScheduleEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator())); 143 Parameters.Add(new OptionalValueParameter<IScheduleDecoder>("ScheduleDecoder", "The operator that decodes the representation and creates a schedule.", new JSMDecoder())); 144 145 EvaluatorParameter.GetsCollected = false; 146 EvaluatorParameter.Hidden = true; 147 ScheduleDecoderParameter.Hidden = true; 148 149 InitializeOperators(); 150 Load(DefaultInstance); 151 RegisterEventHandlers(); 152 } 153 137 154 public override IDeepCloneable Clone(Cloner cloner) { 138 155 return new JobShopSchedulingProblem(this, cloner); 156 } 157 158 [StorableHook(HookType.AfterDeserialization)] 159 private void AfterDeserialization() { 160 RegisterEventHandlers(); 161 } 162 163 private void RegisterEventHandlers() { 164 ScheduleEvaluatorParameter.ValueChanged += ScheduleEvaluatorParameter_ValueChanged; 165 ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 166 SolutionCreatorParameter.ValueChanged += SolutionCreatorParameter_ValueChanged; 167 SolutionCreator.ScheduleEncodingParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 168 ScheduleDecoderParameter.ValueChanged += ScheduleDecoderParameter_ValueChanged; 169 if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 139 170 } 140 171 … … 142 173 protected override void OnSolutionCreatorChanged() { 143 174 InitializeOperators(); 175 } 176 protected override void OnEvaluatorChanged() { 177 base.OnEvaluatorChanged(); 178 ParameterizeOperators(); 179 } 180 private void ScheduleEvaluatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 181 ScheduleEvaluator.QualityParameter.ActualNameChanged += ScheduleEvaluator_QualityParameter_ActualNameChanged; 182 ParameterizeOperators(); 183 } 184 private void ScheduleEvaluator_QualityParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 185 ParameterizeOperators(); 186 } 187 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 188 SolutionCreator.ScheduleEncodingParameter.ActualNameChanged += SolutionCreator_SchedulingEncodingParameter_ActualNameChanged; 189 ParameterizeOperators(); 190 } 191 private void SolutionCreator_SchedulingEncodingParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 192 ParameterizeOperators(); 193 } 194 private void ScheduleDecoderParameter_ValueChanged(object sender, EventArgs eventArgs) { 195 if (ScheduleDecoder != null) ScheduleDecoder.ScheduleParameter.ActualNameChanged += ScheduleDecoder_ScheduleParameter_ActualNameChanged; 196 ParameterizeOperators(); 197 } 198 private void ScheduleDecoder_ScheduleParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 199 ParameterizeOperators(); 144 200 } 145 201 #endregion … … 156 212 } 157 213 158 if (data.BestKnownQuality.HasValue) BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value); 159 else BestKnownQuality = null; 214 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 160 215 if (data.BestKnownSchedule != null) { 161 216 var enc = new JSMEncoding(); … … 168 223 } 169 224 BestKnownSolution = new JSMDecoder().CreateScheduleFromEncoding(enc, jobData); 170 if (S olutionEvaluator is MeanTardinessEvaluator)225 if (ScheduleEvaluator is MeanTardinessEvaluator) 171 226 BestKnownQuality = new DoubleValue(MeanTardinessEvaluator.GetMeanTardiness(BestKnownSolution, jobData)); 172 else if (S olutionEvaluator is MakespanEvaluator)227 else if (ScheduleEvaluator is MakespanEvaluator) 173 228 BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution)); 174 229 } … … 208 263 ApplyEncoding(); 209 264 Operators.Add(new BestSchedulingSolutionAnalyzer()); 265 ParameterizeOperators(); 210 266 } 211 267 … … 213 269 if (SolutionCreator.GetType() == typeof(JSMRandomCreator)) { 214 270 Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>()); 215 var decoder = new JSMDecoder(); 216 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 271 ScheduleDecoder = new JSMDecoder(); 217 272 } else if (SolutionCreator.GetType() == typeof(PRVRandomCreator)) { 218 273 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>()); 219 var decoder = new PRVDecoder(); 220 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 274 ScheduleDecoder = new PRVDecoder(); 221 275 } else if (SolutionCreator.GetType() == typeof(PWRRandomCreator)) { 222 276 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>()); 223 var decoder = new PWRDecoder(); 224 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph(decoder); 277 ScheduleDecoder = new PWRDecoder(); 225 278 } else if (SolutionCreator.GetType() == typeof(DirectScheduleRandomCreator)) { 226 279 Operators.AddRange(ApplicationManager.Manager.GetInstances<IDirectScheduleOperator>()); 227 ((SchedulingEvaluationAlgorithm)EvaluatorParameter.ActualValue).InitializeOperatorGraph<Schedule>(); 280 ScheduleDecoder = null; 281 } 282 } 283 284 private void ParameterizeOperators() { 285 Evaluator.ScheduleDecoderParameter.ActualName = ScheduleDecoderParameter.Name; 286 Evaluator.ScheduleDecoderParameter.Hidden = true; 287 Evaluator.ScheduleEvaluatorParameter.ActualName = ScheduleEvaluatorParameter.Name; 288 Evaluator.ScheduleEvaluatorParameter.Hidden = true; 289 Evaluator.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 290 Evaluator.QualityParameter.Hidden = true; 291 292 if (ScheduleDecoder != null) 293 ScheduleDecoder.ScheduleEncodingParameter.ActualName = SolutionCreator.ScheduleEncodingParameter.ActualName; 294 295 if (ScheduleDecoder != null) { 296 ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 297 ScheduleEvaluator.ScheduleParameter.Hidden = true; 298 } else if (SolutionCreator is DirectScheduleRandomCreator) { 299 var directEvaluator = (DirectScheduleRandomCreator)SolutionCreator; 300 ScheduleEvaluator.ScheduleParameter.ActualName = directEvaluator.ScheduleEncodingParameter.ActualName; 301 ScheduleEvaluator.ScheduleParameter.Hidden = true; 302 } else { 303 ScheduleEvaluator.ScheduleParameter.ActualName = ScheduleEvaluator.ScheduleParameter.Name; 304 ScheduleEvaluator.ScheduleParameter.Hidden = false; 305 } 306 307 foreach (var op in Operators.OfType<IScheduleManipulator>()) { 308 op.ScheduleEncodingParameter.ActualName = SolutionCreator.ScheduleEncodingParameter.ActualName; 309 op.ScheduleEncodingParameter.Hidden = true; 310 } 311 312 foreach (var op in Operators.OfType<IScheduleCrossover>()) { 313 op.ChildParameter.ActualName = SolutionCreator.ScheduleEncodingParameter.ActualName; 314 op.ChildParameter.Hidden = true; 315 op.ParentsParameter.ActualName = SolutionCreator.ScheduleEncodingParameter.ActualName; 316 op.ParentsParameter.Hidden = true; 317 } 318 319 foreach (var op in Operators.OfType<BestSchedulingSolutionAnalyzer>()) { 320 op.QualityParameter.ActualName = ScheduleEvaluator.QualityParameter.ActualName; 321 if (ScheduleDecoder != null) { 322 op.ScheduleParameter.ActualName = ScheduleDecoder.ScheduleParameter.ActualName; 323 op.ScheduleParameter.Hidden = true; 324 } else if (SolutionCreator is DirectScheduleRandomCreator) { 325 op.ScheduleParameter.ActualName = ((DirectScheduleRandomCreator)SolutionCreator).ScheduleEncodingParameter.ActualName; 326 op.ScheduleParameter.Hidden = true; 327 } else { 328 op.ScheduleParameter.ActualName = op.ScheduleParameter.Name; 329 op.ScheduleParameter.Hidden = false; 330 } 228 331 } 229 332 } -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Plugin.cs.frame
r8882 r8887 23 23 24 24 namespace HeuristicLab.Problems.Scheduling { 25 [Plugin("HeuristicLab.Problems.Scheduling", "3.3. 3.$WCREV$")]25 [Plugin("HeuristicLab.Problems.Scheduling", "3.3.7.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Scheduling-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Properties/AssemblyInfo.cs.frame
r8759 r8887 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.3.0.0")] 55 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]55 [assembly: AssemblyFileVersion("3.3.7.$WCREV$")] -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/SchedulingProblem.cs
r8603 r8887 29 29 [Item("SchedulingProblem", "Abstract class that represents a Scheduling Problem")] 30 30 [StorableClass] 31 public abstract class SchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<ISchedul eEvaluationAlgorithm, IScheduleCreator> {31 public abstract class SchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<ISchedulingEvaluator, IScheduleCreator> { 32 32 [StorableConstructor] 33 33 protected SchedulingProblem(bool deserializing) : base(deserializing) { } 34 protected SchedulingProblem(SchedulingProblem original, Cloner cloner) 35 : base(original, cloner) { 36 } 37 38 protected SchedulingProblem(IScheduleEvaluationAlgorithm se, IScheduleCreator sc) : base(se, sc) { } 39 34 protected SchedulingProblem(SchedulingProblem original, Cloner cloner) : base(original, cloner) { } 35 protected SchedulingProblem(ISchedulingEvaluator evaluator, IScheduleCreator creator) : base(evaluator, creator) { } 40 36 } 41 37 }
Note: See TracChangeset
for help on using the changeset viewer.