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, 5 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
RevLine 
[17263]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
[17284]8namespace HeuristicLab.JsonInterface {
[17407]9  public class ValueParameterConverter : BaseConverter {
[17394]10    public override int Priority => 2;
11    public override Type ConvertableType => typeof(IValueParameter);
[17263]12
[17407]13    public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
14      IParameter parameter = value as IParameter;
15
[17342]16      if (parameter.ActualValue == null && data.Value != null)
17        parameter.ActualValue = Instantiate(parameter.DataType);
[17439]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      }
[17342]26    }
[17263]27
[17407]28    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
29      IParameter parameter = value as IParameter;
30
31      IJsonItem item = new JsonItem() {
[17433]32        Name = parameter.Name,
33        Description = parameter.Description
[17407]34      };
35
36      if (parameter.ActualValue != null) {
37        IJsonItem tmp = root.Extract(parameter.ActualValue, root);
38        if (!(tmp is UnsupportedJsonItem)) {
[17404]39          if (tmp.Name == "[OverridableParamName]") {
[17407]40            tmp.Name = parameter.Name;
[17433]41            tmp.Description = parameter.Description;
[17410]42            item = tmp;
43            //JsonItem.Merge(item as JsonItem, tmp as JsonItem);
[17404]44          } else
[17420]45            item.AddChildren(tmp);
[17374]46        }
47      }
[17407]48      return item;
[17266]49    }
[17263]50  }
51}
Note: See TracBrowser for help on using the repository browser.