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/JobShopSchedulingProblem.cs

    r6364 r6406  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
     24using System.IO;
     25using HeuristicLab.Common;
     26using HeuristicLab.Core;
     27using HeuristicLab.Data;
     28using HeuristicLab.Encodings.PermutationEncoding;
     29using HeuristicLab.Encodings.ScheduleEncoding;
     30using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
     31using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
     32using HeuristicLab.Encodings.ScheduleEncoding.PriorityRulesVector;
     33using HeuristicLab.Parameters;
    2634using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Core;
    28 using HeuristicLab.Optimization;
    29 using HeuristicLab.Common;
    30 using System.Drawing;
    31 using HeuristicLab.Data;
    32 using System.IO;
    33 using HeuristicLab.Problems.Scheduling.Evaluators;
    34 using HeuristicLab.Parameters;
    35 using HeuristicLab.Problems.Scheduling.Analyzers;
    3635using HeuristicLab.PluginInfrastructure;
    37 using HeuristicLab.Encodings.SchedulingEncoding;
    38 using HeuristicLab.Encodings.SchedulingEncoding.Interfaces;
    39 using HeuristicLab.Encodings.SchedulingEncoding.JobSequenceMatrix;
    40 using HeuristicLab.Encodings.PermutationEncoding;
    41 using HeuristicLab.Encodings.SchedulingEncoding.PriorityRulesVector;
    42 using HeuristicLab.Encodings.SchedulingEncoding.PermutationWithRepetition;
    43 using HeuristicLab.Problems.Scheduling.Decoders;
    4436
    4537namespace HeuristicLab.Problems.Scheduling {
     
    4840  [StorableClass]
    4941  public sealed class JobShopSchedulingProblem : SchedulingProblem {
     42    #region Parameter Properties
     43    public ValueParameter<ItemList<Job>> JobDataParameter {
     44      get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; }
     45    }
     46    public OptionalValueParameter<Schedule> BestKnownSolutionParameter {
     47      get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; }
     48    }
     49
     50    public ValueParameter<IntValue> JobsParameter {
     51      get { return (ValueParameter<IntValue>)Parameters["Jobs"]; }
     52    }
     53    public ValueParameter<IntValue> ResourcesParameter {
     54      get { return (ValueParameter<IntValue>)Parameters["Resources"]; }
     55    }
     56    public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter {
     57      get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; }
     58    }
     59    public ValueParameter<BoolValue> DueDatesParameter {
     60      get { return (ValueParameter<BoolValue>)Parameters["DueDates"]; }
     61    }
     62    #endregion
     63
     64    #region Properties
     65    public ItemList<Job> JobData {
     66      get { return JobDataParameter.Value; }
     67      set { JobDataParameter.Value = value; }
     68    }
     69    public Schedule BestKnownSolution {
     70      get { return BestKnownSolutionParameter.Value; }
     71      set { BestKnownSolutionParameter.Value = value; }
     72    }
     73    public IntValue Jobs {
     74      get { return JobsParameter.Value; }
     75      set { JobsParameter.Value = value; }
     76    }
     77    public IntValue Resources {
     78      get { return ResourcesParameter.Value; }
     79      set { ResourcesParameter.Value = value; }
     80    }
     81    public SchedulingEvaluator SolutionEvaluator {
     82      get { return SolutionEvaluatorParameter.Value; }
     83      set { SolutionEvaluatorParameter.Value = value; }
     84    }
     85    public BoolValue DueDates {
     86      get { return DueDatesParameter.Value; }
     87      set { DueDatesParameter.Value = value; }
     88    }
     89    #endregion
     90
     91    public JobShopSchedulingProblem()
     92      : base(new SchedulingEvaluationAlgorithm(), new JSMRandomCreator()) {
     93      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>()));
     94      Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));
     95
     96      Parameters.Add(new ValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue()));
     97      Parameters.Add(new ValueParameter<IntValue>("Resources", "The number of resources used this JSSP instance.", new IntValue()));
     98      Parameters.Add(new ValueParameter<BoolValue>("DueDates", "Determines whether the problem instance uses due dates or not.", new BoolValue()));
     99      Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));
     100
     101      InitializeOperators();
     102      InitializeProblemInstance();
     103    }
     104
    50105    [StorableConstructor]
    51106    private JobShopSchedulingProblem(bool deserializing) : base(deserializing) { }
    52107    private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner)
    53108      : base(original, cloner) {
    54       this.Jobs = cloner.Clone(original.Jobs);
    55       this.Resources = cloner.Clone(original.Resources);
    56       this.JobData = cloner.Clone(original.JobData);
    57       this.SolutionEvaluator = cloner.Clone(original.SolutionEvaluator);
    58       this.DueDates = cloner.Clone(original.DueDates);
    59109    }
    60110    public override IDeepCloneable Clone(Cloner cloner) {
    61111      return new JobShopSchedulingProblem(this, cloner);
    62     }
    63 
    64 
    65     #region Parameter Properties
    66     public ValueParameter<ItemList<Job>> JobDataParameter {
    67       get { return (ValueParameter<ItemList<Job>>)Parameters["JobData"]; }
    68     }
    69     public OptionalValueParameter<Schedule> BestKnownSolutionParameter {
    70       get { return (OptionalValueParameter<Schedule>)Parameters["BestKnownSolution"]; }
    71     }
    72 
    73     public ValueParameter<IntValue> JobsParameter {
    74       get { return (ValueParameter<IntValue>)Parameters["Jobs"]; }
    75     }
    76     public ValueParameter<IntValue> ResourcesParameter {
    77       get { return (ValueParameter<IntValue>)Parameters["Resources"]; }
    78     }
    79     public ValueParameter<SchedulingEvaluator> SolutionEvaluatorParameter {
    80       get { return (ValueParameter<SchedulingEvaluator>)Parameters["SolutionEvaluator"]; }
    81     }
    82     public ValueParameter<BoolValue> DueDatesParameter {
    83       get { return (ValueParameter<BoolValue>)Parameters["DueDates"]; }
    84     }
    85     #endregion
    86 
    87     #region Properties
    88     public ItemList<Job> JobData {
    89       get { return JobDataParameter.Value; }
    90       set { JobDataParameter.Value = value; }
    91     }
    92     public Schedule BestKnownSolution {
    93       get { return BestKnownSolutionParameter.Value; }
    94       set { BestKnownSolutionParameter.Value = value; }
    95     }
    96     public IntValue Jobs {
    97       get { return JobsParameter.Value; }
    98       set { JobsParameter.Value = value; }
    99     }
    100     public IntValue Resources {
    101       get { return ResourcesParameter.Value; }
    102       set { ResourcesParameter.Value = value; }
    103     }
    104     public SchedulingEvaluator SolutionEvaluator {
    105       get { return SolutionEvaluatorParameter.Value; }
    106       set { SolutionEvaluatorParameter.Value = value; }
    107     }
    108     public BoolValue DueDates {
    109       get { return DueDatesParameter.Value; }
    110       set { DueDatesParameter.Value = value; }
    111     }
    112     #endregion
    113 
    114 
    115     public JobShopSchedulingProblem()
    116       : base(new SchedulingEvaluationAlgorithm (), new JSMRandomCreator ()) {
    117       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>()));
    118       Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));
    119 
    120       Parameters.Add(new ValueParameter<IntValue>("Jobs", "The number of jobs used in this JSSP instance.", new IntValue()));
    121       Parameters.Add(new ValueParameter<IntValue>("Resources", "The number of resources used this JSSP instance.", new IntValue()));
    122       Parameters.Add(new ValueParameter<BoolValue>("DueDates", "Determines whether the problem instance uses due dates or not.", new BoolValue()));
    123       Parameters.Add(new ValueParameter<SchedulingEvaluator>("SolutionEvaluator", "The evaluator used to determine the quality of a solution.", new MakespanEvaluator()));
    124 
    125       InitializeOperators();
    126       InitializeProblemInstance();
    127112    }
    128113
     
    131116      InitializeOperators();
    132117    }
     118
     119    protected override void OnEvaluatorChanged() {
     120      base.OnEvaluatorChanged();
     121    }
    133122    #endregion
    134123
    135124    #region Helpers
    136     private void InitializeProblemInstance () {
    137       Jobs = new IntValue (10);
    138       Resources = new IntValue (10);
    139       BestKnownQuality = new DoubleValue (930);
     125    private void InitializeProblemInstance() {
     126      Jobs = new IntValue(10);
     127      Resources = new IntValue(10);
     128      BestKnownQuality = new DoubleValue(930);
    140129      JobData = new ItemList<Job>();
    141130      List<string> data = new List<string>
     
    167156      if (SolutionCreator.GetType().Equals(typeof(JSMRandomCreator))) {
    168157        Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>());
    169         ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(new JSMDecoder());
     158        JSMDecoder decoder = new JSMDecoder();
     159        ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(decoder);
    170160      } else {
    171161        if (SolutionCreator.GetType().Equals(typeof(PRVRandomCreator))) {
    172162          Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>());
    173           ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(new PRVDecoder());
     163          PRVDecoder decoder = new PRVDecoder();
     164          ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(decoder);
    174165        } else {
    175166          if (SolutionCreator.GetType().Equals(typeof(PWRRandomCreator))) {
    176167            Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>());
    177             ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(new PWRDecoder());
     168            PWRDecoder decoder = new PWRDecoder();
     169            ((SchedulingEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(decoder);
    178170          }
    179171        }
     
    197189    }
    198190    private int[] GetIntArray(List<string> data) {
    199       int[] arr = new int [data.Count];
    200       for (int i = 0; i < data.Count; i++ ) {
     191      int[] arr = new int[data.Count];
     192      for (int i = 0; i < data.Count; i++) {
    201193        arr[i] = Int32.Parse(data[i]);
    202194      }
    203195      return arr;
    204196    }
    205     private Job CreateJobFromData (List<string> data, int jobCount)  {
     197    private Job CreateJobFromData(List<string> data, int jobCount) {
    206198      DoubleValue dueDate = null;
    207199      int dataCount = data.Count;
     
    233225        if (data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) {
    234226          int jobCount = 0;
    235           Jobs = new IntValue (Int32.Parse(data[0]));
    236           Resources = new IntValue (Int32.Parse(data[1]));
     227          Jobs = new IntValue(Int32.Parse(data[0]));
     228          Resources = new IntValue(Int32.Parse(data[1]));
    237229          //data[2] = bestKnownQuality (double)
    238230          //data[3] = dueDates (0|1)
    239231          DueDates.Value = false;
    240232          if (data.Count > 2)
    241             BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse (data[2]));
     233            BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse(data[2]));
    242234          if (data.Count > 3 && data[3] == "1")
    243235            DueDates.Value = true;
     
    265257      JSMEncoding solution = new JSMEncoding();
    266258      while (!solutionFile.EndOfStream && !solutionFound) {
    267        
     259
    268260        string line = solutionFile.ReadLine();
    269261        List<string> data = SplitString(line);
     
    274266          data = SplitString(line);
    275267          while (data != null && data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) {
    276             Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray (data));
     268            Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray(data));
    277269            solution.JobSequenceMatrix.Add(p);
    278270
Note: See TracChangeset for help on using the changeset viewer.