Changeset 18046
- Timestamp:
- 09/02/21 16:42:16 (3 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs
r18045 r18046 22 22 Task task = optimizer.StartAsync(); 23 23 while (!task.IsCompleted) { 24 WriteResultsToFile(outputFile, optimizer, configuredResultItem );24 WriteResultsToFile(outputFile, optimizer, configuredResultItem, instantiatorResult.PostProcessors); 25 25 Thread.Sleep(100); 26 26 } 27 27 28 WriteResultsToFile(outputFile, optimizer, configuredResultItem );28 WriteResultsToFile(outputFile, optimizer, configuredResultItem, instantiatorResult.PostProcessors); 29 29 } 30 30 31 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItem ) {31 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItem, IEnumerable<IResultCollectionPostProcessor> postProcessors) { 32 32 if (optimizer.Runs.Count > 0) 33 File.WriteAllText(file, FetchResults(optimizer, configuredResultItem ));33 File.WriteAllText(file, FetchResults(optimizer, configuredResultItem, postProcessors)); 34 34 } 35 35 … … 41 41 ResultFormatter?.Where(x => x.GetType().FullName == fullName).Last(); 42 42 43 private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems ) {43 private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionPostProcessor> postProcessors) { 44 44 JArray arr = new JArray(); 45 45 IEnumerable<string> configuredResults = configuredResultItems.Select(x => x.Name); … … 66 66 obj.Add(result.Item1.Name, formatter.Format(result.Item2)); 67 67 } 68 69 IDictionary<string, string> resultDict = new Dictionary<string, string>(); 70 foreach (var processor in postProcessors) { 71 processor.Apply(run.Results, resultDict); 72 } 73 foreach(var kvp in resultDict) { 74 obj.Add(kvp.Key, kvp.Value); 75 } 68 76 } 69 77 return SingleLineArrayJsonWriter.Serialize(arr); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs
r17828 r18046 1 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 1 using HeuristicLab.Core; 2 3 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 2 4 partial class ExportJsonDialog { 3 5 /// <summary> … … 38 40 this.tabPage1 = new System.Windows.Forms.TabPage(); 39 41 this.tabPage2 = new System.Windows.Forms.TabPage(); 42 this.tabPage3 = new System.Windows.Forms.TabPage(); 40 43 this.label1 = new System.Windows.Forms.Label(); 41 44 this.textBoxTemplateName = new System.Windows.Forms.TextBox(); … … 172 175 this.splitContainer2.SplitterDistance = 380; 173 176 this.splitContainer2.TabIndex = 9; 177 // postProcessorListView 178 this.postProcessorListView = new Core.Views.CheckedItemListView<IResultCollectionPostProcessor>(); 179 this.postProcessorListView.Content = new CheckedItemList<IResultCollectionPostProcessor>(); 180 this.postProcessorListView.Content.Add(new SymRegPythonPostProcessor()); 181 this.postProcessorListView.Location = new System.Drawing.Point(0, 6); 182 this.postProcessorListView.Dock = System.Windows.Forms.DockStyle.Fill; 174 183 // 175 184 // tabControl1 … … 180 189 this.tabControl1.Controls.Add(this.tabPage1); 181 190 this.tabControl1.Controls.Add(this.tabPage2); 191 this.tabControl1.Controls.Add(this.tabPage3); 182 192 this.tabControl1.Location = new System.Drawing.Point(12, 38); 183 193 this.tabControl1.Name = "tabControl1"; … … 207 217 this.tabPage2.Text = "Results"; 208 218 this.tabPage2.UseVisualStyleBackColor = true; 219 // 220 // tabPage3 221 // 222 this.tabPage3.Controls.Add(this.postProcessorListView); 223 this.tabPage3.Location = new System.Drawing.Point(4, 22); 224 this.tabPage3.Name = "tabPage3"; 225 this.tabPage3.Size = new System.Drawing.Size(802, 505); 226 this.tabPage3.TabIndex = 2; 227 this.tabPage3.Text = "Post Processors"; 228 this.tabPage3.UseVisualStyleBackColor = true; 209 229 // 210 230 // label1 … … 289 309 private System.Windows.Forms.GroupBox groupBox; 290 310 private System.Windows.Forms.Panel panelResultDetails; 311 private System.Windows.Forms.TabPage tabPage3; 312 private Core.Views.CheckedItemListView<IResultCollectionPostProcessor> postProcessorListView; 291 313 } 292 314 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r18043 r18046 4 4 using System.Drawing; 5 5 using System.IO; 6 using System.Linq; 6 7 using System.Windows.Forms; 7 8 using HeuristicLab.Common; 9 using HeuristicLab.Core; 8 10 using HeuristicLab.Optimization; 9 11 using HeuristicLab.PluginInfrastructure; … … 20 22 private IOptimizer Optimizer { get; set; } 21 23 private IList<IJsonItemVM> VMs { get; set; } 24 private ICheckedItemList<IResultCollectionPostProcessor> PostProcessors { get; set; } 22 25 #endregion 23 26 … … 27 30 set { 28 31 content = value; 29 32 //CheckedItemListView 30 33 #region Clear 31 34 VMs = new List<IJsonItemVM>(); … … 33 36 treeViewResults.Nodes.Clear(); 34 37 #endregion 35 36 38 Optimizer = content as IOptimizer; 37 39 if(Optimizer != null) { … … 59 61 public ExportJsonDialog() { 60 62 InitializeComponent(); 63 this.PostProcessors = this.postProcessorListView.Content; 61 64 this.Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon; 62 65 InitCache(); … … 71 74 if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) { 72 75 try { 76 //foreach(var x in PostProcessors.CheckedItems) 77 73 78 JsonTemplateGenerator.GenerateTemplate( 74 79 Path.Combine(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text), 75 Optimizer, Root );80 Optimizer, Root, PostProcessors.CheckedItems.Select(x => x.Value)); 76 81 Close(); 77 82 } catch (Exception ex) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r18044 r18046 53 53 <Reference Include="System" /> 54 54 <Reference Include="System.Core" /> 55 <Reference Include="System.Drawing" /> 55 56 <Reference Include="System.Xml.Linq" /> 56 57 <Reference Include="System.Data.DataSetExtensions" /> … … 82 83 <Compile Include="Interfaces\IValueJsonItem.cs" /> 83 84 <Compile Include="Interfaces\IValueLookupJsonItem.cs" /> 85 <Compile Include="Interfaces\IResultCollectionPostProcessor.cs" /> 84 86 <Compile Include="JsonItems\ArrayJsonItem.cs" /> 85 87 <Compile Include="JsonItems\BoolJsonItems.cs" /> … … 103 105 <Compile Include="JsonItems\ValueJsonItem.cs" /> 104 106 <Compile Include="JsonItems\ValueLookupJsonItem.cs" /> 107 <Compile Include="ResultCollectionPostProcessors\SymRegPythonPostProcessor.cs" /> 105 108 <Compile Include="ResultFormatters\MatlabResultFormatter.cs" /> 106 109 <Compile Include="ResultFormatters\PythonResultFormatter.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs
r18040 r18046 5 5 using System.IO; 6 6 using HeuristicLab.Core; 7 using System.Linq; 7 8 8 9 namespace HeuristicLab.JsonInterface { … … 18 19 /// <param name="optimizer">the optimizer object to serialize</param> 19 20 /// <param name="rootItem">Root JsonItem for serialization, considers only active JsonItems for serialization</param> 20 public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem ) {21 public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem, IEnumerable<IResultCollectionPostProcessor> postProcessors) { 21 22 // clear all runs 22 23 optimizer.Runs.Clear(); … … 31 32 JArray parameterItems = new JArray(); 32 33 JArray resultItems = new JArray(); 34 JArray postProcessorItems = new JArray(); 35 // postProcessors.Select(x => new JObject().Add("Name", JToken.Parse(x.GetType().Name)) 36 foreach (var proc in postProcessors) { 37 var tmp = new JObject(); 38 tmp.Add("Name", proc.GetType().Name); 39 postProcessorItems.Add(tmp); 40 } 41 33 42 IList<IJsonItem> jsonItems = new List<IJsonItem>(); 34 43 … … 67 76 template[Constants.Parameters] = parameterItems; 68 77 template[Constants.Results] = resultItems; 78 template["PostProcessors"] = postProcessorItems; 69 79 #endregion 70 80 … … 76 86 #region Helper 77 87 private static void PopulateJsonItems(IJsonItem item, IList<IJsonItem> jsonItems) { 78 foreach(var x in item) { 88 foreach(var x in item) { // TODO: dieses konstrukt notwendig? 79 89 if (x.Active && !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)) { 80 90 jsonItems.Add(x); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r18040 r18046 6 6 using HEAL.Attic; 7 7 using HeuristicLab.Optimization; 8 using HeuristicLab.PluginInfrastructure; 8 9 using Newtonsoft.Json.Linq; 9 10 … … 13 14 Optimizer = optimizer; 14 15 ConfiguredResultItems = configuredResultItems; 16 PostProcessors = Enumerable.Empty<IResultCollectionPostProcessor>(); 17 } 18 19 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionPostProcessor> postProcessors) { 20 Optimizer = optimizer; 21 ConfiguredResultItems = configuredResultItems; 22 PostProcessors = postProcessors; 15 23 } 16 24 17 25 public IOptimizer Optimizer { get; } 18 26 public IEnumerable<IResultJsonItem> ConfiguredResultItems { get; } 27 public IEnumerable<IResultCollectionPostProcessor> PostProcessors { get; } 19 28 } 20 29 … … 85 94 JsonItemConverter.Inject(optimizer, rootItem); 86 95 87 return new InstantiatorResult(optimizer, CollectResults()); 96 IList<IResultCollectionPostProcessor> postProcessorList = new List<IResultCollectionPostProcessor>(); 97 var postProcessors = ApplicationManager.Manager.GetInstances<IResultCollectionPostProcessor>(); 98 foreach (JObject obj in Template["PostProcessors"]) { 99 //string name = obj.Property("Name").Value.ToString(); 100 foreach(var proc in postProcessors) { 101 if (proc.GetType().Name == obj["Name"].ToString()) 102 postProcessorList.Add(proc); 103 } 104 } 105 106 return new InstantiatorResult(optimizer, CollectResults(), postProcessorList); 88 107 } 89 108
Note: See TracChangeset
for help on using the changeset viewer.