- Timestamp:
- 10/15/19 15:29:36 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs
r17287 r17330 8 8 internal class Constants { 9 9 10 publicconst string Metadata = "Metadata";11 publicconst string Algorithm = "Algorithm";12 publicconst string Problem = "Problem";13 publicconst string Objects = "Objects";14 publicconst string Types = "Types";15 publicconst string StaticParameters = "StaticParameters";16 publicconst string FreeParameters = "FreeParameters";10 internal const string Metadata = "Metadata"; 11 internal const string Algorithm = "Algorithm"; 12 internal const string Problem = "Problem"; 13 internal const string Objects = "Objects"; 14 internal const string Types = "Types"; 15 internal const string StaticParameters = "StaticParameters"; 16 internal const string FreeParameters = "FreeParameters"; 17 17 18 publicconst string Template = @"{18 internal const string Template = @"{ 19 19 'Metadata': { 20 20 'Algorithm':'', -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs
r17284 r17330 27 27 JsonItem data = JsonItemConverter.Extract(param); 28 28 data.Name = param.Name; 29 data.Path = param.Name;29 data.Path = data.Name; 30 30 data.PrependPath(item.Path); 31 31 data.UpdatePaths(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17324 r17330 15 15 private JArray JsonItems { get; set; } = new JArray(); 16 16 17 public string GenerateTemplate(IAlgorithm algorithm) { 18 JsonItems.Clear(); 19 TypeList.Clear(); 20 21 // 1.1. extract JsonItem, save the name in the metadata section of the 22 // template and save it an JArray incl. all parameters of the JsonItem, 23 // which have parameters aswell 24 AddInstantiableIItem(Constants.Algorithm, algorithm); 25 if (algorithm.Problem != null) // 1.2. only when an problem exists 26 AddInstantiableIItem(Constants.Problem, algorithm.Problem); 27 28 // 2. save the JArray with JsonItems (= IParameterizedItems) 29 template[Constants.Objects] = JsonItems; 30 // 3. save the types of the JsonItems (for instatiation) 31 template[Constants.Types] = JObject.FromObject(TypeList); 32 // 4. serialize template and return string 33 return CustomJsonWriter.Serialize(template); 34 } 35 36 #region Helper 37 private void AddInstantiableIItem(string metaDataTagName, IItem item) { 38 JsonItem jsonItem = JsonItemConverter.Extract(item); 39 template[Constants.Metadata][metaDataTagName] = item.ItemName; 40 PopulateJsonItems(jsonItem); 41 } 42 17 43 private void PopulateJsonItems(JsonItem item) { 18 44 if (item.Parameters != null) { 19 if (item.Range == null)45 if (item.Range == null) 20 46 JsonItems.Add(Serialize(item)); 21 47 foreach (var p in item.Parameters) 22 if (p.Parameters != null)48 if (p.Parameters != null) 23 49 PopulateJsonItems(p); 24 50 } … … 31 57 32 58 obj.Property(nameof(JsonItem.Parameters))?.Remove(); 33 RefactorFreeParameters(obj , null);59 RefactorFreeParameters(obj); 34 60 RefactorStaticParameters(obj); 35 61 … … 41 67 } 42 68 43 public string GenerateTemplate(IAlgorithm algorithm, IProblem problem, params string[] freeParameters) { 44 JsonItems.Clear(); 45 TypeList.Clear(); 46 47 algorithm.Problem = problem; 48 JsonItem algorithmData = JsonItemConverter.Extract(algorithm); 49 JsonItem problemData = JsonItemConverter.Extract(problem); 50 PopulateJsonItems(algorithmData); 51 PopulateJsonItems(problemData); 52 53 template[Constants.Metadata][Constants.Algorithm] = algorithm.Name; 54 template[Constants.Metadata][Constants.Problem] = problem.Name; 55 template[Constants.Objects] = JsonItems; 56 template[Constants.Types] = JObject.FromObject(TypeList); 57 58 return CustomJsonWriter.Serialize(template); 59 } 60 61 #region Helper 62 private void RefactorFreeParameters(JToken token, string[] freeParameters) { 69 private void RefactorFreeParameters(JToken token) { 63 70 IList<JObject> objToRemove = new List<JObject>(); 64 71 TransformNodes(x => { 65 72 var p = x.ToObject<JsonItem>(); 66 67 /*bool isSelected = false; 68 string name = x["Name"].ToObject<string>(); 69 foreach (var selected in freeParameters) 70 isSelected = (name == selected || isSelected); 71 */ 72 if (/*!isSelected ||*/ p.Default == null || (p.Default != null && p.Default.GetType() == typeof(string) && p.Range == null)) { 73 if (p.Default == null || (p.Default != null && p.Default.GetType() == typeof(string) && p.Range == null)) { 73 74 objToRemove.Add(x); 74 75 } else { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCInstantiator.cs
r17324 r17330 23 23 private IDictionary<string, JsonItem> ConfigurableItems { get; set; } = new Dictionary<string, JsonItem>(); 24 24 25 public IAlgorithm Instantiate(string templateFile, string configFile ) {25 public IAlgorithm Instantiate(string templateFile, string configFile = "") { 26 26 27 27 //1. Parse Template and Config files 28 28 Template = JToken.Parse(File.ReadAllText(templateFile)); 29 Config = JArray.Parse(File.ReadAllText(configFile)); 29 if(!string.IsNullOrEmpty(configFile)) 30 Config = JArray.Parse(File.ReadAllText(configFile)); 30 31 TypeList = Template[Constants.Types].ToObject<Dictionary<string, string>>(); 31 32 string algorithmName = Template[Constants.Metadata][Constants.Algorithm].ToString(); … … 38 39 SelectConfigurableItems(); 39 40 40 //4. Merge Template and Config 41 MergeTemplateWithConfig(); 41 //4. if config != null -> merge Template and Config 42 if (Config != null) 43 MergeTemplateWithConfig(); 42 44 43 45 //5. resolve the references between parameterizedItems -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Plugin.cs.frame
r17324 r17330 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.IO;26 using System.Text;27 using System.Threading.Tasks;28 22 using HeuristicLab.PluginInfrastructure; 29 23
Note: See TracChangeset
for help on using the changeset viewer.