Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17442 for branches


Ignore:
Timestamp:
02/17/20 17:29:52 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • added new CLI argument StringArgument
  • removed unnecessary check in StartArgument
  • changed output format from simple .txt to .json in HeuristicLab.JsonInterface.App.Runner
  • user has to enter output path now when executing JsonInterface on console
Location:
branches/3026_IntegrationIntoSymSpace
Files:
9 edited

Legend:

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

    r17439 r17442  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
     41      <HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
     42    </Reference>
    4043    <Reference Include="System" />
    4144    <Reference Include="System.Core" />
     
    4952  <ItemGroup>
    5053    <None Include="HeuristicLab.snk" />
     54    <None Include="packages.config" />
    5155    <None Include="Plugin.cs.frame" />
    5256    <Compile Include="Runner.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Plugin.cs.frame

    r17330 r17442  
    3838  public class HeuristicLabJsonInterfaceAppApplication : ApplicationBase {
    3939    public override void Run(ICommandLineArgument[] args) {
    40       if(args.Length == 3 && args[1] is OpenArgument && args[2] is OpenArgument) {
    41         Runner.Run(args[1].Value.ToString(), args[2].Value.ToString());
     40      if(args.Length == 4 && args[1] is OpenArgument && args[2] is OpenArgument && (args[3] is StringArgument || args[3] is OpenArgument)) {
     41        Runner.Run(args[1].Value.ToString(), args[2].Value.ToString(), args[3].Value.ToString());
    4242      }
    4343    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs

    r17439 r17442  
    88using HeuristicLab.Optimization;
    99using HeuristicLab.SequentialEngine;
     10using Newtonsoft.Json.Linq;
    1011
    1112namespace HeuristicLab.JsonInterface.App {
    1213  internal static class Runner {
    13     internal static void Run(string template, string config, string outputFile = @"C:\Workspace\test.txt") {
    14       IOptimizer optimizer = JsonTemplateInstantiator.Instantiate(template, config);
     14    internal static void Run(string template, string config, string outputFile) {
     15      IOptimizer optimizer = JsonTemplateInstantiator.Instantiate(template, config, out IEnumerable<string> allowedResultNames);
    1516      if(optimizer is EngineAlgorithm e)
    1617        e.Engine = new SequentialEngine.SequentialEngine();
     
    1819      Task task = optimizer.StartAsync();
    1920      while(!task.IsCompleted) {
    20         WriteResultsToFile(outputFile, optimizer);
     21        WriteResultsToFile(outputFile, optimizer, allowedResultNames);
    2122        Thread.Sleep(100);
    2223      }
    23       WriteResultsToFile(outputFile, optimizer);
     24      WriteResultsToFile(outputFile, optimizer, allowedResultNames);
    2425    }
    2526
    26     private static void WriteResultsToFile(string file, IOptimizer optimizer) =>
    27       File.WriteAllText(file, FetchResults(optimizer));
     27    private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<string> allowedResultNames) =>
     28      File.WriteAllText(file, FetchResults(optimizer, allowedResultNames));
    2829
    29     private static string FetchResults(IOptimizer optimizer) {
    30       StringBuilder sb = new StringBuilder();
     30    private static string FetchResults(IOptimizer optimizer, IEnumerable<string> allowedResultNames) {
     31      JArray arr = new JArray();
     32     
    3133      foreach (var run in optimizer.Runs) {
    32         sb.AppendLine($"--- {run.ToString()} ---");
     34        JObject obj = new JObject();
     35        arr.Add(obj);
     36        obj.Add("Run", JToken.FromObject(run.ToString()));
    3337        foreach (var res in run.Results) {
    34           sb.AppendLine($"{res.Key}: {res.Value}");
     38          if (allowedResultNames.Contains(res.Key))
     39            obj.Add(res.Key, JToken.FromObject(res.Value.ToString()));
    3540        }
    3641      }
    37       return sb.ToString();
     42      return SingleLineArrayJsonWriter.Serialize(arr);
    3843    }
    3944  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r17439 r17442  
    2525    }
    2626
     27    public static IOptimizer Instantiate(string templateFile) =>
     28      Instantiate(templateFile, null, out IEnumerable<string> allowedResultNames);
     29
     30
     31    public static IOptimizer Instantiate(string templateFile, out IEnumerable<string> allowedResultNames) =>
     32      Instantiate(templateFile, null, out allowedResultNames);
     33
     34   
     35
    2736    /// <summary>
    2837    /// Instantiate an IAlgorithm object with a template and config.
     
    3140    /// <param name="configFile">Config file (json) for the template.</param>
    3241    /// <returns>confugrated IOptimizer object</returns>
    33     public static IOptimizer Instantiate(string templateFile, string configFile = "") {
     42    public static IOptimizer Instantiate(string templateFile, string configFile, out IEnumerable<string> allowedResultNames) {
    3443      InstData instData = new InstData() {
    3544        Objects = new Dictionary<string, IJsonItem>()
     
    6372      JsonItemConverter.Inject(optimizer, optimizerData);
    6473
     74      allowedResultNames = CollectResults(instData);
     75
    6576      return optimizer;
    6677    }
     
    7081    private static object GetValueFromJObject(JObject obj) =>
    7182      obj[nameof(IJsonItem.Value)]?.ToObject<object>();
     83
     84    private static IEnumerable<string> CollectResults(InstData instData) {
     85      IList<string> res = new List<string>();
     86      foreach(JObject obj in instData.Template[Constants.Results]) {
     87        res.Add(obj.Property("Name").Value.ToString());
     88      }
     89      return res;
     90    }
    7291
    7392    private static void CollectParameterizedItems(InstData instData) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/SingleLineArrayJsonWriter.cs

    r17406 r17442  
    88  /// It collapses arrays into a single line.
    99  /// </summary>
    10   internal class SingleLineArrayJsonWriter : JsonTextWriter {
     10  public class SingleLineArrayJsonWriter : JsonTextWriter {
    1111    private bool isRangeArray = false;
    1212    public override void WriteStartArray() {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/StartArgument.cs

    r17180 r17442  
    3232
    3333    protected override bool CheckValidity() {
    34       return !string.IsNullOrEmpty(Value) && !string.IsNullOrWhiteSpace(Value);
     34      return !string.IsNullOrWhiteSpace(Value);
    3535    }
    3636  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs

    r17180 r17442  
    5454          case StartArgument.TOKEN: return new StartArgument(value);
    5555          case HideStarterArgument.TOKEN: return new HideStarterArgument(value);
    56           default: return null;
     56          default: return new StringArgument(value);
    5757        }
    5858      } else return new OpenArgument(entry);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj

    r16565 r17442  
    223223    <Compile Include="CommandLineArgumentHandling\Arguments\HideStarterArgument.cs" />
    224224    <Compile Include="CommandLineArgumentHandling\Arguments\StartArgument.cs" />
     225    <Compile Include="CommandLineArgumentHandling\Arguments\StringArgument.cs" />
    225226    <Compile Include="CommandLineArgumentHandling\CommandLineArgument.cs" />
    226227    <Compile Include="CommandLineArgumentHandling\CommandLineArgumentHandling.cs" />
  • branches/3026_IntegrationIntoSymSpace/Heuristiclab.ConfigStarter/Program.cs

    r17439 r17442  
    5353      arguments.Add(new OpenArgument(@"C:\Workspace\Template.json"));
    5454      arguments.Add(new OpenArgument(@"C:\Workspace\ConfigProto1.json"));
     55      arguments.Add(new StringArgument(@"C:\Workspace\Output.json"));
    5556
    5657      app.Run(arguments.ToArray());
Note: See TracChangeset for help on using the changeset viewer.