Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/08/15 14:31:05 (9 years ago)
Author:
mkommend
Message:

#2521: Adapted decoders for SchedulingProblem.

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  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.ScheduleEncoding;
    26 using HeuristicLab.Optimization;
    27 using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 
    30 namespace HeuristicLab.Problems.Scheduling {
     28using HeuristicLab.Random;
     29
     30namespace HeuristicLab.Encodings.ScheduleEncoding {
    3131  [Item("JobSequencingMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")]
    3232  [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 {
    4234    #region Priority Rules
    4335    //smallest number of remaining tasks
    44     private Task FILORule(ItemList<Task> tasks) {
     36    private static Task FILORule(ItemList<Task> tasks) {
    4537      Task currentResult = tasks[tasks.Count - 1];
    4638      return currentResult;
     
    4840
    4941    //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();
    5244      double currentEST = double.MaxValue;
    5345      foreach (Task t in tasks) {
     
    6254
    6355    //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();
    6658      foreach (Task t in tasks) {
    6759        if (t.Duration < currentResult.Duration)
     
    7264
    7365    //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();
    7668      foreach (Task t in tasks) {
    7769        if (t.Duration > currentResult.Duration)
     
    8274
    8375    //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();
    8678      double currentLargestRemainingProcessingTime = 0;
    8779      foreach (Task t in tasks) {
     
    10092
    10193    //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();
    10496      double currentSmallestRemainingProcessingTime = double.MaxValue;
    10597      foreach (Task t in tasks) {
     
    118110
    119111    //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();
    122114      int currentLargestNrOfRemainingTasks = 0;
    123115      foreach (Task t in tasks) {
     
    136128
    137129    //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();
    140132      int currentSmallestNrOfRemainingTasks = int.MaxValue;
    141133      foreach (Task t in tasks) {
     
    154146
    155147    //first operation in Queue
    156     private Task FIFORule(ItemList<Task> tasks) {
     148    private static Task FIFORule(ItemList<Task> tasks) {
    157149      Task currentResult = tasks[0];
    158150      return currentResult;
     
    160152
    161153    //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)];
    164156      return currentResult;
    165157    }
     
    170162    protected PRVDecoder(bool deserializing) : base(deserializing) { }
    171163    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() { }
    178165
    179166    public override IDeepCloneable Clone(Cloner cloner) {
     
    181168    }
    182169
    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) {
    184171      if (conflictSet.Count == 1)
    185172        return conflictSet[0];
    186173
    187       ruleIndex = ruleIndex % nrOfRules;
     174      //TODO change to property, Encoding parameter?
     175      ruleIndex = ruleIndex % 10;
    188176      switch (ruleIndex) {
    189177        case 0: return FILORule(conflictSet);
     
    196184        case 7: return LORRule(conflictSet, jobs);
    197185        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) {
    204192      var solution = encoding as PRVEncoding;
    205193      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();
    208200      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);
    209201
     
    228220        //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
    229221        //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);
    231223
    232224        //STEP 4 - Adding the selected operation to the current schedule
Note: See TracChangeset for help on using the changeset viewer.