Changeset 17395
- Timestamp:
- 01/07/20 17:19:05 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs
r17394 r17395 11 11 internal static class Runner { 12 12 internal static void Run(string template, string config, string outputFile = @"C:\Workspace\test.txt") { 13 I Algorithm alg= JsonTemplateInstantiator.Instantiate(template, config);13 IOptimizer optimizer = JsonTemplateInstantiator.Instantiate(template, config); 14 14 15 Task task = alg.StartAsync();15 Task task = optimizer.StartAsync(); 16 16 while(!task.IsCompleted) { 17 WriteResultsToFile(outputFile, alg);17 WriteResultsToFile(outputFile, optimizer); 18 18 Thread.Sleep(100); 19 19 } 20 WriteResultsToFile(outputFile, alg);20 WriteResultsToFile(outputFile, optimizer); 21 21 } 22 22 23 private static void WriteResultsToFile(string file, I Algorithmoptimizer) =>23 private static void WriteResultsToFile(string file, IOptimizer optimizer) => 24 24 File.WriteAllText(file, FetchResults(optimizer)); 25 25 26 private static string FetchResults(I Algorithmoptimizer) {26 private static string FetchResults(IOptimizer optimizer) { 27 27 StringBuilder sb = new StringBuilder(); 28 //foreach (var run in optimizer.Runs) {29 //sb.AppendLine($"--- {run.ToString()} ---");30 foreach (var res in optimizer.Results) {31 sb.AppendLine($"{res. Name}: {res.Value}");28 foreach (var run in optimizer.Runs) { 29 sb.AppendLine($"--- {run.ToString()} ---"); 30 foreach (var res in run.Results) { 31 sb.AppendLine($"{res.Key}: {res.Value}"); 32 32 } 33 //}33 } 34 34 return sb.ToString(); 35 35 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs
r17379 r17395 12 12 13 13 internal const string Metadata = "Metadata"; 14 internal const string Algorithm = "Algorithm";14 internal const string Optimizer = "Optimizer"; 15 15 internal const string Problem = "Problem"; 16 16 internal const string HLFileLocation = "HLFileLocation"; … … 19 19 internal const string Template = @"{ 20 20 '" + Metadata + @"': { 21 '" + Algorithm+ @"':'',21 '" + Optimizer + @"':'', 22 22 '" + Problem + @"':'', 23 23 '" + HLFileLocation + @"':'' -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs
r17394 r17395 26 26 27 27 public abstract void InjectData(IItem item, JsonItem data, IJsonItemConverter root); 28 public abstract void Populate(IItem value, JsonItem item, IJsonItemConverter root); 28 public abstract void Populate(IItem value, JsonItem item, IJsonItemConverter root); // TODO: populate? 29 29 30 30 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17394 r17395 62 62 <ItemGroup> 63 63 <Compile Include="Constants.cs" /> 64 <Compile Include="Converters\AlgorithmConverter.cs" /> 64 65 <Compile Include="Converters\RegressionProblemDataConverter.cs" /> 65 66 <Compile Include="Converters\ValueLookupParameterConverter.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17394 r17395 20 20 } 21 21 22 public static string GenerateTemplate(I Algorithm algorithm) {22 public static string GenerateTemplate(IOptimizer optimizer) { 23 23 // data container 24 24 GenData genData = new GenData() { … … 28 28 29 29 ProtoBufSerializer serializer = new ProtoBufSerializer(); 30 serializer.Serialize( algorithm, @"C:\Workspace\template.hl");30 serializer.Serialize(optimizer, @"C:\Workspace\template.hl"); 31 31 genData.Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl"; 32 32 … … 34 34 // template and save it an JArray incl. all parameters of the JsonItem, 35 35 // which have parameters aswell 36 AddInstantiableIItem(Constants.Algorithm, algorithm, genData); 37 if (algorithm.Problem != null) // only when an problem exists 38 AddInstantiableIItem(Constants.Problem, algorithm.Problem, genData); 36 AddInstantiableIItem(Constants.Optimizer, optimizer, genData); 39 37 40 38 // save the JArray with JsonItems (= IParameterizedItems) -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r17394 r17395 29 29 /// <param name="templateFile">Template file (json), generated with JCGenerator.</param> 30 30 /// <param name="configFile">Config file (json) for the template.</param> 31 /// <returns>confugrated I Algorithmobject</returns>32 public static I AlgorithmInstantiate(string templateFile, string configFile = "") {31 /// <returns>confugrated IOptimizer object</returns> 32 public static IOptimizer Instantiate(string templateFile, string configFile = "") { 33 33 InstData instData = new InstData() { 34 34 Objects = new Dictionary<string, JsonItem>() … … 41 41 42 42 // extract metadata information 43 string algorithmName = instData.Template[Constants.Metadata][Constants.Algorithm].ToString(); 44 string problemName = instData.Template[Constants.Metadata][Constants.Problem].ToString(); 43 string optimizerName = instData.Template[Constants.Metadata][Constants.Optimizer].ToString(); 45 44 string hLFileLocation = instData.Template[Constants.Metadata][Constants.HLFileLocation].ToString(); 46 45 47 46 // deserialize hl file 48 47 ProtoBufSerializer serializer = new ProtoBufSerializer(); 49 I Algorithm algorithm = (IAlgorithm)serializer.Deserialize(hLFileLocation);48 IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation); 50 49 51 50 // collect all parameterizedItems from template … … 57 56 58 57 // get algorthm data and object 59 JsonItem algorithmData = GetData(algorithmName, instData); 60 61 // get problem data and object 62 JsonItem problemData = GetData(problemName, instData); 58 JsonItem optimizerData = instData.Objects[optimizerName]; 63 59 64 60 // inject configuration 65 JsonItemConverter.Inject(algorithm, algorithmData); 66 if(algorithm.Problem != null) 67 JsonItemConverter.Inject(algorithm.Problem, problemData); 61 JsonItemConverter.Inject(optimizer, optimizerData); 68 62 69 return algorithm;63 return optimizer; 70 64 } 71 65
Note: See TracChangeset
for help on using the changeset viewer.