Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2780_SAPBA/HeuristicLab.Algorithms.SAPBA/Problems/SurrogateProblem.cs @ 16300

Last change on this file since 16300 was 14893, checked in by bwerth, 8 years ago

#2780 added intial files for SAPBA

File size: 1.8 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Encodings.RealVectorEncoding;
4using HeuristicLab.Optimization;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Algorithms.SAPBA {
8  [StorableClass]
9  [Item("Surrogate problem (single-objective)", "Wrapper for a problem that allows surrogate models to mitigate some of the work")]
10  public class SurrogateProblem : SingleObjectiveBasicProblem<RealVectorEncoding> {
11
12    [Storable]
13    private ISurrogateStrategy Strategy;
14
15    #region HLConstructors
16    [StorableConstructor]
17    protected SurrogateProblem(bool deserializing) : base(deserializing) { }
18    [StorableHook(HookType.AfterDeserialization)]
19    private void AfterDeserialization() { }
20    protected SurrogateProblem(SurrogateProblem original, Cloner cloner) : base(original, cloner) {
21      Strategy = original?.Strategy;
22    }
23    public override IDeepCloneable Clone(Cloner cloner) { return new SurrogateProblem(this, cloner); }
24    public SurrogateProblem() {
25    }
26    #endregion
27
28    public override double Evaluate(Individual individual, IRandom random) {
29      return Strategy.Evaluate(individual.RealVector(), random);
30    }
31    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
32      base.Analyze(individuals, qualities, results, random);
33      Strategy.Analyze(individuals, qualities, results, random);
34    }
35
36    public override bool Maximization { get; }
37
38    public void SetStrategy(ISurrogateStrategy strategy) {
39      Strategy = strategy;
40    }
41    public void SetProblem(SingleObjectiveBasicProblem<IEncoding> expensiveProblem) {
42      if (expensiveProblem != null) Encoding = expensiveProblem.Encoding as RealVectorEncoding;
43    }
44
45  }
46}
Note: See TracBrowser for help on using the repository browser.