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 | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.IO;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading;
|
---|
7 | using System.Threading.Tasks;
|
---|
8 | using HeuristicLab.Optimization;
|
---|
9 |
|
---|
10 | namespace 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.