Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18046


Ignore:
Timestamp:
09/02/21 16:42:16 (3 years ago)
Author:
dpiringe
Message:

#3026

  • added a first version of a new feature called ResultCollectionPostProcessors, which should transform/process the results of an optimizer run
    • created a new interface IResultCollectionPostProcessor
    • created a new class SymRegPythonPostProcessor, which formats all ISymbolicRegressionSolution with the usage of the SymbolicDataAnalysisExpressionPythonFormatter
    • changed the generation and instantiation of templates to handle this new feature
    • the template files contains a new area PostProcessors
    • added functionality in Runner to use these new type of result processing
    • added a new tab in ExportJsonDialog to configure PostProcessors
Location:
branches/3026_IntegrationIntoSymSpace
Files:
3 added
6 edited

Legend:

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

    r18045 r18046  
    2222      Task task = optimizer.StartAsync();
    2323      while (!task.IsCompleted) {
    24         WriteResultsToFile(outputFile, optimizer, configuredResultItem);
     24        WriteResultsToFile(outputFile, optimizer, configuredResultItem, instantiatorResult.PostProcessors);
    2525        Thread.Sleep(100);
    2626      }
    2727
    28       WriteResultsToFile(outputFile, optimizer, configuredResultItem);
     28      WriteResultsToFile(outputFile, optimizer, configuredResultItem, instantiatorResult.PostProcessors);
    2929    }
    3030
    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) {
    3232      if (optimizer.Runs.Count > 0)
    33         File.WriteAllText(file, FetchResults(optimizer, configuredResultItem));
     33        File.WriteAllText(file, FetchResults(optimizer, configuredResultItem, postProcessors));
    3434    }
    3535     
     
    4141      ResultFormatter?.Where(x => x.GetType().FullName == fullName).Last();
    4242
    43     private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems) {
     43    private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionPostProcessor> postProcessors) {
    4444      JArray arr = new JArray();
    4545      IEnumerable<string> configuredResults = configuredResultItems.Select(x => x.Name);
     
    6666            obj.Add(result.Item1.Name, formatter.Format(result.Item2));
    6767        }
     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        }
    6876      }
    6977      return SingleLineArrayJsonWriter.Serialize(arr);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs

    r17828 r18046  
    1 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     1using HeuristicLab.Core;
     2
     3namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    24  partial class ExportJsonDialog {
    35    /// <summary>
     
    3840      this.tabPage1 = new System.Windows.Forms.TabPage();
    3941      this.tabPage2 = new System.Windows.Forms.TabPage();
     42      this.tabPage3 = new System.Windows.Forms.TabPage();
    4043      this.label1 = new System.Windows.Forms.Label();
    4144      this.textBoxTemplateName = new System.Windows.Forms.TextBox();
     
    172175      this.splitContainer2.SplitterDistance = 380;
    173176      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;
    174183      //
    175184      // tabControl1
     
    180189      this.tabControl1.Controls.Add(this.tabPage1);
    181190      this.tabControl1.Controls.Add(this.tabPage2);
     191      this.tabControl1.Controls.Add(this.tabPage3);
    182192      this.tabControl1.Location = new System.Drawing.Point(12, 38);
    183193      this.tabControl1.Name = "tabControl1";
     
    207217      this.tabPage2.Text = "Results";
    208218      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;
    209229      //
    210230      // label1
     
    289309    private System.Windows.Forms.GroupBox groupBox;
    290310    private System.Windows.Forms.Panel panelResultDetails;
     311    private System.Windows.Forms.TabPage tabPage3;
     312    private Core.Views.CheckedItemListView<IResultCollectionPostProcessor> postProcessorListView;
    291313  }
    292314}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r18043 r18046  
    44using System.Drawing;
    55using System.IO;
     6using System.Linq;
    67using System.Windows.Forms;
    78using HeuristicLab.Common;
     9using HeuristicLab.Core;
    810using HeuristicLab.Optimization;
    911using HeuristicLab.PluginInfrastructure;
     
    2022    private IOptimizer Optimizer { get; set; }
    2123    private IList<IJsonItemVM> VMs { get; set; }
     24    private ICheckedItemList<IResultCollectionPostProcessor> PostProcessors { get; set; }
    2225    #endregion
    2326
     
    2730      set {
    2831        content = value;
    29 
     32        //CheckedItemListView
    3033        #region Clear
    3134        VMs = new List<IJsonItemVM>();
     
    3336        treeViewResults.Nodes.Clear();
    3437        #endregion
    35 
    3638        Optimizer = content as IOptimizer;
    3739        if(Optimizer != null) {
     
    5961    public ExportJsonDialog() {
    6062      InitializeComponent();
     63      this.PostProcessors = this.postProcessorListView.Content;
    6164      this.Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon;
    6265      InitCache();
     
    7174      if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) {
    7275        try {
     76          //foreach(var x in PostProcessors.CheckedItems)
     77           
    7378          JsonTemplateGenerator.GenerateTemplate(
    7479            Path.Combine(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text),
    75             Optimizer, Root);
     80            Optimizer, Root, PostProcessors.CheckedItems.Select(x => x.Value));
    7681          Close();
    7782        } catch (Exception ex) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r18044 r18046  
    5353    <Reference Include="System" />
    5454    <Reference Include="System.Core" />
     55    <Reference Include="System.Drawing" />
    5556    <Reference Include="System.Xml.Linq" />
    5657    <Reference Include="System.Data.DataSetExtensions" />
     
    8283    <Compile Include="Interfaces\IValueJsonItem.cs" />
    8384    <Compile Include="Interfaces\IValueLookupJsonItem.cs" />
     85    <Compile Include="Interfaces\IResultCollectionPostProcessor.cs" />
    8486    <Compile Include="JsonItems\ArrayJsonItem.cs" />
    8587    <Compile Include="JsonItems\BoolJsonItems.cs" />
     
    103105    <Compile Include="JsonItems\ValueJsonItem.cs" />
    104106    <Compile Include="JsonItems\ValueLookupJsonItem.cs" />
     107    <Compile Include="ResultCollectionPostProcessors\SymRegPythonPostProcessor.cs" />
    105108    <Compile Include="ResultFormatters\MatlabResultFormatter.cs" />
    106109    <Compile Include="ResultFormatters\PythonResultFormatter.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs

    r18040 r18046  
    55using System.IO;
    66using HeuristicLab.Core;
     7using System.Linq;
    78
    89namespace HeuristicLab.JsonInterface {
     
    1819    /// <param name="optimizer">the optimizer object to serialize</param>
    1920    /// <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) {
    2122      // clear all runs
    2223      optimizer.Runs.Clear();
     
    3132      JArray parameterItems = new JArray();
    3233      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
    3342      IList<IJsonItem> jsonItems = new List<IJsonItem>();
    3443     
     
    6776      template[Constants.Parameters] = parameterItems;
    6877      template[Constants.Results] = resultItems;
     78      template["PostProcessors"] = postProcessorItems;
    6979      #endregion
    7080
     
    7686    #region Helper   
    7787    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?
    7989        if (x.Active && !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)) {
    8090          jsonItems.Add(x);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r18040 r18046  
    66using HEAL.Attic;
    77using HeuristicLab.Optimization;
     8using HeuristicLab.PluginInfrastructure;
    89using Newtonsoft.Json.Linq;
    910
     
    1314      Optimizer = optimizer;
    1415      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;
    1523    }
    1624
    1725    public IOptimizer Optimizer { get; }
    1826    public IEnumerable<IResultJsonItem> ConfiguredResultItems { get; }
     27    public IEnumerable<IResultCollectionPostProcessor> PostProcessors { get; }
    1928  }
    2029
     
    8594      JsonItemConverter.Inject(optimizer, rootItem);
    8695
    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);
    88107    }
    89108
Note: See TracChangeset for help on using the changeset viewer.