Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BatchRunConverter.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.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
8namespace HeuristicLab.JsonInterface {
9  public class BatchRunConverter : BaseConverter {
10    public override int Priority => 10;
11
12    public override bool CanConvertType(Type t) =>
13      HEAL.Attic.Mapper.StaticCache.GetType(new Guid("E85407E0-18EC-4198-8321-9CF030FDF6D7")).IsAssignableFrom(t);
14
15    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
16      dynamic batchRun = (dynamic)value;
17      EmptyJsonItem batchRunJI = new EmptyJsonItem() {
18        Name = batchRun.Name,
19        Description = value.ItemDescription
20      };
21
22      var optimizerJI = root.Extract((IItem)batchRun.Optimizer, root);
23      if(!(optimizerJI is UnsupportedJsonItem)) {
24        batchRunJI.AddChildren(optimizerJI);
25      }
26
27      int reps = (int)batchRun.Repetitions;
28      batchRunJI.AddChildren(new IntJsonItem() {
29        Name = "Repetitions",
30        Description = "The repetitions for this batch run.",
31        Value = reps,
32        Minimum = 0,
33        Maximum = int.MaxValue
34      });
35      return batchRunJI;
36    }
37
38    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
39      dynamic batchRun = (dynamic)item;
40      if(data.Children != null) {
41        foreach(var i in data.Children) {
42          if(i.Path.EndsWith("Repetitions") && i is IntJsonItem reps ) {
43            batchRun.Repetitions = reps.Value;
44          } else {
45            root.Inject((IItem)batchRun.Optimizer, i, root);
46          }
47        }
48      }
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.