Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs @ 17439

Last change on this file since 17439 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: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8
9namespace HeuristicLab.JsonInterface {
10  public class MultiCheckedOperatorConverter : ParameterizedItemConverter {
11    public override int Priority => 3;
12    public override Type ConvertableType => typeof(ICheckedMultiOperator<>);
13   
14    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
15      base.Inject(item, data, root);
16
17      dynamic val = item as dynamic;
18      foreach (var op in val.Operators) {
19        IJsonItem childItem = GetChildItem(op.Name, data);
20        if(childItem != null) {
21          if(childItem.Value is bool b) {
22            val.Operators.SetItemCheckedState(op, b);
23          }
24          root.Inject((IItem)op, childItem, root);
25        }
26      }
27    }
28
29    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
30      IJsonItem item = base.Extract(value, root);
31      dynamic val = value as dynamic;
32      foreach (var op in val.Operators) {
33        IJsonItem operatorItem = new BoolJsonItem() {
34          Name = op.Name,
35          Description = op.Description,
36          Value = val.Operators.ItemChecked(op),
37          Range = new bool[] { false, true }
38        };
39        IJsonItem c = root.Extract((IItem)op, root);
40        if(c != null && c.Children != null)
41          operatorItem.AddChildren(c.Children);
42        item.AddChildren(operatorItem);
43      }
44      return item;
45    }
46
47
48    #region Helper
49    private bool GetOperatorState(string name, IJsonItem data) {
50      foreach(var op in data.Children) {
51        if (op.Name == name && op.Value is bool) return (bool)op.Value;
52      }
53      return false;
54    }
55
56    private IJsonItem GetChildItem(string name, IJsonItem parent) {
57      foreach(var c in parent.Children) {
58        if (c.Name == name) return c;
59      }
60      return null;
61    }
62    #endregion
63  }
64}
Note: See TracBrowser for help on using the repository browser.