Changeset 17287 for branches/3026_IntegrationIntoSymSpace
- Timestamp:
- 10/02/19 12:44:44 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs
r17284 r17287 8 8 namespace HeuristicLab.JsonInterface { 9 9 public class LookupParameterConverter : ParameterBaseConverter { 10 public override JsonItem ExtractData(IParameter value) { 11 return new JsonItem() { Name = value.Name }; 12 } 10 public override JsonItem ExtractData(IParameter value) => 11 new JsonItem() { 12 Name = value.Name, 13 Default = value.Cast<ILookupParameter>().ActualName 14 }; 13 15 14 public override void InjectData(IParameter parameter, JsonItem data) {15 16 }16 public override void InjectData(IParameter parameter, JsonItem data) => 17 parameter.Cast<ILookupParameter>().ActualName = data.Default.Cast<string>(); 18 17 19 } 18 20 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Extensions/TypeExtensions.cs
r17284 r17287 30 30 } 31 31 } 32 return type.IsAssignableFrom(other);32 return false;//type.IsAssignableFrom(other); 33 33 } 34 34 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17284 r17287 51 51 </ItemGroup> 52 52 <ItemGroup> 53 <Compile Include="Constants.cs" /> 54 <Compile Include="Converters\ValueLookupParameterConverter.cs" /> 53 55 <Compile Include="CustomJsonWriter.cs" /> 54 56 <Compile Include="Extensions\ObjectExtensions.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17284 r17287 15 15 public class JCGenerator { 16 16 17 private JObject template = JObject.Parse(@"{ 18 'Metadata': { 19 'Algorithm':'', 20 'Problem':'' 21 }, 22 'Objects': [], 23 'Types': {} 24 }"); 17 private JObject template = JObject.Parse(Constants.Template); 25 18 26 19 private Dictionary<string, string> TypeList = new Dictionary<string, string>(); … … 39 32 private JObject Serialize(JsonItem item) { 40 33 JObject obj = JObject.FromObject(item, Settings()); 41 obj[ "StaticParameters"] = obj["Parameters"];42 obj[ "FreeParameters"] = obj["Parameters"];34 obj[Constants.StaticParameters] = obj[nameof(JsonItem.Parameters)]; 35 obj[Constants.FreeParameters] = obj[nameof(JsonItem.Parameters)]; 43 36 44 obj.Property( "Parameters")?.Remove();37 obj.Property(nameof(JsonItem.Parameters))?.Remove(); 45 38 RefactorFreeParameters(obj, null); 46 39 RefactorStaticParameters(obj); 47 40 48 obj.Property( "Default")?.Remove();49 obj.Property( "Type")?.Remove();41 obj.Property(nameof(JsonItem.Default))?.Remove(); 42 obj.Property(nameof(JsonItem.Type))?.Remove(); 50 43 51 44 TypeList.Add(item.Path, item.Type); … … 60 53 PopulateJsonItems(problemData); 61 54 62 template[ "Metadata"]["Algorithm"] = algorithm.Name;63 template[ "Metadata"]["Problem"] = problem.Name;64 template[ "Objects"] = jsonItems;65 template[ "Types"] = JObject.FromObject(TypeList);55 template[Constants.Metadata][Constants.Algorithm] = algorithm.Name; 56 template[Constants.Metadata][Constants.Problem] = problem.Name; 57 template[Constants.Objects] = jsonItems; 58 template[Constants.Types] = JObject.FromObject(TypeList); 66 59 67 60 return CustomJsonWriter.Serialize(template); … … 84 77 objToRemove.Add(x); 85 78 } else { 86 x.Property( "Path")?.Remove();87 x.Property( "Type")?.Remove();88 x.Property( "Parameters")?.Remove();79 x.Property(nameof(JsonItem.Path))?.Remove(); 80 x.Property(nameof(JsonItem.Type))?.Remove(); 81 x.Property(nameof(JsonItem.Parameters))?.Remove(); 89 82 } 90 }, token[ "FreeParameters"]);83 }, token[Constants.FreeParameters]); 91 84 foreach (var x in objToRemove) x.Remove(); 92 93 85 } 94 86 … … 97 89 TransformNodes(x => { 98 90 var p = x.ToObject<JsonItem>(); 99 x.Property( "Range")?.Remove();100 x.Property( "Operators")?.Remove();101 x.Property( "Parameters")?.Remove();102 x.Property( "Type")?.Remove();91 x.Property(nameof(JsonItem.Range))?.Remove(); 92 x.Property(nameof(JsonItem.Operators))?.Remove(); 93 x.Property(nameof(JsonItem.Parameters))?.Remove(); 94 x.Property(nameof(JsonItem.Type))?.Remove(); 103 95 if (p.Default == null) objToRemove.Add(x); 104 }, token[ "StaticParameters"]);96 }, token[Constants.StaticParameters]); 105 97 foreach (var x in objToRemove) x.Remove(); 106 98 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCInstantiator.cs
r17284 r17287 20 20 public IAlgorithm Instantiate(string configFile) { 21 21 Config = JToken.Parse(File.ReadAllText(configFile)); 22 TypeList = Config[ "Types"].ToObject<Dictionary<string, string>>();22 TypeList = Config[Constants.Types].ToObject<Dictionary<string, string>>(); 23 23 24 JsonItem algorithmData = GetData(Config[ "Metadata"]["Algorithm"].ToString());24 JsonItem algorithmData = GetData(Config[Constants.Metadata][Constants.Algorithm].ToString()); 25 25 ResolveReferences(algorithmData); 26 26 IAlgorithm algorithm = CreateObject<IAlgorithm>(algorithmData); 27 27 28 JsonItem problemData = GetData(Config[ "Metadata"]["Problem"].ToString());28 JsonItem problemData = GetData(Config[Constants.Metadata][Constants.Problem].ToString()); 29 29 ResolveReferences(problemData); 30 30 IProblem problem = CreateObject<IProblem>(problemData); … … 45 45 private JsonItem GetData(string key) 46 46 { 47 foreach(JObject item in Config[ "Objects"])47 foreach(JObject item in Config[Constants.Objects]) 48 48 { 49 49 JsonItem data = BuildJsonItem(item); … … 66 66 Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(), 67 67 Type = obj[nameof(JsonItem.Type)]?.ToObject<string>(), 68 Reference = obj[nameof(JsonItem.Type)] == null ? 69 null : 70 BuildJsonItem(obj[nameof(JsonItem.Type)].ToObject<JObject>()), 68 71 Parameters = PopulateParameters(obj), 69 72 Operators = PopulateOperators(obj) … … 72 75 private IList<JsonItem> PopulateParameters(JObject obj) { 73 76 IList<JsonItem> list = new List<JsonItem>(); 74 if (obj[ "StaticParameters"] != null)75 foreach (JObject param in obj[ "StaticParameters"])77 if (obj[Constants.StaticParameters] != null) 78 foreach (JObject param in obj[Constants.StaticParameters]) 76 79 list.Add(BuildJsonItem(param)); 77 80 78 if (obj[ "FreeParameters"] != null) {79 foreach (JObject param in obj[ "FreeParameters"]) {81 if (obj[Constants.FreeParameters] != null) { 82 foreach (JObject param in obj[Constants.FreeParameters]) { 80 83 JsonItem tmp = BuildJsonItem(param); 81 84 JsonItem comp = null; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs
r17284 r17287 42 42 public override int GetHashCode() => Name.GetHashCode(); 43 43 44 [JsonIgnore]45 44 public JsonItem Reference { get; set; } 46 45 … … 68 67 IsInNumericRange<double>(data.Default, data.Range[0], data.Range[1])); 69 68 69 public void UpdatePaths() { 70 if (Parameters != null) 71 foreach (var p in Parameters) 72 p.Path = Path + "." + p.Name; 70 73 71 72 public void UpdatePaths() { 73 if (Parameters != null) { 74 foreach (var p in Parameters) { 74 if (Operators != null) 75 foreach (var p in Operators) 75 76 p.Path = Path + "." + p.Name; 76 }77 }78 79 if (Operators != null) {80 foreach (var p in Operators) {81 p.Path = Path + "." + p.Name;82 }83 }84 77 } 85 78 … … 91 84 92 85 private void PrependPathHelper(IEnumerable<JsonItem> items, string str) { 93 if (items != null) {86 if (items != null) 94 87 foreach (var p in items) 95 88 p.PrependPath(str); 96 }97 89 } 98 90 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs
r17284 r17287 52 52 Register<IntValue>(new ValueTypeValueConverter<IntValue, int>(), 1); 53 53 Register<DoubleValue>(new ValueTypeValueConverter<DoubleValue, double>(), 1); 54 Register<PercentValue>(new ValueTypeValueConverter<PercentValue, double>(), 1);54 Register<PercentValue>(new ValueTypeValueConverter<PercentValue, double>(), 2); 55 55 Register<BoolValue>(new ValueTypeValueConverter<BoolValue, bool>(), 1); 56 56 Register<DateTimeValue>(new ValueTypeValueConverter<DateTimeValue, DateTime>(), 1); … … 59 59 Register<IntArray>(new ValueTypeArrayConverter<IntArray, int>(), 1); 60 60 Register<DoubleArray>(new ValueTypeArrayConverter<DoubleArray, double>(), 1); 61 Register<PercentArray>(new ValueTypeArrayConverter<PercentArray, double>(), 1);61 Register<PercentArray>(new ValueTypeArrayConverter<PercentArray, double>(), 2); 62 62 Register<BoolArray>(new ValueTypeArrayConverter<BoolArray, bool>(), 1); 63 63 64 64 Register<IntMatrix>(new ValueTypeMatrixConverter<IntMatrix, int>(), 1); 65 65 Register<DoubleMatrix>(new ValueTypeMatrixConverter<DoubleMatrix, double>(), 1); 66 Register<PercentMatrix>(new ValueTypeMatrixConverter<PercentMatrix, double>(), 1);66 Register<PercentMatrix>(new ValueTypeMatrixConverter<PercentMatrix, double>(), 2); 67 67 Register<BoolMatrix>(new ValueTypeMatrixConverter<BoolMatrix, bool>(), 1); 68 68 69 Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterConverter(), 1); 70 Register(typeof(ILookupParameter), new LookupParameterConverter(), 1); 71 Register(typeof(IValueParameter), new ValueParameterConverter(), 1); 72 Register(typeof(IParameterizedItem), new ParameterizedItemConverter(), 1); 69 Register(typeof(EnumValue<>), new EnumTypeConverter(), 1); 70 71 Register<IValueParameter>(new ValueParameterConverter(), 1); 72 Register<IParameterizedItem>(new ParameterizedItemConverter(), 1); 73 Register<ILookupParameter>(new LookupParameterConverter(), 2); 74 Register<IValueLookupParameter>(new ValueLookupParameterConverter(), 3); 75 76 Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterConverter(), 2); 73 77 Register(typeof(ICheckedMultiOperator<>), new MultiCheckedOperatorConverter(), 2); 74 Register(typeof(EnumValue<>), new EnumTypeConverter(), 1);75 78 } 76 77 79 } 78 80 }
Note: See TracChangeset
for help on using the changeset viewer.