Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17399 was 17395, checked in by dpiringe, 5 years ago

#3026:

  • moved from usage of IAlgorithm to IOptimizer (in JCGenerator and JsonTemplateInstantiator)
  • added new converter: AlgorithmConverter
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      IOptimizer optimizer = JsonTemplateInstantiator.Instantiate(template, config);
14 
15      Task task = optimizer.StartAsync();
16      while(!task.IsCompleted) {
17        WriteResultsToFile(outputFile, optimizer);
18        Thread.Sleep(100);
19      }
20      WriteResultsToFile(outputFile, optimizer);
21    }
22
23    private static void WriteResultsToFile(string file, IOptimizer optimizer) =>
24      File.WriteAllText(file, FetchResults(optimizer));
25
26    private static string FetchResults(IOptimizer optimizer) {
27      StringBuilder sb = new StringBuilder();
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        }
33      }
34      return sb.ToString();
35    }
36  }
37}
Note: See TracBrowser for help on using the repository browser.