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

Last change on this file since 17843 was 17843, checked in by dpiringe, 7 weeks ago

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
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 bool CanConvertType(Type t) =>
14      t.GetInterfaces().Any(x => x == typeof(IAlgorithm));
15
16    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
17      base.Inject(item, data, root);
18      IAlgorithm algorithm = item as IAlgorithm;
19      var collection = data.Children.Where(x => x.Name == algorithm.Problem.ItemName);
20      if(collection.Count() > 0) {
21        IJsonItem problemData = collection.First();
22        root.Inject(algorithm.Problem, problemData, root);
23      }
24    }
25   
26    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
27      IJsonItem item = base.Extract(value, root);
28      IAlgorithm algorithm = value as IAlgorithm;
29      foreach (var res in algorithm.Results) {
30        item.AddChildren(root.Extract(res, root));
31        /*
32        item.AddChildren(new ResultJsonItem() {
33          Name = res.Name,
34          Description = res.Description
35        });*/
36      }
37      item.AddChildren(root.Extract(algorithm.Problem, root));
38      return item;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.