source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs @ 17834

Last change on this file since 17834 was 17834, checked in by dpiringe, 2 months ago

#3026

  • added ResultFormatter to add an extra layer of result transformation logic (converting a result value to a string with a defined logic, e.g. MatlabResultFormatter for ISymbolicRegressionSolution)
  • extended the IResultJsonItem with two properties for result formatting
  • added a new control to selected a result formatter for a result value
  • refactored the Runner for the new result formatting process
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Optimization;
8
9namespace HeuristicLab.JsonInterface {
10  public class AlgorithmConverter : ParameterizedItemConverter {
11    public override int Priority => 30;
12
13    public override Type ConvertableType => typeof(IAlgorithm);
14
15    public override bool CanConvertType(Type t) =>
16      t.GetInterfaces().Any(x => x == ConvertableType);
17
18    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
19      base.Inject(item, data, root);
20      IAlgorithm algorithm = item as IAlgorithm;
21      var collection = data.Children.Where(x => x.Name == algorithm.Problem.ItemName);
22      if(collection.Count() > 0) {
23        IJsonItem problemData = collection.First();
24        root.Inject(algorithm.Problem, problemData, root);
25      }
26    }
27   
28    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
29      IJsonItem item = base.Extract(value, root);
30      IAlgorithm algorithm = value as IAlgorithm;
31      foreach (var res in algorithm.Results) {
32        item.AddChildren(root.Extract(res, root));
33        /*
34        item.AddChildren(new ResultJsonItem() {
35          Name = res.Name,
36          Description = res.Description
37        });*/
38      }
39      item.AddChildren(root.Extract(algorithm.Problem, root));
40      return item;
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.