#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.ScheduleEncoding;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.Scheduling {
[Item("SchedulingEvaluator", "First applies the decoder operator to obtain a schedule from an encoding and then applies the evaluator to obtain a quality.")]
[StorableClass]
public class SchedulingEvaluator : InstrumentedOperator, ISchedulingEvaluator {
public IValueLookupParameter ScheduleDecoderParameter {
get { return (IValueLookupParameter)Parameters["ScheduleDecoder"]; }
}
ILookupParameter ISchedulingEvaluator.ScheduleDecoderParameter {
get { return ScheduleDecoderParameter; }
}
public IValueLookupParameter ScheduleEvaluatorParameter {
get { return (IValueLookupParameter)Parameters["ScheduleEvaluator"]; }
}
ILookupParameter ISchedulingEvaluator.ScheduleEvaluatorParameter {
get { return ScheduleEvaluatorParameter; }
}
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
[StorableConstructor]
protected SchedulingEvaluator(bool deserializing) : base(deserializing) { }
protected SchedulingEvaluator(SchedulingEvaluator original, Cloner cloner) : base(original, cloner) { }
public SchedulingEvaluator()
: base() {
Parameters.Add(new ValueLookupParameter("ScheduleDecoder", "The decoding operator that is used to calculate a schedule from the used representation."));
Parameters.Add(new ValueLookupParameter("ScheduleEvaluator", "The actual schedule evaluation operator."));
Parameters.Add(new LookupParameter("Quality", "The quality value aka fitness value of the solution."));
QualityParameter.Hidden = true;
}
public override IDeepCloneable Clone(Cloner cloner) {
return new SchedulingEvaluator(this, cloner);
}
public override IOperation InstrumentedApply() {
var decoder = ScheduleDecoderParameter.ActualValue;
var evaluator = ScheduleEvaluatorParameter.ActualValue;
if (evaluator == null) throw new InvalidOperationException("A ScheduleEvaluator could not be found.");
var operations = new OperationCollection(base.InstrumentedApply());
operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator));
if (decoder != null) // decode before evaluating
operations.Insert(0, ExecutionContext.CreateChildOperation(decoder));
return operations;
}
}
}