- Timestamp:
- 02/17/20 17:29:52 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/HeuristicLab.JsonInterface.App.csproj
r17439 r17442 38 38 </PropertyGroup> 39 39 <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> 40 43 <Reference Include="System" /> 41 44 <Reference Include="System.Core" /> … … 49 52 <ItemGroup> 50 53 <None Include="HeuristicLab.snk" /> 54 <None Include="packages.config" /> 51 55 <None Include="Plugin.cs.frame" /> 52 56 <Compile Include="Runner.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Plugin.cs.frame
r17330 r17442 38 38 public class HeuristicLabJsonInterfaceAppApplication : ApplicationBase { 39 39 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()); 42 42 } 43 43 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs
r17439 r17442 8 8 using HeuristicLab.Optimization; 9 9 using HeuristicLab.SequentialEngine; 10 using Newtonsoft.Json.Linq; 10 11 11 12 namespace HeuristicLab.JsonInterface.App { 12 13 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); 15 16 if(optimizer is EngineAlgorithm e) 16 17 e.Engine = new SequentialEngine.SequentialEngine(); … … 18 19 Task task = optimizer.StartAsync(); 19 20 while(!task.IsCompleted) { 20 WriteResultsToFile(outputFile, optimizer );21 WriteResultsToFile(outputFile, optimizer, allowedResultNames); 21 22 Thread.Sleep(100); 22 23 } 23 WriteResultsToFile(outputFile, optimizer );24 WriteResultsToFile(outputFile, optimizer, allowedResultNames); 24 25 } 25 26 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)); 28 29 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 31 33 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())); 33 37 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())); 35 40 } 36 41 } 37 return sb.ToString();42 return SingleLineArrayJsonWriter.Serialize(arr); 38 43 } 39 44 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r17439 r17442 25 25 } 26 26 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 27 36 /// <summary> 28 37 /// Instantiate an IAlgorithm object with a template and config. … … 31 40 /// <param name="configFile">Config file (json) for the template.</param> 32 41 /// <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) { 34 43 InstData instData = new InstData() { 35 44 Objects = new Dictionary<string, IJsonItem>() … … 63 72 JsonItemConverter.Inject(optimizer, optimizerData); 64 73 74 allowedResultNames = CollectResults(instData); 75 65 76 return optimizer; 66 77 } … … 70 81 private static object GetValueFromJObject(JObject obj) => 71 82 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 } 72 91 73 92 private static void CollectParameterizedItems(InstData instData) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/SingleLineArrayJsonWriter.cs
r17406 r17442 8 8 /// It collapses arrays into a single line. 9 9 /// </summary> 10 internalclass SingleLineArrayJsonWriter : JsonTextWriter {10 public class SingleLineArrayJsonWriter : JsonTextWriter { 11 11 private bool isRangeArray = false; 12 12 public override void WriteStartArray() { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/StartArgument.cs
r17180 r17442 32 32 33 33 protected override bool CheckValidity() { 34 return !string.IsNullOr Empty(Value) && !string.IsNullOrWhiteSpace(Value);34 return !string.IsNullOrWhiteSpace(Value); 35 35 } 36 36 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs
r17180 r17442 54 54 case StartArgument.TOKEN: return new StartArgument(value); 55 55 case HideStarterArgument.TOKEN: return new HideStarterArgument(value); 56 default: return n ull;56 default: return new StringArgument(value); 57 57 } 58 58 } else return new OpenArgument(entry); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj
r16565 r17442 223 223 <Compile Include="CommandLineArgumentHandling\Arguments\HideStarterArgument.cs" /> 224 224 <Compile Include="CommandLineArgumentHandling\Arguments\StartArgument.cs" /> 225 <Compile Include="CommandLineArgumentHandling\Arguments\StringArgument.cs" /> 225 226 <Compile Include="CommandLineArgumentHandling\CommandLineArgument.cs" /> 226 227 <Compile Include="CommandLineArgumentHandling\CommandLineArgumentHandling.cs" /> -
branches/3026_IntegrationIntoSymSpace/Heuristiclab.ConfigStarter/Program.cs
r17439 r17442 53 53 arguments.Add(new OpenArgument(@"C:\Workspace\Template.json")); 54 54 arguments.Add(new OpenArgument(@"C:\Workspace\ConfigProto1.json")); 55 arguments.Add(new StringArgument(@"C:\Workspace\Output.json")); 55 56 56 57 app.Run(arguments.ToArray());
Note: See TracChangeset
for help on using the changeset viewer.