Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17342


Ignore:
Timestamp:
10/22/19 17:32:52 (5 years ago)
Author:
dpiringe
Message:

#3026

  • in JsonItem:
    • renamed property Default to Value
    • removed usage of Reference for ValueLookupParameter
    • created new property ActualName for the actual name and using property Value for the value of an ValueLookupParameter
  • fixed a bug in ValueTypeMatrixConverter -> now it correctly resizes ValueTypeMatrix<T>
  • fixed a bug in ValueParameterConverter -> when ActualValue is null, but there is data for it, a new instance will get created
Location:
branches/3026_IntegrationIntoSymSpace
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/MenuItems/ImportJsonTemplateMenuItem.cs

    r17331 r17342  
    2020    }
    2121
    22 
    2322    public override void Execute() {
    2423      FileManager.ImportJsonTemplate();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs

    r17339 r17342  
    1010    public override void InjectData(IParameter parameter, JsonItem data) {
    1111      foreach (var x in parameter.Cast<dynamic>().ValidValues)
    12         if (x.GetType().Name == CastValue<string>(data.Default))
     12        if (x.GetType().Name == CastValue<string>(data.Value))
    1313          parameter.ActualValue = x;
    1414
     
    2020      new JsonItem() {
    2121        Name = value.Name,
    22         Default = value.ActualValue?.GetType().Name,
     22        Value = value.ActualValue?.GetType().Name,
    2323        Range = GetValidValues(value),
    2424        Parameters = GetParameterizedChilds(value)
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/DummyConverter.cs

    r17284 r17342  
    1414
    1515    public override JsonItem ExtractData(IItem value) =>
    16       new JsonItem() { Default = value.GetType().Name };
     16      new JsonItem() { Value = value.GetType().Name };
    1717  }
    1818}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs

    r17284 r17342  
    1212      item.Cast<dynamic>().Value = Enum.Parse(
    1313        item.GetType().GenericTypeArguments.First(),
    14         CastValue<string>(data.Default));
     14        CastValue<string>(data.Value));
    1515
    1616    public override JsonItem ExtractData(IItem value) {
     
    1818      object val = ((dynamic)value).Value;
    1919      Type enumType = val.GetType();
    20       data.Default = Enum.GetName(enumType, val);
     20      data.Value = Enum.GetName(enumType, val);
    2121      data.Range = Enum.GetNames(enumType);
    2222      return data;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs

    r17287 r17342  
    1111      new JsonItem() {
    1212        Name = value.Name,
    13         Default = value.Cast<ILookupParameter>().ActualName
     13        ActualName = value.Cast<ILookupParameter>().ActualName
    1414      };
    1515
    1616    public override void InjectData(IParameter parameter, JsonItem data) =>
    17       parameter.Cast<ILookupParameter>().ActualName = data.Default.Cast<string>();
    18    
     17      parameter.Cast<ILookupParameter>().ActualName = data.ActualName.Cast<string>();
    1918  }
    2019}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs

    r17322 r17342  
    1111      JsonItem data = base.ExtractData(value);
    1212
    13       data.Default = value.GetType().Name;
     13      data.Value = value.GetType().Name;
    1414      data.Operators = new List<JsonItem>();
    1515      dynamic val = value.Cast<dynamic>();
     
    1717        data.Operators.Add(new JsonItem() {
    1818          Name = op.Name,
    19           Default = val.Operators.ItemChecked(op),
     19          Value = val.Operators.ItemChecked(op),
    2020          Range = new object[] { false, true },
    2121          Path = data.Path + "." + op.Name
     
    3535    private bool GetOperatorState(string name, JsonItem data) {
    3636      foreach(var op in data.Operators) {
    37         if (op.Name == name) return op.Default.Cast<bool>();
     37        if (op.Name == name) return op.Value.Cast<bool>();
    3838      }
    3939      return false;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs

    r17284 r17342  
    1010  public class StringValueConverter : BaseConverter {
    1111    public override void InjectData(IItem item, JsonItem data) =>
    12       item.Cast<StringValue>().Value = CastValue<string>(data.Default);
     12      item.Cast<StringValue>().Value = CastValue<string>(data.Value);
    1313
    1414    public override JsonItem ExtractData(IItem value) =>
    1515      new JsonItem() {
    16         Default = value.Cast<StringValue>().Value
     16        Value = value.Cast<StringValue>().Value
    1717      };
    1818  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs

    r17287 r17342  
    1010    public override JsonItem ExtractData(IParameter value) {
    1111      IValueLookupParameter param = value.Cast<IValueLookupParameter>();
     12      object actualValue = null;
     13      IList<object> actualRange = null;
     14      if(param.Value != null) {
     15        JsonItem tmp = JsonItemConverter.Extract(param.Value);
     16        actualValue = tmp.Value;
     17        actualRange = tmp.Range;
     18      }
    1219      return new JsonItem() {
    1320        Name = value.Name,
    14         Default = param.ActualName,
    15         Reference = param.Value != null ? JsonItemConverter.Extract(param.Value) : null
     21        ActualName = param.ActualName,
     22        Value = actualValue,
     23        Range = actualRange
    1624      };
    1725    }
     
    1927    public override void InjectData(IParameter parameter, JsonItem data) {
    2028      IValueLookupParameter param = parameter.Cast<IValueLookupParameter>();
    21       param.ActualName = CastValue<string>(data.Default);
    22       if (param.Value != null && data.Reference != null)
    23         JsonItemConverter.Inject(param.Value, data.Reference);
     29      param.ActualName = CastValue<string>(data.ActualName);
     30      if (param.Value != null)
     31        JsonItemConverter.Inject(param.Value, data);
    2432    }
    2533  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs

    r17284 r17342  
    99  public class ValueParameterConverter : ParameterBaseConverter {
    1010
    11     public override void InjectData(IParameter parameter, JsonItem data) =>
     11    public override void InjectData(IParameter parameter, JsonItem data) {
     12      if (parameter.ActualValue == null && data.Value != null)
     13        parameter.ActualValue = Instantiate(parameter.DataType);
    1214      JsonItemConverter.Inject(parameter.ActualValue, data);
     15    }
    1316
    1417    public override JsonItem ExtractData(IParameter value) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs

    r17284 r17342  
    1414  {
    1515    public override void InjectData(IItem item, JsonItem data) =>
    16       CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default));
     16      CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Value));
    1717
    1818    public override JsonItem ExtractData(IItem value) =>
    1919      new JsonItem() {
    20         Default = value.Cast<ArrayType>().CloneAsArray()
     20        Value = value.Cast<ArrayType>().CloneAsArray()
    2121      };
    2222
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs

    r17284 r17342  
    1414  {
    1515    public override void InjectData(IItem item, JsonItem data) =>
    16       CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default));
     16      CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Value));
    1717
    1818    public override JsonItem ExtractData(IItem value) =>
    1919      new JsonItem() {
    20         Default = value.Cast<MatrixType>().CloneAsMatrix()
     20        Value = value.Cast<MatrixType>().CloneAsMatrix()
    2121      };
    2222
    2323    #region Helper
    2424    private void CopyMatrixData(MatrixType matrix, T[,] data) {
     25      var rowInfo = matrix.GetType().GetProperty("Rows");
     26      rowInfo.SetValue(matrix, data.GetLength(0));
     27      var colInfo = matrix.GetType().GetProperty("Columns");
     28      colInfo.SetValue(matrix, data.GetLength(1));
     29      //matrix.Cast<dynamic>().Columns = data.GetLength(1);
    2530      for (int x = 0; x < data.GetLength(0); ++x) {
    2631        for (int y = 0; y < data.GetLength(1); ++y) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs

    r17284 r17342  
    1313
    1414    public override void InjectData(IItem item, JsonItem data) =>
    15       item.Cast<ValueType>().Value = CastValue<T>(data.Default);
     15      item.Cast<ValueType>().Value = CastValue<T>(data.Value);
    1616
    1717    public override JsonItem ExtractData(IItem value) =>
    1818      new JsonItem() {
    19         Default = value.Cast<ValueType>().Value,
     19        Value = value.Cast<ValueType>().Value,
    2020        Range = new object[] { GetMinValue(), GetMaxValue() }
    2121      };
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/CustomJsonWriter.cs

    r17284 r17342  
    1515      base.Formatting = Formatting.Indented;
    1616      base.WritePropertyName(name);
    17       isRangeArray = name == "Range" || name == "Default";
     17      isRangeArray = name == nameof(JsonItem.Range) || name == nameof(JsonItem.Value);
    1818    }
    1919
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs

    r17339 r17342  
    5959      RefactorStaticParameters(obj);
    6060
    61       obj.Property(nameof(JsonItem.Default))?.Remove();
     61      obj.Property(nameof(JsonItem.Value))?.Remove();
    6262      obj.Property(nameof(JsonItem.Type))?.Remove();
    6363
     
    7070      TransformNodes(x => {
    7171        var p = x.ToObject<JsonItem>();
    72         if (p.Default == null || (p.Default != null && p.Default.GetType() == typeof(string) && p.Range == null)) {
     72        if ((p.Value == null || (p.Value != null && p.Value.GetType() == typeof(string) && p.Range == null) && p.ActualName == null)) {
    7373          objToRemove.Add(x);
    7474        } else {
     
    8888        x.Property(nameof(JsonItem.Parameters))?.Remove();
    8989        x.Property(nameof(JsonItem.Type))?.Remove();
    90         if (p.Default == null) objToRemove.Add(x);
     90        if (p.Value == null) objToRemove.Add(x);
    9191      }, token[Constants.StaticParameters]);
    9292      foreach (var x in objToRemove) x.Remove();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCInstantiator.cs

    r17339 r17342  
    9191      foreach(var x in ParameterizedItems.Values)
    9292        foreach (var p in x.Parameters)
    93           if (p.Default is string) {
     93          if (p.Value is string) {
    9494            string key = p.Path;
    9595            if (p.Range != null)
    96               key = $"{p.Path}.{p.Default.Cast<string>()}";
     96              key = $"{p.Path}.{p.Value.Cast<string>()}";
    9797
    9898            if (ParameterizedItems.TryGetValue(key, out JsonItem value))
     
    107107        // override default value
    108108        if (ConfigurableItems.TryGetValue(item.Path, out JsonItem param)) {
    109           param.Default = item.Default;
    110           // override default value of reference (for ValueLookupParameters)
    111           if (param.Reference != null)
    112             param.Reference.Default = item.Reference?.Default;
     109          param.Value = item.Value;
     110          // override ActualName (for LookupParameters)
     111          if (param.ActualName != null)
     112            param.ActualName = item.ActualName;
    113113        } else throw new InvalidDataException($"No {Constants.FreeParameters.Trim('s')} with path='{item.Path}' defined!");
    114114      }
     
    135135        Name = obj[nameof(JsonItem.Name)]?.ToString(),
    136136        Path = obj[nameof(JsonItem.Path)]?.ToString(),
    137         Default = obj[nameof(JsonItem.Default)]?.ToObject<object>(),
     137        Value = obj[nameof(JsonItem.Value)]?.ToObject<object>(),
    138138        Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(),
    139139        Type = GetType(obj[nameof(JsonItem.Path)]?.ToObject<string>()),
    140         Reference = obj[nameof(JsonItem.Type)] == null ?
    141                     null :
    142                     BuildJsonItem(obj[nameof(JsonItem.Type)].ToObject<JObject>()),
     140        ActualName = obj[nameof(JsonItem.ActualName)]?.ToString(),
    143141        Parameters = PopulateParameters(obj),
    144142        Operators = PopulateOperators(obj)
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17339 r17342  
    2525    public IList<JsonItem> Operators { get; set; }
    2626
    27     private object defaultValue;
    28     public object Default {
    29       get => defaultValue;
     27    private object value;
     28    public object Value {
     29      get => value;
    3030      set {
    31         defaultValue = value;
     31        this.value = value;
    3232        if(Range != null && value != null && !FulfillConstraints())
    3333          throw new ArgumentOutOfRangeException("Default", "Default is not in range.");
     
    4040      set {
    4141        range = value;
    42         if (Default != null && value != null && !FulfillConstraints())
     42        if (Value != null && value != null && !FulfillConstraints())
    4343          throw new ArgumentOutOfRangeException("Default", "Default is not in range.");
    4444      }
    4545    }
    46        
     46   
     47    public string ActualName { get; set; }
     48
     49    [JsonIgnore]
    4750    public JsonItem Reference { get; set; }
    4851
    4952    [JsonIgnore]
    50     public bool IsConfigurable => (Default != null && Range != null);
     53    public bool IsConfigurable => (Value != null && Range != null);
    5154
    5255    public static void Merge(JsonItem target, JsonItem from) {
     
    5558      target.Range = from.Range ?? target.Range;
    5659      target.Path = from.Path ?? target.Path;
    57       target.Default = from.Default ?? target.Default;
     60      target.Value = from.Value ?? target.Value;
    5861      target.Reference = from.Reference ?? target.Reference;
     62      target.ActualName = from.ActualName ?? target.ActualName;
    5963      target.Parameters = from.Parameters ?? target.Parameters;
    6064      target.Operators = from.Operators ?? target.Operators;
     
    6468
    6569    public static bool FulfillConstraints(JsonItem data) =>
    66       data.Range != null && data.Default != null && (
    67       IsInRangeList(data.Range, data.Default) ||
    68       IsInNumericRange<long>(data.Default, data.Range[0], data.Range[1]) ||
    69       IsInNumericRange<int>(data.Default, data.Range[0], data.Range[1]) ||
    70       IsInNumericRange<short>(data.Default, data.Range[0], data.Range[1]) ||
    71       IsInNumericRange<byte>(data.Default, data.Range[0], data.Range[1]) ||
    72       IsInNumericRange<float>(data.Default, data.Range[0], data.Range[1]) ||
    73       IsInNumericRange<double>(data.Default, data.Range[0], data.Range[1]));
     70      data.Range != null && data.Value != null && (
     71      IsInRangeList(data.Range, data.Value) ||
     72      IsInNumericRange<long>(data.Value, data.Range[0], data.Range[1]) ||
     73      IsInNumericRange<int>(data.Value, data.Range[0], data.Range[1]) ||
     74      IsInNumericRange<short>(data.Value, data.Range[0], data.Range[1]) ||
     75      IsInNumericRange<byte>(data.Value, data.Range[0], data.Range[1]) ||
     76      IsInNumericRange<float>(data.Value, data.Range[0], data.Range[1]) ||
     77      IsInNumericRange<double>(data.Value, data.Range[0], data.Range[1]));
    7478
    7579    public void UpdatePath() {
Note: See TracChangeset for help on using the changeset viewer.