Changeset 17342
- Timestamp:
- 10/22/19 17:32:52 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/MenuItems/ImportJsonTemplateMenuItem.cs
r17331 r17342 20 20 } 21 21 22 23 22 public override void Execute() { 24 23 FileManager.ImportJsonTemplate(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs
r17339 r17342 10 10 public override void InjectData(IParameter parameter, JsonItem data) { 11 11 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)) 13 13 parameter.ActualValue = x; 14 14 … … 20 20 new JsonItem() { 21 21 Name = value.Name, 22 Default= value.ActualValue?.GetType().Name,22 Value = value.ActualValue?.GetType().Name, 23 23 Range = GetValidValues(value), 24 24 Parameters = GetParameterizedChilds(value) -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/DummyConverter.cs
r17284 r17342 14 14 15 15 public override JsonItem ExtractData(IItem value) => 16 new JsonItem() { Default= value.GetType().Name };16 new JsonItem() { Value = value.GetType().Name }; 17 17 } 18 18 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs
r17284 r17342 12 12 item.Cast<dynamic>().Value = Enum.Parse( 13 13 item.GetType().GenericTypeArguments.First(), 14 CastValue<string>(data. Default));14 CastValue<string>(data.Value)); 15 15 16 16 public override JsonItem ExtractData(IItem value) { … … 18 18 object val = ((dynamic)value).Value; 19 19 Type enumType = val.GetType(); 20 data. Default= Enum.GetName(enumType, val);20 data.Value = Enum.GetName(enumType, val); 21 21 data.Range = Enum.GetNames(enumType); 22 22 return data; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs
r17287 r17342 11 11 new JsonItem() { 12 12 Name = value.Name, 13 Default= value.Cast<ILookupParameter>().ActualName13 ActualName = value.Cast<ILookupParameter>().ActualName 14 14 }; 15 15 16 16 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>(); 19 18 } 20 19 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs
r17322 r17342 11 11 JsonItem data = base.ExtractData(value); 12 12 13 data. Default= value.GetType().Name;13 data.Value = value.GetType().Name; 14 14 data.Operators = new List<JsonItem>(); 15 15 dynamic val = value.Cast<dynamic>(); … … 17 17 data.Operators.Add(new JsonItem() { 18 18 Name = op.Name, 19 Default= val.Operators.ItemChecked(op),19 Value = val.Operators.ItemChecked(op), 20 20 Range = new object[] { false, true }, 21 21 Path = data.Path + "." + op.Name … … 35 35 private bool GetOperatorState(string name, JsonItem data) { 36 36 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>(); 38 38 } 39 39 return false; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs
r17284 r17342 10 10 public class StringValueConverter : BaseConverter { 11 11 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); 13 13 14 14 public override JsonItem ExtractData(IItem value) => 15 15 new JsonItem() { 16 Default= value.Cast<StringValue>().Value16 Value = value.Cast<StringValue>().Value 17 17 }; 18 18 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs
r17287 r17342 10 10 public override JsonItem ExtractData(IParameter value) { 11 11 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 } 12 19 return new JsonItem() { 13 20 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 16 24 }; 17 25 } … … 19 27 public override void InjectData(IParameter parameter, JsonItem data) { 20 28 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); 24 32 } 25 33 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs
r17284 r17342 9 9 public class ValueParameterConverter : ParameterBaseConverter { 10 10 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); 12 14 JsonItemConverter.Inject(parameter.ActualValue, data); 15 } 13 16 14 17 public override JsonItem ExtractData(IParameter value) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs
r17284 r17342 14 14 { 15 15 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)); 17 17 18 18 public override JsonItem ExtractData(IItem value) => 19 19 new JsonItem() { 20 Default= value.Cast<ArrayType>().CloneAsArray()20 Value = value.Cast<ArrayType>().CloneAsArray() 21 21 }; 22 22 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs
r17284 r17342 14 14 { 15 15 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)); 17 17 18 18 public override JsonItem ExtractData(IItem value) => 19 19 new JsonItem() { 20 Default= value.Cast<MatrixType>().CloneAsMatrix()20 Value = value.Cast<MatrixType>().CloneAsMatrix() 21 21 }; 22 22 23 23 #region Helper 24 24 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); 25 30 for (int x = 0; x < data.GetLength(0); ++x) { 26 31 for (int y = 0; y < data.GetLength(1); ++y) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs
r17284 r17342 13 13 14 14 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); 16 16 17 17 public override JsonItem ExtractData(IItem value) => 18 18 new JsonItem() { 19 Default= value.Cast<ValueType>().Value,19 Value = value.Cast<ValueType>().Value, 20 20 Range = new object[] { GetMinValue(), GetMaxValue() } 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/CustomJsonWriter.cs
r17284 r17342 15 15 base.Formatting = Formatting.Indented; 16 16 base.WritePropertyName(name); 17 isRangeArray = name == "Range" || name == "Default";17 isRangeArray = name == nameof(JsonItem.Range) || name == nameof(JsonItem.Value); 18 18 } 19 19 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17339 r17342 59 59 RefactorStaticParameters(obj); 60 60 61 obj.Property(nameof(JsonItem. Default))?.Remove();61 obj.Property(nameof(JsonItem.Value))?.Remove(); 62 62 obj.Property(nameof(JsonItem.Type))?.Remove(); 63 63 … … 70 70 TransformNodes(x => { 71 71 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)) { 73 73 objToRemove.Add(x); 74 74 } else { … … 88 88 x.Property(nameof(JsonItem.Parameters))?.Remove(); 89 89 x.Property(nameof(JsonItem.Type))?.Remove(); 90 if (p. Default== null) objToRemove.Add(x);90 if (p.Value == null) objToRemove.Add(x); 91 91 }, token[Constants.StaticParameters]); 92 92 foreach (var x in objToRemove) x.Remove(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCInstantiator.cs
r17339 r17342 91 91 foreach(var x in ParameterizedItems.Values) 92 92 foreach (var p in x.Parameters) 93 if (p. Defaultis string) {93 if (p.Value is string) { 94 94 string key = p.Path; 95 95 if (p.Range != null) 96 key = $"{p.Path}.{p. Default.Cast<string>()}";96 key = $"{p.Path}.{p.Value.Cast<string>()}"; 97 97 98 98 if (ParameterizedItems.TryGetValue(key, out JsonItem value)) … … 107 107 // override default value 108 108 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; 113 113 } else throw new InvalidDataException($"No {Constants.FreeParameters.Trim('s')} with path='{item.Path}' defined!"); 114 114 } … … 135 135 Name = obj[nameof(JsonItem.Name)]?.ToString(), 136 136 Path = obj[nameof(JsonItem.Path)]?.ToString(), 137 Default = obj[nameof(JsonItem.Default)]?.ToObject<object>(),137 Value = obj[nameof(JsonItem.Value)]?.ToObject<object>(), 138 138 Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(), 139 139 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(), 143 141 Parameters = PopulateParameters(obj), 144 142 Operators = PopulateOperators(obj) -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs
r17339 r17342 25 25 public IList<JsonItem> Operators { get; set; } 26 26 27 private object defaultValue;28 public object Default{29 get => defaultValue;27 private object value; 28 public object Value { 29 get => value; 30 30 set { 31 defaultValue = value;31 this.value = value; 32 32 if(Range != null && value != null && !FulfillConstraints()) 33 33 throw new ArgumentOutOfRangeException("Default", "Default is not in range."); … … 40 40 set { 41 41 range = value; 42 if ( Default!= null && value != null && !FulfillConstraints())42 if (Value != null && value != null && !FulfillConstraints()) 43 43 throw new ArgumentOutOfRangeException("Default", "Default is not in range."); 44 44 } 45 45 } 46 46 47 public string ActualName { get; set; } 48 49 [JsonIgnore] 47 50 public JsonItem Reference { get; set; } 48 51 49 52 [JsonIgnore] 50 public bool IsConfigurable => ( Default!= null && Range != null);53 public bool IsConfigurable => (Value != null && Range != null); 51 54 52 55 public static void Merge(JsonItem target, JsonItem from) { … … 55 58 target.Range = from.Range ?? target.Range; 56 59 target.Path = from.Path ?? target.Path; 57 target. Default = from.Default ?? target.Default;60 target.Value = from.Value ?? target.Value; 58 61 target.Reference = from.Reference ?? target.Reference; 62 target.ActualName = from.ActualName ?? target.ActualName; 59 63 target.Parameters = from.Parameters ?? target.Parameters; 60 64 target.Operators = from.Operators ?? target.Operators; … … 64 68 65 69 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])); 74 78 75 79 public void UpdatePath() {
Note: See TracChangeset
for help on using the changeset viewer.