Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs @ 17349

Last change on this file since 17349 was 17349, checked in by dpiringe, 4 years ago

#3026

  • added ConvertableAttribute, a new attribute for classes/structs (usage: convertable with JsonInterface)
  • changed JCGenerator -> is now a static class with one public static method Instantiate
  • changed JCInstantiator -> is now a static class with one public static method GenerateTemplate
  • refactored JsonItem
File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Text;
6using System.Threading;
7using System.Threading.Tasks;
8using HeuristicLab.Optimization;
9
10namespace HeuristicLab.JsonInterface.App {
11  internal static class Runner {
12    internal static void Run(string template, string config, string outputFile = @"C:\Workspace\test.txt") {
13      IAlgorithm alg = JCInstantiator.Instantiate(template, config);
14 
15      Task task = alg.StartAsync();
16      while(!task.IsCompleted) {
17        WriteResultsToFile(outputFile, alg);
18        Thread.Sleep(100);
19      }
20      WriteResultsToFile(outputFile, alg);
21    }
22
23    private static void WriteResultsToFile(string file, IAlgorithm optimizer) =>
24      File.WriteAllText(file, FetchResults(optimizer));
25
26    private static string FetchResults(IAlgorithm optimizer) {
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}");
32        }
33      //}
34      return sb.ToString();
35    }
36  }
37}
Note: See TracBrowser for help on using the repository browser.