Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ExperimentConverter.cs @ 17712

Last change on this file since 17712 was 17540, checked in by dpiringe, 5 years ago

#3026:

  • added new converter: BatchRunConverter, ExperimentConverter
  • fixed a bug with the path of the .hl file in JCGenerator
  • fixed a bug with a redundant search for a suitable converter in JsonItemConverter
  • added a restriction for TargetVariable and AllowedInputVariables in RegressionProblemDataConverter
  • removed unnecessary code in Runner
File size: 1.9 KB
RevLine 
[17540]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 ExperimentConverter : BaseConverter {
11    public override int Priority => 10;
12    public override Type ConvertableType => HEAL.Attic.Mapper.StaticCache.GetType(new Guid("A8A4536B-54C1-4A17-AB58-A6006F7F394B"));
13
14    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
15      dynamic experiment = (dynamic)value;
16      EmptyJsonItem experimentJI = new EmptyJsonItem() {
17        Name = experiment.Name,
18        Description = value.ItemDescription
19      };
20
21      OptimizerList optimizers = experiment.Optimizers;
22      foreach(var o in optimizers) {
23        var optimizerJI = root.Extract(o, root);
24        if (!(optimizerJI is UnsupportedJsonItem)) {
25          experimentJI.AddChildren(optimizerJI);
26        }
27      }
28
29      int worker = (int)experiment.NumberOfWorkers;
30      experimentJI.AddChildren(new IntJsonItem() {
31        Name = "NumberOfWorkers",
32        Description = "The number of workers for this experiment.",
33        Value = worker,
34        Minimum = 1,
35        Maximum = int.MaxValue
36      });
37
38      return experimentJI;
39    }
40
41    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
42      dynamic experiment = (dynamic)item;
43      OptimizerList optimizers = experiment.Optimizers;
44      if (data.Children != null) {
45        foreach (var i in data.Children) {
46          if (i.Path.EndsWith("NumberOfWorkers") && i is IntJsonItem worker) {
47            experiment.NumberOfWorkers = worker.Value;
48          } else {
49            var optimizer = optimizers.Find(o => i.Path.EndsWith(o.Name));
50            root.Inject(optimizer, i, root);
51          }
52        }
53      }
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.