[6266] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6266] | 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 |
|
---|
[8887] | 22 | using System;
|
---|
[6406] | 23 | using HeuristicLab.Common;
|
---|
[6266] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[6406] | 26 | using HeuristicLab.Encodings.ScheduleEncoding;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
[15219] | 28 | using HeuristicLab.Optimization;
|
---|
[6266] | 29 | using HeuristicLab.Parameters;
|
---|
[17097] | 30 | using HEAL.Attic;
|
---|
[6266] | 31 |
|
---|
[6406] | 32 | namespace HeuristicLab.Problems.Scheduling {
|
---|
[8887] | 33 | [Item("SchedulingEvaluator", "First applies the decoder operator to obtain a schedule from an encoding and then applies the evaluator to obtain a quality.")]
|
---|
[17097] | 34 | [StorableType("A7AED7B7-C431-4E39-A002-8CBCA6223BCD")]
|
---|
[15219] | 35 | public class SchedulingEvaluator : InstrumentedOperator, ISchedulingEvaluator, IStochasticOperator {
|
---|
[6266] | 36 |
|
---|
[8887] | 37 | public IValueLookupParameter<IScheduleDecoder> ScheduleDecoderParameter {
|
---|
[10507] | 38 | get { return (IValueLookupParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; }
|
---|
[6266] | 39 | }
|
---|
[8887] | 40 | ILookupParameter<IScheduleDecoder> ISchedulingEvaluator.ScheduleDecoderParameter {
|
---|
| 41 | get { return ScheduleDecoderParameter; }
|
---|
| 42 | }
|
---|
| 43 | public IValueLookupParameter<IScheduleEvaluator> ScheduleEvaluatorParameter {
|
---|
[10507] | 44 | get { return (IValueLookupParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; }
|
---|
[8887] | 45 | }
|
---|
| 46 | ILookupParameter<IScheduleEvaluator> ISchedulingEvaluator.ScheduleEvaluatorParameter {
|
---|
| 47 | get { return ScheduleEvaluatorParameter; }
|
---|
| 48 | }
|
---|
[6266] | 49 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
[8887] | 50 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
[6266] | 51 | }
|
---|
[15219] | 52 | // ABE: This parameter exists purely, because some IScheduleDecoders are stochastic...
|
---|
| 53 | // ... which could be solved by letting the algorithm parameterize them ...
|
---|
| 54 | // ... but they have to use the same RNG as the evaluator (due to parallel execution)...
|
---|
| 55 | // ... in particular relevant for Island-GA and ALPS (Local- vs GlobalRandom).
|
---|
| 56 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 57 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 58 | }
|
---|
[6266] | 59 |
|
---|
[8887] | 60 | [StorableConstructor]
|
---|
[17097] | 61 | protected SchedulingEvaluator(StorableConstructorFlag _) : base(_) { }
|
---|
[8887] | 62 | protected SchedulingEvaluator(SchedulingEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
[6406] | 63 | public SchedulingEvaluator()
|
---|
| 64 | : base() {
|
---|
[8887] | 65 | Parameters.Add(new ValueLookupParameter<IScheduleDecoder>("ScheduleDecoder", "The decoding operator that is used to calculate a schedule from the used representation."));
|
---|
| 66 | Parameters.Add(new ValueLookupParameter<IScheduleEvaluator>("ScheduleEvaluator", "The actual schedule evaluation operator."));
|
---|
[6266] | 67 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution."));
|
---|
[15219] | 68 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
|
---|
[8887] | 69 | QualityParameter.Hidden = true;
|
---|
[6266] | 70 | }
|
---|
| 71 |
|
---|
[8887] | 72 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 73 | return new SchedulingEvaluator(this, cloner);
|
---|
| 74 | }
|
---|
[15219] | 75 |
|
---|
| 76 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 77 | private void AfterDeserialization() {
|
---|
| 78 | // BackwardsCompatibility3.3
|
---|
| 79 | #region Backwards compatible code, remove with 3.4
|
---|
| 80 | if (!Parameters.ContainsKey("Random")) {
|
---|
| 81 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
|
---|
| 82 | }
|
---|
| 83 | #endregion
|
---|
| 84 | }
|
---|
[6406] | 85 |
|
---|
[10507] | 86 | public override IOperation InstrumentedApply() {
|
---|
[8887] | 87 | var decoder = ScheduleDecoderParameter.ActualValue;
|
---|
| 88 | var evaluator = ScheduleEvaluatorParameter.ActualValue;
|
---|
| 89 | if (evaluator == null) throw new InvalidOperationException("A ScheduleEvaluator could not be found.");
|
---|
| 90 |
|
---|
[10507] | 91 | var operations = new OperationCollection(base.InstrumentedApply());
|
---|
[8887] | 92 | operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator));
|
---|
| 93 | if (decoder != null) // decode before evaluating
|
---|
| 94 | operations.Insert(0, ExecutionContext.CreateChildOperation(decoder));
|
---|
| 95 | return operations;
|
---|
[6266] | 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|