Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/10/11 16:18:44 (13 years ago)
Author:
jhelm
Message:

#1329: Applied suggestions from codereview. Added unit-tests. Renamed encoding-project.

Location:
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3

    • Property svn:ignore
      •  

        old new  
        22bin
        33obj
         4HeuristicLab.Problems.Scheduling-3.3.csproj.user
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Decoders/JSMDecoder.cs

    r6364 r6406  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
     24using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Common;
    29 using HeuristicLab.Data;
    3026using HeuristicLab.Encodings.PermutationEncoding;
     27using HeuristicLab.Encodings.ScheduleEncoding;
     28using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
    3129using HeuristicLab.Optimization;
    3230using HeuristicLab.Parameters;
    33 using HeuristicLab.Encodings.SchedulingEncoding.JobSequenceMatrix;
    34 using HeuristicLab.Encodings.SchedulingEncoding;
    35 using HeuristicLab.Problems.Scheduling.Interfaces;
     31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3632
    37 namespace HeuristicLab.Problems.Scheduling.Decoders {
    38   [Item("Job Sequence Matrix Decoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequence Matrix.")]
     33namespace HeuristicLab.Problems.Scheduling {
     34  [Item("JobSequenceMatrixDecoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequence Matrix.")]
    3935  [StorableClass]
    40   public class JSMDecoder : SchedulingDecoder<JSMEncoding>, IStochasticOperator, IJSSPOperator {
    41     [StorableConstructor]
    42     protected JSMDecoder(bool deserializing) : base(deserializing) { }
    43     protected JSMDecoder(JSMDecoder original, Cloner cloner)
    44       : base(original, cloner) {
    45         this.resultingSchedule = cloner.Clone(original.resultingSchedule);
    46         this.jobs = cloner.Clone(original.jobs);
    47         this.decodingErrorPolicy = original.decodingErrorPolicy;
    48         this.forcingStrategy = original.forcingStrategy;
    49     }
    50     public override IDeepCloneable Clone(Cloner cloner) {
    51       return new JSMDecoder(this, cloner);
    52     }
    53 
     36  public class JSMDecoder : ScheduleDecoder<JSMEncoding>, IStochasticOperator, IJSSPOperator {
    5437    public ILookupParameter<IRandom> RandomParameter {
    5538      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    7053
    7154    [Storable]
    72     private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing; 
     55    private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing;
    7356    #endregion
     57
     58    [StorableConstructor]
     59    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    }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      return new JSMDecoder(this, cloner);
     69    }
    7470
    7571    public JSMDecoder()
     
    7773      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    7874      Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the Schedulingproblem - Instance."));
     75      ScheduleEncodingParameter.ActualName = "JobSequenceMatrix";
    7976    }
    8077
    81    
     78
    8279    private Task SelectTaskFromConflictSet(int conflictedResourceNr, int progressOnConflictedResource, ItemList<Task> conflictSet, ItemList<Permutation> jsm) {
    8380      if (conflictSet.Count == 1)
    8481        return conflictSet[0];
    85      
     82
    8683      //get solutionCandidate from jobSequencingMatrix
    8784      int solutionCandidateJobNr = jsm[conflictedResourceNr][progressOnConflictedResource];
     
    104101    }
    105102    private Task ApplyDecodingErrorPolicy(ItemList<Task> conflictSet, Permutation resource, int progress) {
    106       if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) { 
     103      if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
    107104        //Random
    108105        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
     
    118115        }
    119116        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
    120       }   
     117      }
    121118    }
    122119    private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) {
     
    132129          asList.Insert(progressOnResource, newResolution);
    133130        } else {
    134           asList.Insert(progressOnResource, newResolution); 
     131          asList.Insert(progressOnResource, newResolution);
    135132          asList.RemoveAt(newResolutionIndex);
    136133        }
    137         jsm[conflictedResource] = new Permutation (PermutationTypes.Absolute, asList.ToArray<int>());
    138       } 
     134        jsm[conflictedResource] = new Permutation(PermutationTypes.Absolute, asList.ToArray<int>());
     135      }
    139136    }
    140137
     
    143140
    144141      jobs = (ItemList<Job>)jobData.Clone();
    145       resultingSchedule = new Schedule(new IntValue(jobs[0].Tasks.Count));
     142      resultingSchedule = new Schedule(jobs[0].Tasks.Count);
    146143
    147144      //Reset scheduled tasks in result
     
    186183    public override IOperation Apply() {
    187184      return base.Apply();
    188     }   
     185    }
    189186  }
    190187}
Note: See TracChangeset for help on using the changeset viewer.