Last change
on this file since 17349 was
17349,
checked in by dpiringe, 5 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 | |
---|
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 | 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.