Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17395


Ignore:
Timestamp:
01/07/20 17:19:05 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • moved from usage of IAlgorithm to IOptimizer (in JCGenerator and JsonTemplateInstantiator)
  • added new converter: AlgorithmConverter
Location:
branches/3026_IntegrationIntoSymSpace
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs

    r17394 r17395  
    1111  internal static class Runner {
    1212    internal static void Run(string template, string config, string outputFile = @"C:\Workspace\test.txt") {
    13       IAlgorithm alg = JsonTemplateInstantiator.Instantiate(template, config);
     13      IOptimizer optimizer = JsonTemplateInstantiator.Instantiate(template, config);
    1414 
    15       Task task = alg.StartAsync();
     15      Task task = optimizer.StartAsync();
    1616      while(!task.IsCompleted) {
    17         WriteResultsToFile(outputFile, alg);
     17        WriteResultsToFile(outputFile, optimizer);
    1818        Thread.Sleep(100);
    1919      }
    20       WriteResultsToFile(outputFile, alg);
     20      WriteResultsToFile(outputFile, optimizer);
    2121    }
    2222
    23     private static void WriteResultsToFile(string file, IAlgorithm optimizer) =>
     23    private static void WriteResultsToFile(string file, IOptimizer optimizer) =>
    2424      File.WriteAllText(file, FetchResults(optimizer));
    2525
    26     private static string FetchResults(IAlgorithm optimizer) {
     26    private static string FetchResults(IOptimizer optimizer) {
    2727      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}");
    3232        }
    33       //}
     33      }
    3434      return sb.ToString();
    3535    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs

    r17379 r17395  
    1212
    1313    internal const string Metadata = "Metadata";
    14     internal const string Algorithm = "Algorithm";
     14    internal const string Optimizer = "Optimizer";
    1515    internal const string Problem = "Problem";
    1616    internal const string HLFileLocation = "HLFileLocation";
     
    1919    internal const string Template = @"{
    2020      '" + Metadata + @"': {
    21         '" + Algorithm + @"':'',
     21        '" + Optimizer + @"':'',
    2222        '" + Problem + @"':'',
    2323        '" + HLFileLocation + @"':''
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs

    r17394 r17395  
    2626   
    2727    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?
    2929
    3030    #region Helper
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r17394 r17395  
    6262  <ItemGroup>
    6363    <Compile Include="Constants.cs" />
     64    <Compile Include="Converters\AlgorithmConverter.cs" />
    6465    <Compile Include="Converters\RegressionProblemDataConverter.cs" />
    6566    <Compile Include="Converters\ValueLookupParameterConverter.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs

    r17394 r17395  
    2020    }
    2121   
    22     public static string GenerateTemplate(IAlgorithm algorithm) {
     22    public static string GenerateTemplate(IOptimizer optimizer) {
    2323      // data container
    2424      GenData genData = new GenData() {
     
    2828
    2929      ProtoBufSerializer serializer = new ProtoBufSerializer();
    30       serializer.Serialize(algorithm, @"C:\Workspace\template.hl");
     30      serializer.Serialize(optimizer, @"C:\Workspace\template.hl");
    3131      genData.Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl";
    3232
     
    3434      // template and save it an JArray incl. all parameters of the JsonItem,
    3535      // 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);
    3937
    4038      // save the JArray with JsonItems (= IParameterizedItems)
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r17394 r17395  
    2929    /// <param name="templateFile">Template file (json), generated with JCGenerator.</param>
    3030    /// <param name="configFile">Config file (json) for the template.</param>
    31     /// <returns>confugrated IAlgorithm object</returns>
    32     public static IAlgorithm Instantiate(string templateFile, string configFile = "") {
     31    /// <returns>confugrated IOptimizer object</returns>
     32    public static IOptimizer Instantiate(string templateFile, string configFile = "") {
    3333      InstData instData = new InstData() {
    3434        Objects = new Dictionary<string, JsonItem>()
     
    4141
    4242      // 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();
    4544      string hLFileLocation = instData.Template[Constants.Metadata][Constants.HLFileLocation].ToString();
    4645
    4746      // deserialize hl file
    4847      ProtoBufSerializer serializer = new ProtoBufSerializer();
    49       IAlgorithm algorithm = (IAlgorithm)serializer.Deserialize(hLFileLocation);
     48      IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation);
    5049
    5150      // collect all parameterizedItems from template
     
    5756
    5857      // 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];
    6359
    6460      // inject configuration
    65       JsonItemConverter.Inject(algorithm, algorithmData);
    66       if(algorithm.Problem != null)
    67         JsonItemConverter.Inject(algorithm.Problem, problemData);
     61      JsonItemConverter.Inject(optimizer, optimizerData);
    6862
    69       return algorithm;
     63      return optimizer;
    7064    }
    7165
Note: See TracChangeset for help on using the changeset viewer.