1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
4 | using HeuristicLab.Optimization;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 |
|
---|
7 | namespace 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 | } |
---|