Changeset 18059 for branches/3026_IntegrationIntoSymSpace
- Timestamp:
- 09/23/21 13:03:53 (3 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 9 deleted
- 11 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs
r18055 r18059 14 14 InstantiatorResult instantiatorResult = JsonTemplateInstantiator.Instantiate(template, config); 15 15 IOptimizer optimizer = instantiatorResult.Optimizer; 16 IEnumerable<IResultJsonItem> configuredResultItem = instantiatorResult.ConfiguredResultItems;17 16 18 17 optimizer.Runs.Clear(); … … 22 21 Task task = optimizer.StartAsync(); 23 22 while (!task.IsCompleted) { 24 WriteResultsToFile(outputFile, optimizer, configuredResultItem,instantiatorResult.RunCollectionModifiers);23 WriteResultsToFile(outputFile, optimizer, instantiatorResult.RunCollectionModifiers); 25 24 Thread.Sleep(100); 26 25 } 27 26 28 WriteResultsToFile(outputFile, optimizer, configuredResultItem,instantiatorResult.RunCollectionModifiers);27 WriteResultsToFile(outputFile, optimizer, instantiatorResult.RunCollectionModifiers); 29 28 } 30 29 31 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IR esultJsonItem> configuredResultItem, IEnumerable<IRunCollectionModifier> runCollectionModifiers) {30 private static void WriteResultsToFile(string file, IOptimizer optimizer, IEnumerable<IRunCollectionModifier> runCollectionModifiers) { 32 31 if (optimizer.Runs.Count > 0) 33 File.WriteAllText(file, FetchResults(optimizer, configuredResultItem,runCollectionModifiers));32 File.WriteAllText(file, FetchResults(optimizer, runCollectionModifiers)); 34 33 } 34 35 private static string FetchResults(IOptimizer optimizer, IEnumerable<IRunCollectionModifier> runCollectionModifiers) { 36 JArray arr = new JArray(); 35 37 36 37 private static IEnumerable<IResultFormatter> ResultFormatter { get; } = 38 PluginInfrastructure.ApplicationManager.Manager.GetInstances<IResultFormatter>(); 39 40 private static IResultFormatter GetResultFormatter(string fullName) => 41 ResultFormatter?.Where(x => x.GetType().FullName == fullName).Last(); 42 43 private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IRunCollectionModifier> runCollectionModifiers) { 44 JArray arr = new JArray(); 45 IEnumerable<string> configuredResults = configuredResultItems.Select(x => x.Name); 46 47 foreach (var processor in runCollectionModifiers) 48 processor.Modify(new List<IRun>(optimizer.Runs.ToArray())); 38 foreach (var modifier in runCollectionModifiers) 39 modifier.Modify(new List<IRun>(optimizer.Runs.ToArray())); 49 40 50 41 foreach (var run in optimizer.Runs) { … … 54 45 foreach (var result in run.Results) 55 46 obj.Add(result.Key, result.Value.ToString()); 56 57 // zip and filter the results with the ResultJsonItems58 var filteredResults = new List<Tuple<IResultJsonItem, IItem>>();59 foreach (var resultItem in configuredResultItems) {60 foreach (var result in run.Results) {61 if (resultItem.Name == result.Key) {62 filteredResults.Add(Tuple.Create(resultItem, result.Value));63 }64 }65 }66 67 // add results to the JObject68 foreach (var result in filteredResults) {69 var formatter = GetResultFormatter(result.Item1.ResultFormatterType);70 if (!obj.ContainsKey(result.Item1.Name)) // to prevent duplicates71 obj.Add(result.Item1.Name, formatter.Format(result.Item2));72 }73 47 } 74 /*75 foreach (var run in optimizer.Runs) {76 JObject obj = new JObject();77 arr.Add(obj);78 obj.Add("Run", JToken.FromObject(run.ToString()));79 80 // zip and filter the results with the ResultJsonItems81 var filteredResults = new List<Tuple<IResultJsonItem, IItem>>();82 foreach(var resultItem in configuredResultItems) {83 foreach(var result in run.Results) {84 if(resultItem.Name == result.Key) {85 filteredResults.Add(Tuple.Create(resultItem, result.Value));86 }87 }88 }89 90 // add results to the JObject91 foreach(var result in filteredResults) {92 var formatter = GetResultFormatter(result.Item1.ResultFormatterType);93 if(!obj.ContainsKey(result.Item1.Name)) // to prevent duplicates94 obj.Add(result.Item1.Name, formatter.Format(result.Item2));95 }96 }*/97 48 return SingleLineArrayJsonWriter.Serialize(arr); 98 49 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj
r18047 r18059 134 134 <Compile Include="ViewModels\RangedValueBaseVM.cs" /> 135 135 <Compile Include="ViewModels\RangeVM.cs" /> 136 <Compile Include="ViewModels\ResultItemVM.cs" />137 136 <Compile Include="ViewModels\SingleValueVM.cs" /> 138 137 <Compile Include="ViewModels\StringValueVM.cs" /> … … 155 154 <Compile Include="Plugin.cs" /> 156 155 <Compile Include="Properties\AssemblyInfo.cs" /> 157 <Compile Include="Views\ResultCollectionPostProcessorControl.cs"> 158 <SubType>UserControl</SubType> 159 </Compile> 160 <Compile Include="Views\ResultCollectionPostProcessorControl.Designer.cs"> 161 <DependentUpon>ResultCollectionPostProcessorControl.cs</DependentUpon> 162 </Compile> 163 <Compile Include="Views\ResultJsonItemControl.cs"> 164 <SubType>UserControl</SubType> 165 </Compile> 166 <Compile Include="Views\ResultJsonItemControl.Designer.cs"> 167 <DependentUpon>ResultJsonItemControl.cs</DependentUpon> 156 <Compile Include="Views\RunCollectionModifierControl.cs"> 157 <SubType>UserControl</SubType> 158 </Compile> 159 <Compile Include="Views\RunCollectionModifierControl.Designer.cs"> 160 <DependentUpon>RunCollectionModifierControl.cs</DependentUpon> 168 161 </Compile> 169 162 <Compile Include="Views\ValueLookupJsonItemControl.cs"> … … 241 234 <EmbeddedResource Include="Views\ExportJsonDialog.resx"> 242 235 <DependentUpon>ExportJsonDialog.cs</DependentUpon> 243 </EmbeddedResource>244 <EmbeddedResource Include="Views\ResultJsonItemControl.resx">245 <DependentUpon>ResultJsonItemControl.cs</DependentUpon>246 236 </EmbeddedResource> 247 237 <EmbeddedResource Include="Views\ValueLookupJsonItemControl.resx"> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs
r18055 r18059 34 34 this.groupBoxDetails = new System.Windows.Forms.GroupBox(); 35 35 this.panelParameterDetails = new System.Windows.Forms.Panel(); 36 this.splitContainer1 = new System.Windows.Forms.SplitContainer();37 this.treeViewResults = new System.Windows.Forms.TreeView();38 this.groupBox = new System.Windows.Forms.GroupBox();39 this.panelResultDetails = new System.Windows.Forms.Panel();40 36 this.splitContainer2 = new System.Windows.Forms.SplitContainer(); 41 37 this.tabControl1 = new System.Windows.Forms.TabControl(); 42 38 this.tabPage1 = new System.Windows.Forms.TabPage(); 43 39 this.tabPage2 = new System.Windows.Forms.TabPage(); 44 this.tabPage3 = new System.Windows.Forms.TabPage(); 45 this.postProcessorListControl = new HeuristicLab.JsonInterface.OptimizerIntegration.ResultCollectionPostProcessorControl(); 40 this.postProcessorListControl = new HeuristicLab.JsonInterface.OptimizerIntegration.RunCollectionModifierControl(); 46 41 this.label1 = new System.Windows.Forms.Label(); 47 42 this.textBoxTemplateName = new System.Windows.Forms.TextBox(); … … 49 44 this.jsonItemBindingSource = new System.Windows.Forms.BindingSource(this.components); 50 45 this.groupBoxDetails.SuspendLayout(); 51 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();52 this.splitContainer1.Panel1.SuspendLayout();53 this.splitContainer1.Panel2.SuspendLayout();54 this.splitContainer1.SuspendLayout();55 this.groupBox.SuspendLayout();56 46 ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); 57 47 this.splitContainer2.Panel1.SuspendLayout(); … … 61 51 this.tabPage1.SuspendLayout(); 62 52 this.tabPage2.SuspendLayout(); 63 this.tabPage3.SuspendLayout();64 53 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 65 54 ((System.ComponentModel.ISupportInitialize)(this.jsonItemBindingSource)).BeginInit(); … … 113 102 this.panelParameterDetails.TabIndex = 0; 114 103 // 115 // splitContainer1116 //117 this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;118 this.splitContainer1.Location = new System.Drawing.Point(3, 3);119 this.splitContainer1.Name = "splitContainer1";120 //121 // splitContainer1.Panel1122 //123 this.splitContainer1.Panel1.Controls.Add(this.treeViewResults);124 this.splitContainer1.Panel1.Padding = new System.Windows.Forms.Padding(0, 6, 0, 1);125 //126 // splitContainer1.Panel2127 //128 this.splitContainer1.Panel2.Controls.Add(this.groupBox);129 this.splitContainer1.Size = new System.Drawing.Size(796, 499);130 this.splitContainer1.SplitterDistance = 380;131 this.splitContainer1.TabIndex = 7;132 //133 // treeViewResults134 //135 this.treeViewResults.CheckBoxes = true;136 this.treeViewResults.Dock = System.Windows.Forms.DockStyle.Fill;137 this.treeViewResults.Location = new System.Drawing.Point(0, 6);138 this.treeViewResults.Name = "treeViewResults";139 this.treeViewResults.Size = new System.Drawing.Size(380, 492);140 this.treeViewResults.TabIndex = 6;141 this.treeViewResults.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewResults_AfterCheck);142 this.treeViewResults.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewResults_AfterSelect);143 //144 // groupBox145 //146 this.groupBox.Controls.Add(this.panelResultDetails);147 this.groupBox.Dock = System.Windows.Forms.DockStyle.Fill;148 this.groupBox.Location = new System.Drawing.Point(0, 0);149 this.groupBox.Name = "groupBox";150 this.groupBox.Size = new System.Drawing.Size(412, 499);151 this.groupBox.TabIndex = 5;152 this.groupBox.TabStop = false;153 this.groupBox.Text = "Details";154 //155 // panelResultDetails156 //157 this.panelResultDetails.AutoScroll = true;158 this.panelResultDetails.Dock = System.Windows.Forms.DockStyle.Fill;159 this.panelResultDetails.Location = new System.Drawing.Point(3, 16);160 this.panelResultDetails.Name = "panelResultDetails";161 this.panelResultDetails.Size = new System.Drawing.Size(406, 480);162 this.panelResultDetails.TabIndex = 0;163 //164 104 // splitContainer2 165 105 // … … 187 127 this.tabControl1.Controls.Add(this.tabPage1); 188 128 this.tabControl1.Controls.Add(this.tabPage2); 189 this.tabControl1.Controls.Add(this.tabPage3);190 129 this.tabControl1.Location = new System.Drawing.Point(12, 38); 191 130 this.tabControl1.Name = "tabControl1"; … … 207 146 // tabPage2 208 147 // 209 this.tabPage2.Controls.Add(this. splitContainer1);148 this.tabPage2.Controls.Add(this.postProcessorListControl); 210 149 this.tabPage2.Location = new System.Drawing.Point(4, 22); 211 150 this.tabPage2.Name = "tabPage2"; 212 this.tabPage2.Padding = new System.Windows.Forms.Padding(3);213 151 this.tabPage2.Size = new System.Drawing.Size(802, 505); 214 this.tabPage2.TabIndex = 1;215 this.tabPage2.Text = "Result s";152 this.tabPage2.TabIndex = 2; 153 this.tabPage2.Text = "Result Collection Modifiers"; 216 154 this.tabPage2.UseVisualStyleBackColor = true; 217 //218 // tabPage3219 //220 this.tabPage3.Controls.Add(this.postProcessorListControl);221 this.tabPage3.Location = new System.Drawing.Point(4, 22);222 this.tabPage3.Name = "tabPage3";223 this.tabPage3.Size = new System.Drawing.Size(802, 505);224 this.tabPage3.TabIndex = 2;225 this.tabPage3.Text = "Result Collection Modifiers";226 this.tabPage3.UseVisualStyleBackColor = true;227 155 // 228 156 // postProcessorListControl … … 281 209 this.Text = "Export Json"; 282 210 this.groupBoxDetails.ResumeLayout(false); 283 this.splitContainer1.Panel1.ResumeLayout(false);284 this.splitContainer1.Panel2.ResumeLayout(false);285 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();286 this.splitContainer1.ResumeLayout(false);287 this.groupBox.ResumeLayout(false);288 211 this.splitContainer2.Panel1.ResumeLayout(false); 289 212 this.splitContainer2.Panel2.ResumeLayout(false); … … 293 216 this.tabPage1.ResumeLayout(false); 294 217 this.tabPage2.ResumeLayout(false); 295 this.tabPage3.ResumeLayout(false);296 218 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 297 219 ((System.ComponentModel.ISupportInitialize)(this.jsonItemBindingSource)).EndInit(); … … 312 234 private System.Windows.Forms.TabControl tabControl1; 313 235 private System.Windows.Forms.TabPage tabPage1; 314 private System.Windows.Forms.TabPage tabPage2;315 private System.Windows.Forms.TreeView treeViewResults;316 236 private System.Windows.Forms.Label label1; 317 237 private System.Windows.Forms.TextBox textBoxTemplateName; 318 238 private System.Windows.Forms.ErrorProvider errorProvider; 319 private System.Windows.Forms.SplitContainer splitContainer1; 320 private System.Windows.Forms.GroupBox groupBox; 321 private System.Windows.Forms.Panel panelResultDetails; 322 private System.Windows.Forms.TabPage tabPage3; 323 private ResultCollectionPostProcessorControl postProcessorListControl; 239 private System.Windows.Forms.TabPage tabPage2; 240 private RunCollectionModifierControl postProcessorListControl; 324 241 } 325 242 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r18055 r18059 30 30 set { 31 31 content = value; 32 //CheckedItemListView33 32 #region Clear 34 33 VMs = new List<IJsonItemVM>(); 35 34 treeView.Nodes.Clear(); 36 treeViewResults.Nodes.Clear();37 35 #endregion 38 36 Optimizer = content as IOptimizer; … … 46 44 treeView.ExpandAll(); 47 45 panelParameterDetails.Controls.Clear(); 48 panelResultDetails.Controls.Clear();49 46 } 50 47 } … … 61 58 public ExportJsonDialog() { 62 59 InitializeComponent(); 63 this.RunCollectionModifiers = this.postProcessorListControl.Content;64 this.Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon;60 RunCollectionModifiers = postProcessorListControl.Content; 61 Icon = Common.Resources.HeuristicLab.Icon; 65 62 InitCache(); 66 63 } … … 74 71 if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) { 75 72 try { 76 //foreach(var x in PostProcessors.CheckedItems)77 78 73 JsonTemplateGenerator.GenerateTemplate( 79 74 Path.Combine(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text), … … 92 87 if (IsDrawableItem(c)) { 93 88 TreeNode childNode = new TreeNode(c.Name); 94 if (c is IResultJsonItem) { 95 treeViewResults.Nodes.Add(childNode); 96 IJsonItemVM vm = RegisterItem(childNode, c, treeViewResults); 97 if (vm != null) vm.Selected = true; 98 } else { 99 node.Nodes.Add(childNode); 100 BuildTreeNode(childNode, c); 101 } 89 node.Nodes.Add(childNode); 90 BuildTreeNode(childNode, c); 102 91 } 103 92 } … … 128 117 private bool IsDrawableItem(IJsonItem item) { 129 118 bool b = false; 130 if (item.Children != null) {131 foreach (var c in item.Children) {119 if (item.Children != null) 120 foreach (var c in item.Children) 132 121 b = b || IsDrawableItem(c); 133 }134 }135 122 136 123 return b || !(item is EmptyJsonItem) || !(item is UnsupportedJsonItem); … … 140 127 if(Node2Control.TryGetValue(treeView.SelectedNode, out UserControl control)) { 141 128 SetControlOnPanel(control, panelParameterDetails); 142 }143 }144 145 private void treeViewResults_AfterSelect(object sender, TreeViewEventArgs e) {146 if (Node2Control.TryGetValue(treeViewResults.SelectedNode, out UserControl control)) {147 SetControlOnPanel(control, panelResultDetails);148 129 } 149 130 } … … 171 152 172 153 private void TreeView_AfterCheck(object sender, TreeViewEventArgs e) { 173 if (e.Action != TreeViewAction.Unknown) {174 if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) {154 if (e.Action != TreeViewAction.Unknown) 155 if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) 175 156 vm.Selected = e.Node.Checked; 176 }177 }178 157 } 179 158 180 159 private void treeViewResults_AfterCheck(object sender, TreeViewEventArgs e) { 181 if (e.Action != TreeViewAction.Unknown) {182 if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) {160 if (e.Action != TreeViewAction.Unknown) 161 if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) 183 162 vm.Selected = e.Node.Checked; 184 }185 }186 163 } 187 164 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/RunCollectionModifierControl.Designer.cs
r18058 r18059 1 1 2 2 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 3 partial class R esultCollectionPostProcessorControl {3 partial class RunCollectionModifierControl { 4 4 /// <summary> 5 5 /// Erforderliche Designervariable. -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/RunCollectionModifierControl.cs
r18058 r18059 12 12 13 13 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 14 public partial class R esultCollectionPostProcessorControl : Core.Views.CheckedItemListView<IRunCollectionModifier> {15 public R esultCollectionPostProcessorControl() {14 public partial class RunCollectionModifierControl : Core.Views.CheckedItemListView<IRunCollectionModifier> { 15 public RunCollectionModifierControl() { 16 16 InitializeComponent(); 17 17 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Constants.cs
r18056 r18059 10 10 internal const string OptimizerDescription = "OptimizerDescription"; 11 11 internal const string Parameters = "Parameters"; 12 internal const string Results = "Results";13 12 internal const string RunCollectionModifiers = "RunCollectionModifiers"; 14 13 … … 20 19 }, 21 20 '" + Parameters + @"': [], 22 '" + Results + @"': [],23 21 '" + RunCollectionModifiers + @"': [] 24 22 }"; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs
r18043 r18059 24 24 IJsonItem item = base.Extract(value, root); 25 25 IAlgorithm algorithm = value as IAlgorithm; 26 foreach (var res in algorithm.Results) {27 var resultItem = root.Extract(res, root);28 // fetch all result parameter items29 var resultParameterItems =30 item.Where(x => x31 .GetType()32 .GetInterfaces()33 .Any(y => y == typeof(IResultJsonItem)));34 // check for duplicates (to prevent double result items,35 // which can occur with result parameters)36 if(!resultParameterItems.Any(x => x.Name == resultItem.Name))37 item.AddChildren(resultItem);38 }39 26 item.AddChildren(root.Extract(algorithm.Problem, root)); 40 27 return item; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs
r18043 r18059 6 6 { 7 7 public abstract int Priority { get; } 8 9 8 public abstract bool CanConvertType(Type t); 10 11 9 public abstract void Inject(IItem item, IJsonItem data, IJsonItemConverter root); 12 10 public abstract IJsonItem Extract(IItem value, IJsonItemConverter root); 13 14 11 15 12 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ResultParameterConverter.cs
r17843 r18059 12 12 13 13 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 14 IResultParameter res = value as IResultParameter; 15 var formatter = ResultFormatter.ForType(res.DataType).Last(); 16 return new ResultJsonItem() { 17 Name = res.ActualName, 18 Description = res.Description, 19 ResultFormatterType = formatter.GetType().FullName, 20 ValueType = res.DataType 21 }; 14 return new UnsupportedJsonItem(); 22 15 } 23 16 24 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 25 IResultParameter res = item as IResultParameter; 26 res.ActualName = data.Name; 27 } 17 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {} 28 18 } 29 19 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r18055 r18059 68 68 <Compile Include="Converters\ItemCollectionConverter.cs" /> 69 69 <Compile Include="Converters\RegressionProblemDataConverter.cs" /> 70 <Compile Include="Converters\ResultConverter.cs" />71 70 <Compile Include="Converters\ResultParameterConverter.cs" /> 72 71 <Compile Include="Converters\ValueLookupParameterConverter.cs" /> … … 80 79 <Compile Include="Interfaces\IMatrixJsonItem.cs" /> 81 80 <Compile Include="Interfaces\IRangedJsonItem.cs" /> 82 <Compile Include="Interfaces\IResultFormatter.cs" />83 <Compile Include="Interfaces\IResultJsonItem.cs" />84 81 <Compile Include="Interfaces\IValueJsonItem.cs" /> 85 82 <Compile Include="Interfaces\IValueLookupJsonItem.cs" /> … … 102 99 <Compile Include="JsonItems\MatrixJsonItem.cs" /> 103 100 <Compile Include="JsonItems\RangedJsonItem.cs" /> 104 <Compile Include="JsonItems\ResultJsonItem.cs" />105 101 <Compile Include="JsonItems\StringJsonItem.cs" /> 106 102 <Compile Include="JsonItems\UnsupportedJsonItem.cs" /> … … 112 108 <Compile Include="ResultCollectionProcessors\RunCollectionSRSolutionLatexFormatter.cs" /> 113 109 <Compile Include="ResultCollectionProcessors\RunCollectionSRSolutionPythonFormatter.cs" /> 114 <Compile Include="ResultFormatters\MatlabResultFormatter.cs" />115 <Compile Include="ResultFormatters\PythonResultFormatter.cs" />116 <Compile Include="ResultFormatters\ResultFormatter.cs" />117 <Compile Include="ResultFormatters\StringResultFormatter.cs" />118 <Compile Include="ResultFormatters\SymbolicRegressionSolutionFormatterBase.cs" />119 110 <Compile Include="SingleLineArrayJsonWriter.cs" /> 120 111 <Compile Include="JsonTemplateGenerator.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs
r18056 r18059 53 53 #region Filter Items 54 54 foreach (var item in jsonItems) { 55 if (item is IResultJsonItem) 56 resultItems.Add(item.GenerateJObject()); 57 else 58 parameterItems.Add(item.GenerateJObject()); 55 parameterItems.Add(item.GenerateJObject()); 59 56 } 60 57 #endregion 61 58 62 59 #region RunCollectionModifiers Serialization 63 foreach (var procin runCollectionModifiers) {64 JArray rc pParameterItems = new JArray();65 var guid = StorableTypeAttribute.GetStorableTypeAttribute( proc.GetType()).Guid.ToString();66 var item = JsonItemConverter.Extract( proc);60 foreach (var rcModifier in runCollectionModifiers) { 61 JArray rcModifierParameterItems = new JArray(); 62 var guid = StorableTypeAttribute.GetStorableTypeAttribute(rcModifier.GetType()).Guid.ToString(); 63 var item = JsonItemConverter.Extract(rcModifier); 67 64 68 var rc pItems = item65 var rcModifierItems = item 69 66 .Where(x => !(x is EmptyJsonItem) && !(x is UnsupportedJsonItem)) 70 67 .Select(x => x.GenerateJObject()); 71 68 72 foreach (var i in rc pItems)73 rc pParameterItems.Add(i);69 foreach (var i in rcModifierItems) 70 rcModifierParameterItems.Add(i); 74 71 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 runCollectionModifierItems.Add( processorObj);72 JObject rcModifierObj = new JObject(); 73 rcModifierObj.Add(nameof(IJsonItem.Name), item.Name); 74 rcModifierObj.Add("GUID", guid); 75 rcModifierObj.Add(Constants.Parameters, rcModifierParameterItems); 76 runCollectionModifierItems.Add(rcModifierObj); 80 77 } 81 78 #endregion … … 86 83 template[Constants.Metadata][Constants.OptimizerDescription] = optimizer.Description; 87 84 template[Constants.Parameters] = parameterItems; 88 template[Constants.Results] = resultItems;89 85 template[Constants.RunCollectionModifiers] = runCollectionModifierItems; 90 86 #endregion -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r18055 r18059 11 11 namespace HeuristicLab.JsonInterface { 12 12 public readonly struct InstantiatorResult { 13 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems) { 13 14 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IRunCollectionModifier> runCollectionModifiers) { 14 15 Optimizer = optimizer; 15 ConfiguredResultItems = configuredResultItems;16 RunCollectionModifiers = Enumerable.Empty<IRunCollectionModifier>();17 }18 19 public InstantiatorResult(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems, IEnumerable<IRunCollectionModifier> runCollectionModifiers) {20 Optimizer = optimizer;21 ConfiguredResultItems = configuredResultItems;22 16 RunCollectionModifiers = runCollectionModifiers; 23 17 } 24 18 25 19 public IOptimizer Optimizer { get; } 26 public IEnumerable<IResultJsonItem> ConfiguredResultItems { get; }27 20 public IEnumerable<IRunCollectionModifier> RunCollectionModifiers { get; } 28 21 } … … 75 68 ProtoBufSerializer serializer = new ProtoBufSerializer(); 76 69 IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation); 70 optimizer.Prepare(true); 77 71 #endregion 78 72 … … 94 88 JsonItemConverter.Inject(optimizer, rootItem); 95 89 96 return new InstantiatorResult(optimizer, CollectR esults(), CollectRunCollectionModifiers());90 return new InstantiatorResult(optimizer, CollectRunCollectionModifiers()); 97 91 } 98 92 … … 102 96 private IEnumerable<IRunCollectionModifier> CollectRunCollectionModifiers() { 103 97 IList<IRunCollectionModifier> runCollectionModifiers = new List<IRunCollectionModifier>(); 98 99 if (Template is JObject o && !o.ContainsKey(Constants.RunCollectionModifiers)) 100 return Enumerable.Empty<IRunCollectionModifier>(); 101 104 102 foreach (JObject obj in Template[Constants.RunCollectionModifiers]) { 105 103 var guid = obj["GUID"].ToString(); 106 104 var parameters = obj[Constants.Parameters]; 107 105 var type = Mapper.StaticCache.GetType(new Guid(guid)); 108 var rc p= (IRunCollectionModifier)Activator.CreateInstance(type);109 var rc pItem = JsonItemConverter.Extract(rcp);106 var rcModifier = (IRunCollectionModifier)Activator.CreateInstance(type); 107 var rcModifierItem = JsonItemConverter.Extract(rcModifier); 110 108 111 109 foreach (JObject param in parameters) { 112 110 var path = param[nameof(IJsonItem.Path)].ToString(); 113 foreach (var item in rc pItem)111 foreach (var item in rcModifierItem) 114 112 if (item.Path == path) 115 113 item.SetJObject(param); 116 114 } 117 115 118 JsonItemConverter.Inject(rc p, rcpItem);119 runCollectionModifiers.Add(rc p);116 JsonItemConverter.Inject(rcModifier, rcModifierItem); 117 runCollectionModifiers.Add(rcModifier); 120 118 } 121 119 return runCollectionModifiers; 122 }123 124 private IEnumerable<IResultJsonItem> CollectResults() {125 IList<IResultJsonItem> res = new List<IResultJsonItem>();126 foreach(JObject obj in Template[Constants.Results]) {127 var resultItem = new ResultJsonItem();128 resultItem.SetJObject(obj);129 res.Add(resultItem);130 }131 return res;132 120 } 133 121
Note: See TracChangeset
for help on using the changeset viewer.