1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Collections;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Optimization;
|
---|
10 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
11 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
12 | using HEAL.Attic;
|
---|
13 | using HeuristicLab.Data;
|
---|
14 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
15 | using HeuristicLab.Parameters;
|
---|
16 |
|
---|
17 | namespace HeuristicLab.JsonInterface {
|
---|
18 | [StorableType("806BB409-E50C-4827-ABEF-0376D65F7414")]
|
---|
19 | public abstract class RunCollectionSRSolutionFormatter : ParameterizedNamedItem, IRunCollectionModifier {
|
---|
20 |
|
---|
21 | #region Constants
|
---|
22 | private const string SuffixParameterName = "Suffix";
|
---|
23 | #endregion
|
---|
24 |
|
---|
25 | #region Parameter Properties
|
---|
26 | public IFixedValueParameter<StringValue> SuffixParameter =>
|
---|
27 | (IFixedValueParameter<StringValue>)Parameters[SuffixParameterName];
|
---|
28 | #endregion
|
---|
29 |
|
---|
30 | #region Properties
|
---|
31 | public string Suffix {
|
---|
32 | get => SuffixParameter.Value.Value;
|
---|
33 | set => SuffixParameter.Value.Value = value;
|
---|
34 | }
|
---|
35 | protected abstract ISymbolicExpressionTreeStringFormatter Formatter { get; }
|
---|
36 | #endregion
|
---|
37 |
|
---|
38 | #region Constructors & Cloning
|
---|
39 | [StorableConstructor]
|
---|
40 | protected RunCollectionSRSolutionFormatter(StorableConstructorFlag _) : base(_) { }
|
---|
41 | public RunCollectionSRSolutionFormatter() {
|
---|
42 | Parameters.Add(new FixedValueParameter<StringValue>(SuffixParameterName, "Appends a suffix to the original name.", new StringValue()));
|
---|
43 | }
|
---|
44 | public RunCollectionSRSolutionFormatter(RunCollectionSRSolutionFormatter original, Cloner cloner) : base(original, cloner) { }
|
---|
45 | #endregion
|
---|
46 |
|
---|
47 | public void Apply(IObservableDictionary<string, IItem> results) {
|
---|
48 | var resultCopy = new ObservableDictionary<string, IItem>(results);
|
---|
49 | foreach (var kvp in resultCopy) {
|
---|
50 | if (kvp.Value is ISymbolicRegressionSolution sol) {
|
---|
51 | results.Add(
|
---|
52 | $"{kvp.Key} - {SuffixParameter.Value.Value}",
|
---|
53 | new StringValue(Formatter.Format(sol.Model.SymbolicExpressionTree)));
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void Modify(List<IRun> runs) {
|
---|
59 | foreach(var run in runs) {
|
---|
60 | var resultCopy = new ObservableDictionary<string, IItem>(run.Results);
|
---|
61 | foreach (var kvp in resultCopy) {
|
---|
62 | if (kvp.Value is ISymbolicRegressionSolution sol) {
|
---|
63 | run.Results.Add(
|
---|
64 | $"{kvp.Key} - {SuffixParameter.Value.Value}",
|
---|
65 | new StringValue(Formatter.Format(sol.Model.SymbolicExpressionTree)));
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|