- Timestamp:
- 01/21/20 17:14:46 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs
r17395 r17405 16 16 internal const string HLFileLocation = "HLFileLocation"; 17 17 internal const string Parameters = "Parameters"; 18 internal const string ActivatedResults = "ActivatedResults"; 18 19 19 20 internal const string Template = @"{ … … 23 24 '" + HLFileLocation + @"':'' 24 25 }, 25 '" + Parameters + @"': [] 26 '" + Parameters + @"': [], 27 '" + ActivatedResults + @"': [] 26 28 }"; 27 29 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs
r17395 r17405 24 24 base.Populate(value, item, root); 25 25 IAlgorithm algorithm = value as IAlgorithm; 26 foreach(var res in algorithm.Results) { 27 item.AddChilds(new ResultItem() { 28 Name = res.Name, 29 Value = true, 30 Range = new object[] { true, false } 31 }); 32 } 26 33 item.AddChilds(root.Extract(algorithm.Problem, root)); 27 34 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17395 r17405 66 66 <Compile Include="Converters\ValueLookupParameterConverter.cs" /> 67 67 <Compile Include="Converters\ValueRangeConverter.cs" /> 68 <Compile Include="ResultItem.cs" /> 68 69 <Compile Include="SingleLineArrayJsonWriter.cs" /> 69 70 <Compile Include="Extensions\TypeExtensions.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17404 r17405 20 20 private IOptimizer Optimizer { get; set; } 21 21 22 22 23 public string GenerateTemplate(IOptimizer optimizer) { 23 24 // data container … … 33 34 // which have parameters aswell 34 35 AddIItem(optimizer); 35 36 36 // save the JArray with JsonItems (= IParameterizedItems) 37 37 Template[Constants.Parameters] = JArrayItems; … … 45 45 Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl"; 46 46 47 JArray ResultItems = new JArray(); 48 47 49 JArrayItems = new JArray(); 48 50 foreach (var item in items) { 49 JArrayItems.Add(Serialize(item)); 51 if (item is ResultItem) 52 ResultItems.Add(Serialize(item)); 53 else 54 JArrayItems.Add(Serialize(item)); 50 55 } 51 56 Template[Constants.Parameters] = JArrayItems; 57 Template[Constants.ActivatedResults] = ResultItems; 58 59 // serialize template and return string 60 return SingleLineArrayJsonWriter.Serialize(Template); 61 } 62 63 public string GenerateTemplate(JsonItem rootItem, IOptimizer optimizer) { 64 // data container 65 Template = JObject.Parse(Constants.Template); 66 JsonItems = new List<JsonItem>(); 67 68 // extract JsonItem, save the name in the metadata section of the 69 // template and save it an JArray incl. all parameters of the JsonItem, 70 // which have parameters aswell 71 Template[Constants.Metadata][Constants.Optimizer] = optimizer.Name; 72 PopulateJsonItems(rootItem); 73 74 ProtoBufSerializer serializer = new ProtoBufSerializer(); 75 serializer.Serialize(Optimizer, @"C:\Workspace\template.hl"); 76 Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl"; 77 78 JArray ResultItems = new JArray(); 79 80 JArrayItems = new JArray(); 81 foreach (var item in JsonItems) { 82 if (item is ResultItem) 83 ResultItems.Add(Serialize(item)); 84 else 85 JArrayItems.Add(Serialize(item)); 86 } 87 Template[Constants.Parameters] = JArrayItems; 88 Template[Constants.ActivatedResults] = ResultItems; 52 89 53 90 // serialize template and return string … … 81 118 private void PopulateJsonItems(JsonItem item) { 82 119 IEnumerable<JsonItem> tmpParameter = item.Children; 83 84 if (item.Value != null || item.Range != null ) {120 121 if (item.Value != null || item.Range != null || item is ResultItem || item.ActualName != null) { 85 122 JsonItems.Add(item); 86 123 }
Note: See TracChangeset
for help on using the changeset viewer.