Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17843 was 17843, checked in by dpiringe, 3 years 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
RevLine 
[17395]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Optimization;
8
[17435]9namespace HeuristicLab.JsonInterface {
[17395]10  public class AlgorithmConverter : ParameterizedItemConverter {
11    public override int Priority => 30;
12
[17828]13    public override bool CanConvertType(Type t) =>
[17843]14      t.GetInterfaces().Any(x => x == typeof(IAlgorithm));
[17828]15
[17407]16    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
17      base.Inject(item, data, root);
[17395]18      IAlgorithm algorithm = item as IAlgorithm;
[17444]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      }
[17395]24    }
[17407]25   
26    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
27      IJsonItem item = base.Extract(value, root);
[17395]28      IAlgorithm algorithm = value as IAlgorithm;
[17407]29      foreach (var res in algorithm.Results) {
[17834]30        item.AddChildren(root.Extract(res, root));
31        /*
[17451]32        item.AddChildren(new ResultJsonItem() {
[17407]33          Name = res.Name,
[17444]34          Description = res.Description
[17834]35        });*/
[17405]36      }
[17420]37      item.AddChildren(root.Extract(algorithm.Problem, root));
[17407]38      return item;
[17395]39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.