Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/11/12 22:57:09 (12 years ago)
Author:
abeham
Message:

#1329:

  • Moved decoders and evaluators from encoding to problem
  • Removed unnecessary state variables in operators
  • Introduced parameters in interfaces and added wiring code
  • Removed ConcreteScheduleManipulator as it does not perform any manipulation
  • Made ErrorPolicy and ForcingStrategy configurable and added views for them
  • Renamed the SchedulingEvaluationAlgorithm and also converted the AlgorithmOperator to a SingleSuccessorOperator
  • Fixed Plugin- and AssemblyFileVersion
  • Added missing license headers
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  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3435  [Item("JobSequenceMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequence Matrix.")]
    3536  [StorableClass]
    36   public class JSMDecoder : ScheduleDecoder<JSMEncoding>, IStochasticOperator, IJSSPOperator {
     37  public class JSMDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator {
     38
    3739    public ILookupParameter<IRandom> RandomParameter {
    3840      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    4143      get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
    4244    }
     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    }
    4351
    44     #region Private Members
    45     [Storable]
    46     private Schedule resultingSchedule;
     52    private JSMDecodingErrorPolicyTypes DecodingErrorPolicy {
     53      get { return DecodingErrorPolicyParameter.Value.Value; }
     54    }
    4755
    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    }
    5759
    5860    [StorableConstructor]
    5961    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) { }
    6763    public override IDeepCloneable Clone(Cloner cloner) {
    6864      return new JSMDecoder(this, cloner);
     
    7369      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    7470      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
    7574      ScheduleEncodingParameter.ActualName = "JobSequenceMatrix";
    7675    }
    77 
    7876
    7977    private Task SelectTaskFromConflictSet(int conflictedResourceNr, int progressOnConflictedResource, ItemList<Task> conflictSet, ItemList<Permutation> jsm) {
     
    10098      return result;
    10199    }
     100
    102101    private Task ApplyDecodingErrorPolicy(ItemList<Task> conflictSet, Permutation resource, int progress) {
    103       if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
     102      if (DecodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
    104103        //Random
    105104        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
     
    117116      }
    118117    }
     118
    119119    private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) {
    120       if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {
     120      if (ForcingStrategy == JSMForcingStrategyTypes.SwapForcing) {
    121121        //SwapForcing
    122122        jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource];
     
    139139      ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix;
    140140
    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);
    143143
    144144      //Reset scheduled tasks in result
     
    177177    }
    178178
    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");
    180182      return CreateScheduleFromEncoding(solution, JobDataParameter.ActualValue);
    181     }
    182 
    183     public override IOperation Apply() {
    184       return base.Apply();
    185183    }
    186184  }
  • trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/JSMDecodingErrorPolicyTypes.cs

    r8603 r8887  
    1919 */
    2020#endregion
     21
    2122namespace HeuristicLab.Problems.Scheduling {
    2223  public enum JSMDecodingErrorPolicyTypes {
  • trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/PRVDecoder.cs

    r8603 r8887  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3132  [Item("JobSequencingMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")]
    3233  [StorableClass]
    33   public class PRVDecoder : ScheduleDecoder<PRVEncoding>, IStochasticOperator, IJSSPOperator {
     34  public class PRVDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator {
     35
    3436    public ILookupParameter<IRandom> RandomParameter {
    3537      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    3840      get { return (LookupParameter<ItemList<Job>>)Parameters["JobData"]; }
    3941    }
    40 
    41     #region Private Members
    42     [Storable]
    43     private Schedule resultingSchedule;
    44 
    45     [Storable]
    46     private ItemList<Job> jobs;
    47     #endregion
    4842
    4943    #region Priority Rules
     
    5549
    5650    //earliest start time
    57     private Task ESTRule(ItemList<Task> tasks) {
     51    private Task ESTRule(ItemList<Task> tasks, Schedule schedule) {
    5852      Task currentResult = RandomRule(tasks);
    5953      double currentEST = double.MaxValue;
    6054      foreach (Task t in tasks) {
    61         double est = GTAlgorithmUtils.ComputeEarliestStartTime(t, resultingSchedule);
     55        double est = GTAlgorithmUtils.ComputeEarliestStartTime(t, schedule);
    6256        if (est < currentEST) {
    6357          currentEST = est;
     
    8983
    9084    //most work remaining
    91     private Task MWRRule(ItemList<Task> tasks) {
     85    private Task MWRRule(ItemList<Task> tasks, ItemList<Job> jobs) {
    9286      Task currentResult = RandomRule(tasks);
    9387      double currentLargestRemainingProcessingTime = 0;
     
    107101
    108102    //least work remaining
    109     private Task LWRRule(ItemList<Task> tasks) {
     103    private Task LWRRule(ItemList<Task> tasks, ItemList<Job> jobs) {
    110104      Task currentResult = RandomRule(tasks);
    111105      double currentSmallestRemainingProcessingTime = double.MaxValue;
     
    125119
    126120    //most operations remaining
    127     private Task MORRule(ItemList<Task> tasks) {
     121    private Task MORRule(ItemList<Task> tasks, ItemList<Job> jobs) {
    128122      Task currentResult = RandomRule(tasks);
    129123      int currentLargestNrOfRemainingTasks = 0;
     
    143137
    144138    //least operationsremaining
    145     private Task LORRule(ItemList<Task> tasks) {
     139    private Task LORRule(ItemList<Task> tasks, ItemList<Job> jobs) {
    146140      Task currentResult = RandomRule(tasks);
    147141      int currentSmallestNrOfRemainingTasks = int.MaxValue;
     
    176170    [StorableConstructor]
    177171    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) { }
    186173    public PRVDecoder()
    187174      : base() {
     
    191178    }
    192179
    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) {
    194185      if (conflictSet.Count == 1)
    195186        return conflictSet[0];
     
    198189      switch (ruleIndex) {
    199190        case 0: return FILORule(conflictSet);
    200         case 1: return ESTRule(conflictSet);
     191        case 1: return ESTRule(conflictSet, schedule);
    201192        case 2: return SPTRule(conflictSet);
    202193        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);
    207198        case 8: return FIFORule(conflictSet);
    208199        case 9: return RandomRule(conflictSet);
     
    211202    }
    212203
    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);
    216210
    217211      //Reset scheduled tasks in result
     
    235229        //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
    236230        //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);
    238232
    239233        //STEP 4 - Adding the selected operation to the current schedule
     
    248242      return resultingSchedule;
    249243    }
    250 
    251     public override IOperation Apply() {
    252       return base.Apply();
    253     }
    254244  }
    255245}
  • trunk/sources/HeuristicLab.Problems.Scheduling/3.3/Decoders/PWRDecoder.cs

    r8603 r8887  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3132  [Item("PWRDecoder", "An item used to convert a PWR-individual into a generalized schedule.")]
    3233  [StorableClass]
    33   public class PWRDecoder : ScheduleDecoder<PWREncoding>, IStochasticOperator, IJSSPOperator {
     34  public class PWRDecoder : ScheduleDecoder, IStochasticOperator, IJSSPOperator {
     35
    3436    public ILookupParameter<IRandom> RandomParameter {
    3537      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    4143    [StorableConstructor]
    4244    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) { }
    5046    public PWRDecoder()
    5147      : base() {
     
    5551    }
    5652
    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);
    6063      foreach (int jobNr in solution.PermutationWithRepetition) {
    6164        int i = 0;
     
    6871      return resultingSchedule;
    6972    }
    70 
    71     public override IOperation Apply() {
    72       return base.Apply();
    73     }
    7473  }
    7574}
Note: See TracChangeset for help on using the changeset viewer.