Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.Problems.Scheduling/3.3/Evaluators/SchedulingEvaluator.cs @ 14711

Last change on this file since 14711 was 14711, checked in by gkronber, 7 years ago

#2520

  • renamed StorableClass -> StorableType
  • changed persistence to use GUIDs instead of type names
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.ScheduleEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.Scheduling {
32  [Item("SchedulingEvaluator", "First applies the decoder operator to obtain a schedule from an encoding and then applies the evaluator to obtain a quality.")]
33  [StorableType("926EC6F7-9FB2-4BC7-97DD-7CE29642F2C0")]
34  public class SchedulingEvaluator : InstrumentedOperator, ISchedulingEvaluator {
35
36    public IValueLookupParameter<IScheduleDecoder> ScheduleDecoderParameter {
37      get { return (IValueLookupParameter<IScheduleDecoder>)Parameters["ScheduleDecoder"]; }
38    }
39    ILookupParameter<IScheduleDecoder> ISchedulingEvaluator.ScheduleDecoderParameter {
40      get { return ScheduleDecoderParameter; }
41    }
42    public IValueLookupParameter<IScheduleEvaluator> ScheduleEvaluatorParameter {
43      get { return (IValueLookupParameter<IScheduleEvaluator>)Parameters["ScheduleEvaluator"]; }
44    }
45    ILookupParameter<IScheduleEvaluator> ISchedulingEvaluator.ScheduleEvaluatorParameter {
46      get { return ScheduleEvaluatorParameter; }
47    }
48    public ILookupParameter<DoubleValue> QualityParameter {
49      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
50    }
51
52    [StorableConstructor]
53    protected SchedulingEvaluator(bool deserializing) : base(deserializing) { }
54    protected SchedulingEvaluator(SchedulingEvaluator original, Cloner cloner) : base(original, cloner) { }
55    public SchedulingEvaluator()
56      : base() {
57      Parameters.Add(new ValueLookupParameter<IScheduleDecoder>("ScheduleDecoder", "The decoding operator that is used to calculate a schedule from the used representation."));
58      Parameters.Add(new ValueLookupParameter<IScheduleEvaluator>("ScheduleEvaluator", "The actual schedule evaluation operator."));
59      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution."));
60      QualityParameter.Hidden = true;
61    }
62
63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new SchedulingEvaluator(this, cloner);
65    }
66
67    public override IOperation InstrumentedApply() {
68      var decoder = ScheduleDecoderParameter.ActualValue;
69      var evaluator = ScheduleEvaluatorParameter.ActualValue;
70      if (evaluator == null) throw new InvalidOperationException("A ScheduleEvaluator could not be found.");
71
72      var operations = new OperationCollection(base.InstrumentedApply());
73      operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator));
74      if (decoder != null) // decode before evaluating
75        operations.Insert(0, ExecutionContext.CreateChildOperation(decoder));
76      return operations;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.