1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
|
---|
2 | using Common;
|
---|
3 | using Configuration;
|
---|
4 | using Core;
|
---|
5 | using Encodings.IntegerVectorEncoding;
|
---|
6 | using Expressions;
|
---|
7 | using Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | [StorableClass]
|
---|
10 | public class PushSolution : NamedItem {
|
---|
11 | [Storable]
|
---|
12 | public readonly double Quality;
|
---|
13 | [Storable]
|
---|
14 | public readonly IntegerVector IntegerVector;
|
---|
15 | [Storable]
|
---|
16 | public readonly IRandom Random;
|
---|
17 | [Storable]
|
---|
18 | public readonly IReadOnlyPushConfiguration Config;
|
---|
19 |
|
---|
20 | [Storable]
|
---|
21 | public readonly IPushEvaluator Evaluator;
|
---|
22 |
|
---|
23 | public readonly PushProgram Program;
|
---|
24 |
|
---|
25 | public PushSolution(IntegerVector integerVector, double quality, IRandom random, IReadOnlyPushConfiguration config, IPushEvaluator evaluator, bool simplify = false)
|
---|
26 | : base("Solution", "A push solution.") {
|
---|
27 | IntegerVector = integerVector;
|
---|
28 | Quality = quality;
|
---|
29 | Random = random;
|
---|
30 | Config = config;
|
---|
31 | Evaluator = evaluator;
|
---|
32 |
|
---|
33 | Program = IntegerVector.ToPushProgram(config);
|
---|
34 |
|
---|
35 | if (simplify)
|
---|
36 | Program = Simplifier.Simplifier.Simplify(Program, p => Evaluator.EvaluateTraining(config, p, random).TotalQuality);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) {
|
---|
40 | Quality = origin.Quality;
|
---|
41 | IntegerVector = cloner.Clone(origin.IntegerVector);
|
---|
42 | Random = cloner.Clone(origin.Random);
|
---|
43 | Config = cloner.Clone(origin.Config);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public virtual PushSolution Simplify() {
|
---|
47 | return new PushSolution(IntegerVector, Quality, Random, Config, Evaluator, true);
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableConstructor]
|
---|
51 | protected PushSolution(bool deserializing) : base(deserializing) { }
|
---|
52 |
|
---|
53 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
54 | return new PushSolution(this, cloner);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|