Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Problems.ExternalEvaluation/3.3/CachedExternalEvaluator.cs @ 8114

Last change on this file since 8114 was 7270, checked in by spimming, 13 years ago

#1680:

  • merged changes from trunk into branch
File size: 2.9 KB
RevLine 
[6140]1#region License Information
2/* HeuristicLab
[7270]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6140]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
[6183]22using System.Threading;
[6140]23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[6519]28
[6140]29namespace HeuristicLab.Problems.ExternalEvaluation {
30
31  [Item("CachedExternalEvaluationValuesCollector", "Creates a solution message, and communicates it via the driver to receive a quality message, also keeps a cache of previous evaluation results.")]
32  [StorableClass]
33  public class CachedExternalEvaluator : ExternalEvaluator {
34
35    #region Parameters
[6183]36    public ValueLookupParameter<EvaluationCache> CacheParameter {
37      get { return (ValueLookupParameter<EvaluationCache>)Parameters["Cache"]; }
[6140]38    }
39    #endregion
40
41    #region Parameter Values
[6169]42    protected DoubleValue Quality {
[6140]43      get { return QualityParameter.ActualValue; }
44      set { QualityParameter.ActualValue = value; }
45    }
[6183]46    protected EvaluationCache Cache {
47      get { return CacheParameter.ActualValue; }
48      set { CacheParameter.ActualValue = value; }
49    }
[6140]50    #endregion
51
52    #region Construction & Cloning
53    [StorableConstructor]
54    protected CachedExternalEvaluator(bool deserializing) : base(deserializing) { }
55    protected CachedExternalEvaluator(CachedExternalEvaluator original, Cloner cloner) : base(original, cloner) { }
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new CachedExternalEvaluator(this, cloner);
58    }
59    public CachedExternalEvaluator()
60      : base() {
[6183]61      Parameters.Add(new ValueLookupParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions"));
[6140]62    }
63    #endregion
64
65    public override IOperation Apply() {
[6183]66      if (Cache == null)
67        return base.Apply();
68
[6140]69      if (Quality == null) Quality = new DoubleValue(0);
[6189]70      Quality.Value = Cache.GetValue(BuildSolutionMessage(), m => EvaluateOnNextAvailableClient(m).Quality);
[6172]71      if (Successor != null)
72        return ExecutionContext.CreateOperation(Successor);
73      else
74        return null;
[6140]75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.