Changeset 18050
- Timestamp:
- 09/08/21 15:53:37 (3 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 1 added
- 1 deleted
- 9 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Core.Views/3.3/CheckedItemListView.cs
r17180 r18050 43 43 set { base.Content = value; } 44 44 } 45 46 protected virtual string GroupBoxText => "Items"; 45 47 46 48 public CheckedItemListView() … … 179 181 Invoke((Action)SetNumberOfCheckItems); 180 182 } else { 181 this.itemsGroupBox.Text = String.Format(" Items (Checked: {0}/{1})", Content.CheckedItems.Count(), Content.Count);183 this.itemsGroupBox.Text = String.Format("{0} (Checked: {1}/{2})", GroupBoxText, Content.CheckedItems.Count(), Content.Count); 182 184 } 183 185 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs
r18046 r18050 29 29 } 30 30 31 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItem, IEnumerable<IResultCollectionP ostProcessor> postProcessors) {31 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItem, IEnumerable<IResultCollectionProcessor> postProcessors) { 32 32 if (optimizer.Runs.Count > 0) 33 33 File.WriteAllText(file, FetchResults(optimizer, configuredResultItem, postProcessors)); … … 41 41 ResultFormatter?.Where(x => x.GetType().FullName == fullName).Last(); 42 42 43 private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionP ostProcessor> postProcessors) {43 private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionProcessor> postProcessors) { 44 44 JArray arr = new JArray(); 45 45 IEnumerable<string> configuredResults = configuredResultItems.Select(x => x.Name); … … 67 67 } 68 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 } 69 foreach (var processor in postProcessors) 70 processor.Apply(run.Results); 71 72 foreach(var result in run.Results) 73 obj.Add(result.Key, result.Value.ToString()); 76 74 } 77 75 return SingleLineArrayJsonWriter.Serialize(arr); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs
r18047 r18050 177 177 // postProcessorListView 178 178 this.postProcessorListControl = new ResultCollectionPostProcessorControl(); 179 this.postProcessorListControl.Content = new CheckedItemList<IResultCollectionPostProcessor>(); 180 this.postProcessorListControl.Content.Add(new SymRegPythonPostProcessor()); 179 this.postProcessorListControl.Content = new CheckedItemList<IResultCollectionProcessor>(); 181 180 this.postProcessorListControl.Location = new System.Drawing.Point(0, 6); 182 181 this.postProcessorListControl.Dock = System.Windows.Forms.DockStyle.Fill; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r18047 r18050 22 22 private IOptimizer Optimizer { get; set; } 23 23 private IList<IJsonItemVM> VMs { get; set; } 24 private ICheckedItemList<IResultCollectionP ostProcessor> PostProcessors { get; set; }24 private ICheckedItemList<IResultCollectionProcessor> PostProcessors { get; set; } 25 25 #endregion 26 26 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ResultCollectionPostProcessorControl.cs
r18047 r18050 11 11 12 12 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 13 public partial class ResultCollectionPostProcessorControl : Core.Views.CheckedItemListView<IResultCollectionP ostProcessor> {13 public partial class ResultCollectionPostProcessorControl : Core.Views.CheckedItemListView<IResultCollectionProcessor> { 14 14 public ResultCollectionPostProcessorControl() { 15 15 InitializeComponent(); 16 16 } 17 17 18 #region Content Events 19 protected override void OnContentChanged() { 20 base.OnContentChanged(); 21 if (Content != null) { 22 SetNumberOfCheckItems(); 23 } 24 } 18 protected override string GroupBoxText => "Result Collection Processors"; 25 19 26 protected override void Content_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {27 base.Content_CheckedItemsChanged(sender, e);28 if (InvokeRequired)29 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<IResultCollectionPostProcessor>>(Content_CheckedItemsChanged), sender, e);30 else {31 SetNumberOfCheckItems();32 }33 }34 protected override void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {35 base.Content_CollectionReset(sender, e);36 SetNumberOfCheckItems();37 }38 protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {39 base.Content_ItemsAdded(sender, e);40 SetNumberOfCheckItems();41 }42 protected override void Content_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {43 base.Content_ItemsMoved(sender, e);44 SetNumberOfCheckItems();45 }46 protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {47 base.Content_ItemsRemoved(sender, e);48 SetNumberOfCheckItems();49 }50 protected override void Content_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IResultCollectionPostProcessor>> e) {51 base.Content_ItemsReplaced(sender, e);52 SetNumberOfCheckItems();53 }54 #endregion55 56 private void SetNumberOfCheckItems() { // TODO: eigene override für "Post Processors" -> Item Naming57 if (InvokeRequired) {58 Invoke((Action)SetNumberOfCheckItems);59 } else {60 this.itemsGroupBox.Text = String.Format("Post Processors (Checked: {0}/{1})", Content.CheckedItems.Count(), Content.Count);61 }62 }63 20 } 64 21 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs
r17519 r18050 10 10 internal const string Parameters = "Parameters"; 11 11 internal const string Results = "Results"; 12 internal const string ResultCollectionProcessorItems = "ResultCollectionProcessors"; 12 13 13 14 internal const string Template = @"{ … … 17 18 }, 18 19 '" + Parameters + @"': [], 19 '" + Results + @"': [] 20 '" + Results + @"': [], 21 '" + ResultCollectionProcessorItems + @"': [] 20 22 }"; 21 23 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r18046 r18050 66 66 <Compile Include="Converters\BatchRunConverter.cs" /> 67 67 <Compile Include="Converters\ExperimentConverter.cs" /> 68 <Compile Include="Converters\ObervableListConverter.cs" /> 68 69 <Compile Include="Converters\RegressionProblemDataConverter.cs" /> 69 70 <Compile Include="Converters\ResultConverter.cs" /> … … 83 84 <Compile Include="Interfaces\IValueJsonItem.cs" /> 84 85 <Compile Include="Interfaces\IValueLookupJsonItem.cs" /> 85 <Compile Include="Interfaces\IResultCollectionP ostProcessor.cs" />86 <Compile Include="Interfaces\IResultCollectionProcessor.cs" /> 86 87 <Compile Include="JsonItems\ArrayJsonItem.cs" /> 87 88 <Compile Include="JsonItems\BoolJsonItems.cs" /> … … 105 106 <Compile Include="JsonItems\ValueJsonItem.cs" /> 106 107 <Compile Include="JsonItems\ValueLookupJsonItem.cs" /> 107 <Compile Include="ResultCollectionPostProcessors\SymRegPythonPostProcessor.cs" /> 108 <Compile Include="ResultCollectionProcessors\FilterResultCollectionProcessor.cs" /> 109 <Compile Include="ResultCollectionProcessors\SymRegPythonProcessor.cs" /> 108 110 <Compile Include="ResultFormatters\MatlabResultFormatter.cs" /> 109 111 <Compile Include="ResultFormatters\PythonResultFormatter.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Interfaces/IResultCollectionProcessor.cs
r18049 r18050 9 9 10 10 namespace HeuristicLab.JsonInterface { 11 public interface IResultCollectionPostProcessor : IItem { 12 13 void Apply(IObservableDictionary<string, IItem> /*ResultCollection*/ results, IDictionary<string, string> output); //evtl. doch JToken als Dict? 11 public interface IResultCollectionProcessor : IParameterizedNamedItem { 12 void Apply(IObservableDictionary<string, IItem> results); 14 13 } 15 14 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs
r18046 r18050 19 19 /// <param name="optimizer">the optimizer object to serialize</param> 20 20 /// <param name="rootItem">Root JsonItem for serialization, considers only active JsonItems for serialization</param> 21 public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem, IEnumerable<IResultCollectionP ostProcessor> postProcessors) {21 public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem, IEnumerable<IResultCollectionProcessor> resultCollectionProcessors) { 22 22 // clear all runs 23 if (optimizer.ExecutionState == ExecutionState.Paused) 24 optimizer.Stop(); 23 25 optimizer.Runs.Clear(); 24 26 … … 32 34 JArray parameterItems = new JArray(); 33 35 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 42 IList<IJsonItem> jsonItems = new List<IJsonItem>(); 43 36 JArray resultCollectionProcessorItems = new JArray(); 44 37 string templateName = Path.GetFileName(templatePath); 45 38 string templateDirectory = Path.GetDirectoryName(templatePath); 46 47 39 #endregion 48 40 49 if(optimizer.ExecutionState == ExecutionState.Paused) 50 optimizer.Stop(); 51 52 // recursively filter items with values/ranges/actualNames 53 PopulateJsonItems(rootItem, jsonItems); 41 // filter items with values/ranges/actualNames 42 var jsonItems = rootItem.Where(x => x.Active && !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)); 54 43 55 44 #region Serialize HL File … … 71 60 #endregion 72 61 62 #region ResultCollectionProcessor Serialization 63 foreach (var proc in resultCollectionProcessors) { 64 JArray rcpParameterItems = new JArray(); 65 var guid = StorableTypeAttribute.GetStorableTypeAttribute(proc.GetType()).Guid.ToString(); 66 var item = JsonItemConverter.Extract(proc); 67 68 var rcpItems = item 69 .Where(x => !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)) 70 .Select(x => x.GenerateJObject()); 71 72 foreach (var i in rcpItems) 73 rcpParameterItems.Add(i); 74 75 JObject processorObj = new JObject(); 76 processorObj.Add(nameof(IJsonItem.Name), item.Name); 77 processorObj.Add("GUID", guid); 78 processorObj.Add(Constants.Parameters, rcpParameterItems); 79 resultCollectionProcessorItems.Add(processorObj); 80 } 81 #endregion 82 73 83 #region Set Template Data 74 84 template[Constants.Metadata][Constants.TemplateName] = templateName; … … 76 86 template[Constants.Parameters] = parameterItems; 77 87 template[Constants.Results] = resultItems; 78 template[ "PostProcessors"] = postProcessorItems;88 template[Constants.ResultCollectionProcessorItems] = resultCollectionProcessorItems; 79 89 #endregion 80 90 … … 83 93 #endregion 84 94 } 85 86 #region Helper87 private static void PopulateJsonItems(IJsonItem item, IList<IJsonItem> jsonItems) {88 foreach(var x in item) { // TODO: dieses konstrukt notwendig?89 if (x.Active && !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)) {90 jsonItems.Add(x);91 }92 }93 }94 #endregion95 95 } 96 96 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r18046 r18050 14 14 Optimizer = optimizer; 15 15 ConfiguredResultItems = configuredResultItems; 16 PostProcessors = Enumerable.Empty<IResultCollectionP ostProcessor>();16 PostProcessors = Enumerable.Empty<IResultCollectionProcessor>(); 17 17 } 18 18 19 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionP ostProcessor> postProcessors) {19 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IResultCollectionProcessor> postProcessors) { 20 20 Optimizer = optimizer; 21 21 ConfiguredResultItems = configuredResultItems; … … 25 25 public IOptimizer Optimizer { get; } 26 26 public IEnumerable<IResultJsonItem> ConfiguredResultItems { get; } 27 public IEnumerable<IResultCollectionP ostProcessor> PostProcessors { get; }27 public IEnumerable<IResultCollectionProcessor> PostProcessors { get; } 28 28 } 29 29 … … 65 65 #endregion 66 66 67 #region Deserialize HL File 67 68 // extract metadata information 68 69 string relativePath = Template[Constants.Metadata][Constants.HLFileLocation].ToString().Trim(); // get relative path … … 72 73 73 74 string hLFileLocation = Path.Combine(Path.GetDirectoryName(templateFileFullPath), relativePath); 74 #region Deserialize HL File75 75 ProtoBufSerializer serializer = new ProtoBufSerializer(); 76 76 IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation); … … 94 94 JsonItemConverter.Inject(optimizer, rootItem); 95 95 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); 96 return new InstantiatorResult(optimizer, CollectResults(), CollectResultCollectionProcessors()); 97 } 98 99 /// <summary> 100 /// Instantiates all defined (in template) ResultCollectionProcessors and injects the configured parameters. 101 /// </summary> 102 private IEnumerable<IResultCollectionProcessor> CollectResultCollectionProcessors() { 103 IList<IResultCollectionProcessor> postProcessorList = new List<IResultCollectionProcessor>(); 104 foreach (JObject obj in Template[Constants.ResultCollectionProcessorItems]) { 105 var guid = obj["GUID"].ToString(); 106 var parameters = obj[Constants.Parameters]; 107 var type = Mapper.StaticCache.GetType(new Guid(guid)); 108 var rcp = (IResultCollectionProcessor)Activator.CreateInstance(type); 109 var rcpItem = JsonItemConverter.Extract(rcp); 110 111 foreach (JObject param in parameters) { 112 var path = param[nameof(IJsonItem.Path)].ToString(); 113 foreach (var item in rcpItem) 114 if (item.Path == path) 115 item.SetJObject(param); 103 116 } 117 118 JsonItemConverter.Inject(rcp, rcpItem); 119 postProcessorList.Add(rcp); 104 120 } 105 106 return new InstantiatorResult(optimizer, CollectResults(), postProcessorList); 121 return postProcessorList; 107 122 } 108 123 … … 110 125 IList<IResultJsonItem> res = new List<IResultJsonItem>(); 111 126 foreach(JObject obj in Template[Constants.Results]) { 112 //string name = obj.Property("Name").Value.ToString();113 127 var resultItem = new ResultJsonItem(); 114 128 resultItem.SetJObject(obj); 115 129 res.Add(resultItem); 116 //res.Add(new ResultJsonItem() { Name = name });117 130 } 118 131 return res; … … 124 137 125 138 foreach (JObject obj in Template[Constants.Parameters]) { 126 string path = obj.Property( "Path").Value.ToString();139 string path = obj.Property(nameof(IJsonItem.Path)).Value.ToString(); 127 140 foreach(var tmp in root) { 128 141 if(tmp.Path == path) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/ResultCollectionProcessors/SymRegPythonProcessor.cs
r18047 r18050 11 11 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 12 12 using HEAL.Attic; 13 using HeuristicLab.Data; 13 14 14 15 namespace HeuristicLab.JsonInterface { 15 16 [StorableType("844F2887-B7A0-4BD4-89B8-F9155C65D214")] 16 public class SymRegPythonP ostProcessor : Item, IResultCollectionPostProcessor {17 public class SymRegPythonProcessor : ParameterizedNamedItem, IResultCollectionProcessor { 17 18 19 #region Constructors & Cloning 18 20 [StorableConstructor] 19 protected SymRegPythonPostProcessor(StorableConstructorFlag _) : base(_) { 21 protected SymRegPythonProcessor(StorableConstructorFlag _) : base(_) { } 22 public SymRegPythonProcessor() { } 23 public SymRegPythonProcessor(SymRegPythonProcessor original, Cloner cloner) : base(original, cloner) { } 24 25 public override IDeepCloneable Clone(Cloner cloner) { 26 return new SymRegPythonProcessor(this, cloner); 20 27 } 28 #endregion 21 29 22 public SymRegPythonPostProcessor() { } 23 public SymRegPythonPostProcessor(SymRegPythonPostProcessor old, Cloner cloner) { } 24 25 public void Apply(IObservableDictionary<string, IItem> results, IDictionary<string, string> output) { 30 public void Apply(IObservableDictionary<string, IItem> results) { 26 31 var formatter = new SymbolicDataAnalysisExpressionPythonFormatter(); 27 foreach (var kvp in results) { 32 var resultCopy = new ObservableDictionary<string, IItem>(results); 33 foreach (var kvp in resultCopy) { 28 34 if (kvp.Value is ISymbolicRegressionSolution sol) { 29 output.Add(kvp.Key, formatter.Format(sol.Model.SymbolicExpressionTree));35 results.Add($"{kvp.Key} - Python" , new StringValue(formatter.Format(sol.Model.SymbolicExpressionTree))); 30 36 } 31 37 } 32 38 } 33 34 public override IDeepCloneable Clone(Cloner cloner) {35 return new SymRegPythonPostProcessor(this, cloner);36 }37 39 } 38 40 }
Note: See TracChangeset
for help on using the changeset viewer.