Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs @ 17444

Last change on this file since 17444 was 17439, checked in by dpiringe, 4 years ago

#3026:

  • fixed a bug in HeuristicLab.JsonInterface.App -> now the Runner checks if the instantiated optimizer is an EngineAlgorithm, if true: Engine = SequentialEngine (engine can be configured in later versions)
  • added a TabControl in ExportJsonDialog for parameters and results
  • updated parameter tree view with checkboxes (and linked them with VM)
  • renamed ActivatedResults to Results for templates
  • fixed a bug with injection of operators in MultiCheckedOperatorConverter -> now operators of an ValueParameter get set correctly
  • updated MultiCheckedOperatorConverter to extract/inject parameters of operators
  • fixed bug with path for template -> removed usage of method Path.GetDirectoryName, returned wrong results
  • splitted cache for JsonItemConverter into a cache for injection and extraction
  • JsonTemplateInstantiator now uses first item in objects array instead of searching for an object with template name
File size: 1.7 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 ValueParameterConverter : BaseConverter {
10    public override int Priority => 2;
11    public override Type ConvertableType => typeof(IValueParameter);
12
13    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
14      IParameter parameter = value as IParameter;
15
16      if (parameter.ActualValue == null && data.Value != null)
17        parameter.ActualValue = Instantiate(parameter.DataType);
18
19      if(parameter.ActualValue != null) {
20          if (data.Children == null || data.Children.Count == 0)
21            root.Inject(parameter.ActualValue, data, root);
22          else
23            root.Inject(parameter.ActualValue, data.Children?.First(), root);
24         
25      }
26    }
27
28    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
29      IParameter parameter = value as IParameter;
30
31      IJsonItem item = new JsonItem() {
32        Name = parameter.Name,
33        Description = parameter.Description
34      };
35
36      if (parameter.ActualValue != null) {
37        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
38        if (!(tmp is UnsupportedJsonItem)) {
39          if (tmp.Name == "[OverridableParamName]") {
40            tmp.Name = parameter.Name;
41            tmp.Description = parameter.Description;
42            item = tmp;
43            //JsonItem.Merge(item as JsonItem, tmp as JsonItem);
44          } else
45            item.AddChildren(tmp);
46        }
47      }
48      return item;
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.