1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022016 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 System;


23  using HeuristicLab.Common;


24  using HeuristicLab.Core;


25  using HeuristicLab.Data;


26  using HeuristicLab.Encodings.PermutationEncoding;


27  using HeuristicLab.Parameters;


28  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;


29 


30  namespace HeuristicLab.Problems.PFSP


31  {


32  /// <summary>


33  /// A base class for operators which evaluate PFSP solutions given in matrix representation


34  /// </summary>


35  [Item("MakeSpanEvaluator", "A base class for operators which evaluate PFSP solutions given in matrix representation.")]


36  [StorableClass]


37  public abstract class MakeSpanEvaluator : PFSPEvaluator, IMakespanEvaluator


38  {


39  public ILookupParameter<Permutation> PermutationParameter { get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } }


40  public ILookupParameter<JobMatrix> JobMatrixParameter { get { return (ILookupParameter<JobMatrix>)Parameters["JobMatrix"]; } }


41  public ILookupParameter<Permutation> BestKnownSolutionParameter { get { return (ILookupParameter<Permutation>)Parameters["BestKnownSolution"]; } }


42  public ILookupParameter<DoubleValue> BestKnownQualityParameter { get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } }


43  [StorableConstructor]


44  protected MakeSpanEvaluator(bool deserializing) : base(deserializing) { }


45  protected MakeSpanEvaluator(MakeSpanEvaluator original, Cloner cloner) : base(original, cloner) { }


46  protected MakeSpanEvaluator()


47  : base()


48  {


49  Parameters.Add(new LookupParameter<Permutation>("Permutation", "The PFSP solution given in matrix representation which should be evaluated."));


50  Parameters.Add(new LookupParameter<JobMatrix>("JobMatrix", "The matrix which contains the jobduration on the machines."));


51  Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The currently best known solution."));


52  Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The currently best known quality."));


53  }


54 


55  [StorableHook(HookType.AfterDeserialization)]


56  private void AfterDeserialization() { }


57 


58  public static double Apply(MakeSpanEvaluator evaluator, DoubleMatrix matrix, Permutation tour)


59  {


60  return evaluator.CalculateMakespan(matrix, tour);


61  }


62 


63  public sealed override IOperation InstrumentedApply()


64  {


65  Permutation p = PermutationParameter.ActualValue;


66  DoubleMatrix c = JobMatrixParameter.ActualValue;


67  if (c == null) throw new InvalidOperationException("No matrix was given.");


68 


69  double makespan = CalculateMakespan(c, p);


70  QualityParameter.ActualValue = new DoubleValue(makespan);


71 


72  if (BestKnownQualityParameter.ActualValue == null  BestKnownQualityParameter.ActualValue.Value > makespan)


73  {


74  BestKnownSolutionParameter.ActualValue = p;


75  BestKnownQualityParameter.ActualValue = new DoubleValue(makespan);


76  }


77  return base.InstrumentedApply();


78  }


79 


80  protected abstract double CalculateMakespan(DoubleMatrix matrix, Permutation perm);


81  }


82  }

