Changeset 2223 for trunk/sources/HeuristicLab.CEDMA.Core
- Timestamp:
- 08/03/09 14:23:54 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.CEDMA.Core/3.3
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs
r2047 r2223 28 28 using System.ServiceModel; 29 29 using System.ServiceModel.Description; 30 using HeuristicLab.CEDMA.DB.Interfaces; 30 using HeuristicLab.PluginInfrastructure; 31 using HeuristicLab.Modeling.Database.SQLServerCompact; 31 32 32 33 namespace HeuristicLab.CEDMA.Core { 33 34 public class Console : ItemBase, IEditable { 34 private string serverUri; 35 public string ServerUri { 36 get { return serverUri; } 35 private static readonly string sqlServerCompactFile = AppDomain.CurrentDomain.BaseDirectory + "HeuristicLab.Modeling.database.sdf"; 36 private static readonly string sqlServerCompactConnectionString = @"Data Source=" + sqlServerCompactFile; 37 38 private Results results; 39 public Results Results { 40 get { 41 if (results == null) ReloadResults(); 42 return results; 43 } 37 44 } 38 39 private DataSet dataSet;40 public DataSet DataSet {41 get { return dataSet; }42 }43 44 45 public Console() 45 46 : base() { 46 dataSet = new DataSet();47 47 } 48 48 … … 55 55 } 56 56 57 #region serialization 58 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 59 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 60 XmlAttribute uriAttribute = document.CreateAttribute("ServerURI"); 61 uriAttribute.Value = serverUri; 62 node.Attributes.Append(uriAttribute); 63 return node; 64 } 65 66 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 67 base.Populate(node, restoredObjects); 68 serverUri = node.Attributes["ServerURI"].Value; 69 } 70 #endregion 71 72 internal void Connect(string serverUri) { 73 IStore store = new StoreProxy(serverUri); 74 var variableBindings = store.Query("?Dataset <" + Ontology.InstanceOf + "> <" + Ontology.TypeDataSet + "> .", 0, 10).ToArray(); 75 if (variableBindings.Length > 0) { 76 dataSet = new DataSet(store, (Entity)variableBindings[0].Get("Dataset")); 77 } else { 78 dataSet.Store = store; 79 } 57 private void ReloadResults() { 58 results = new Results(new DatabaseService(sqlServerCompactConnectionString)); 80 59 } 81 60 } -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/ConsoleEditor.cs
r2000 r2223 29 29 using HeuristicLab.PluginInfrastructure; 30 30 using System.Drawing; 31 using HeuristicLab.CEDMA.DB.Interfaces;32 31 33 32 namespace HeuristicLab.CEDMA.Core { 34 33 class ConsoleEditor : EditorBase { 35 private System.Windows.Forms.TextBox uriTextBox; 36 private System.Windows.Forms.Label uriLabel; 37 private Button connectButton; 38 private Panel serverPanel; 34 private ComboBox viewComboBox; 35 private Button resultsButton; 39 36 private Console console; 40 37 … … 42 39 InitializeComponent(); 43 40 this.console = console; 41 PopulateViewComboBox(); 44 42 } 45 43 46 44 #region autogenerated code 47 45 private void InitializeComponent() { 48 this.uriTextBox = new System.Windows.Forms.TextBox(); 49 this.uriLabel = new System.Windows.Forms.Label(); 50 this.connectButton = new System.Windows.Forms.Button(); 51 this.serverPanel = new System.Windows.Forms.Panel(); 46 this.viewComboBox = new System.Windows.Forms.ComboBox(); 47 this.resultsButton = new System.Windows.Forms.Button(); 52 48 this.SuspendLayout(); 53 49 // 54 // uriTextBox50 // viewComboBox 55 51 // 56 this.uriTextBox.Location = new System.Drawing.Point(94, 3); 57 this.uriTextBox.Name = "uriTextBox"; 58 this.uriTextBox.Size = new System.Drawing.Size(205, 20); 59 this.uriTextBox.TabIndex = 0; 52 this.viewComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 53 this.viewComboBox.FormattingEnabled = true; 54 this.viewComboBox.Location = new System.Drawing.Point(3, 3); 55 this.viewComboBox.Name = "viewComboBox"; 56 this.viewComboBox.Size = new System.Drawing.Size(121, 21); 57 this.viewComboBox.TabIndex = 7; 60 58 // 61 // uriLabel59 // resultsButton 62 60 // 63 this.uriLabel.AutoSize = true; 64 this.uriLabel.Location = new System.Drawing.Point(6, 6); 65 this.uriLabel.Name = "uriLabel"; 66 this.uriLabel.Size = new System.Drawing.Size(82, 13); 67 this.uriLabel.TabIndex = 1; 68 this.uriLabel.Text = "CEDMA Server:"; 69 // 70 // connectButton 71 // 72 this.connectButton.Location = new System.Drawing.Point(305, 1); 73 this.connectButton.Name = "connectButton"; 74 this.connectButton.Size = new System.Drawing.Size(75, 23); 75 this.connectButton.TabIndex = 3; 76 this.connectButton.Text = "&Connect"; 77 this.connectButton.UseVisualStyleBackColor = true; 78 this.connectButton.Click += new System.EventHandler(this.connectButton_Click); 79 // 80 // serverPanel 81 // 82 this.serverPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 83 | System.Windows.Forms.AnchorStyles.Left) 84 | System.Windows.Forms.AnchorStyles.Right))); 85 this.serverPanel.Location = new System.Drawing.Point(3, 29); 86 this.serverPanel.Name = "serverPanel"; 87 this.serverPanel.Size = new System.Drawing.Size(439, 157); 88 this.serverPanel.TabIndex = 4; 61 this.resultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 62 this.resultsButton.Location = new System.Drawing.Point(130, 1); 63 this.resultsButton.Name = "resultsButton"; 64 this.resultsButton.Size = new System.Drawing.Size(86, 23); 65 this.resultsButton.TabIndex = 6; 66 this.resultsButton.Text = "Show results"; 67 this.resultsButton.UseVisualStyleBackColor = true; 68 this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click); 89 69 // 90 70 // ConsoleEditor 91 71 // 92 72 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 93 this.Controls.Add(this.serverPanel); 94 this.Controls.Add(this.connectButton); 95 this.Controls.Add(this.uriLabel); 96 this.Controls.Add(this.uriTextBox); 73 this.Controls.Add(this.viewComboBox); 74 this.Controls.Add(this.resultsButton); 97 75 this.Name = "ConsoleEditor"; 98 76 this.Size = new System.Drawing.Size(445, 189); 99 77 this.ResumeLayout(false); 100 this.PerformLayout();101 78 102 79 } … … 104 81 #endregion 105 82 106 private void connectButton_Click(object sender, EventArgs e) {107 try {108 console.Connect(uriTextBox.Text);109 connectButton.Enabled = false;110 serverPanel.Enabled = true;111 serverPanel.Controls.Clear();112 Control dataSetView = (Control)console.DataSet.CreateView(); 113 dataSetView.Dock = DockStyle.Fill; 114 serverPanel.Controls.Add(dataSetView);115 } catch(CommunicationException ex) {116 MessageBox.Show("Exception while trying to connect to " + uriTextBox.Text + "\n" + ex.Message);117 }83 private void PopulateViewComboBox() { 84 DiscoveryService service = new DiscoveryService(); 85 IResultsViewFactory[] factories = service.GetInstances<IResultsViewFactory>(); 86 viewComboBox.DataSource = factories; 87 viewComboBox.ValueMember = "Name"; 88 } 89 90 91 private void resultsButton_Click(object sender, EventArgs e) { 92 IResultsViewFactory factory = (IResultsViewFactory)viewComboBox.SelectedItem; 93 IControl control = factory.CreateView(console.Results); 94 PluginManager.ControlManager.ShowControl(control); 118 95 } 119 96 } -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/HeuristicLab.CEDMA.Core-3.3.csproj
r2000 r2223 88 88 </ItemGroup> 89 89 <ItemGroup> 90 <Compile Include="StoreProxy.cs" />91 90 <Compile Include="IResultsViewFactory.cs" /> 92 91 <Compile Include="ResultsEntry.cs" /> … … 101 100 <SubType>UserControl</SubType> 102 101 </Compile> 103 <Compile Include="Problem.cs" />104 <Compile Include="DataSet.cs" />105 <Compile Include="DataSetView.cs">106 <SubType>UserControl</SubType>107 </Compile>108 <Compile Include="DataSetView.Designer.cs">109 <DependentUpon>DataSetView.cs</DependentUpon>110 </Compile>111 102 <Compile Include="HeuristicLabCedmaCorePlugin.cs" /> 112 <Compile Include="ProblemView.cs">113 <SubType>UserControl</SubType>114 </Compile>115 <Compile Include="ProblemView.Designer.cs">116 <DependentUpon>ProblemView.cs</DependentUpon>117 </Compile>118 103 <Compile Include="Properties\AssemblyInfo.cs" /> 119 104 <Compile Include="Results.cs" /> … … 123 108 </ItemGroup> 124 109 <ItemGroup> 125 <ProjectReference Include="..\..\HeuristicLab.CEDMA.DB.Interfaces\3.3\HeuristicLab.CEDMA.DB.Interfaces-3.3.csproj">126 <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>127 <Name>HeuristicLab.CEDMA.DB.Interfaces-3.3</Name>128 </ProjectReference>129 110 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 130 111 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> … … 138 119 <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project> 139 120 <Name>HeuristicLab.Data-3.2</Name> 121 </ProjectReference> 122 <ProjectReference Include="..\..\HeuristicLab.Modeling.Database.SQLServerCompact\3.2\HeuristicLab.Modeling.Database.SQLServerCompact-3.2.csproj"> 123 <Project>{EC1AA756-D612-4FA6-AA52-25CF4F8E3836}</Project> 124 <Name>HeuristicLab.Modeling.Database.SQLServerCompact-3.2</Name> 125 </ProjectReference> 126 <ProjectReference Include="..\..\HeuristicLab.Modeling.Database\3.2\HeuristicLab.Modeling.Database-3.2.csproj"> 127 <Project>{E84E5717-79F8-498F-A5E0-A055C4EC086B}</Project> 128 <Name>HeuristicLab.Modeling.Database-3.2</Name> 140 129 </ProjectReference> 141 130 <ProjectReference Include="..\..\HeuristicLab.Operators\3.2\HeuristicLab.Operators-3.2.csproj"> … … 155 144 <DependentUpon>ConsoleEditor.cs</DependentUpon> 156 145 <SubType>Designer</SubType> 157 </EmbeddedResource>158 <EmbeddedResource Include="DataSetView.resx">159 <DependentUpon>DataSetView.cs</DependentUpon>160 </EmbeddedResource>161 <EmbeddedResource Include="ProblemView.resx">162 <DependentUpon>ProblemView.cs</DependentUpon>163 146 </EmbeddedResource> 164 147 </ItemGroup> -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/HeuristicLabCedmaCorePlugin.cs
r1529 r2223 31 31 [Dependency(Dependency = "HeuristicLab.Data-3.2")] 32 32 [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")] 33 [Dependency(Dependency = "HeuristicLab.CEDMA.DB.Interfaces-3.3")]34 33 [Dependency(Dependency = "HeuristicLab.Operators-3.2")] 34 [Dependency(Dependency = "HeuristicLab.Modeling.Database-3.2")] 35 [Dependency(Dependency = "HeuristicLab.Modeling.Database.SQLServerCompact-3.2")] 35 36 public class HeuristicLabCedmaCorePlugin : PluginBase { 36 37 } -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/IResultsViewFactory.cs
r1529 r2223 26 26 using HeuristicLab.Core; 27 27 using System.Xml; 28 using HeuristicLab.CEDMA.DB.Interfaces;29 28 using HeuristicLab.Operators; 30 29 using System.Windows.Forms; -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs
r2146 r2223 26 26 using HeuristicLab.Core; 27 27 using System.Collections; 28 using HeuristicLab.CEDMA.DB.Interfaces;29 28 using System.Xml; 30 29 using System.Runtime.Serialization; … … 34 33 using HeuristicLab.DataAnalysis; 35 34 using System.Drawing; 35 using HeuristicLab.Modeling.Database; 36 36 37 37 namespace HeuristicLab.CEDMA.Core { 38 38 public class Results : ItemBase { 39 private const int PAGE_SIZE = 1000;40 39 private string[] categoricalVariables = null; 41 40 public string[] CategoricalVariables { … … 58 57 } 59 58 60 private string[] multiDimensionalOrdinalVariables = new string[] { "VariableImpacts: EvaluationImpact", "VariableImpacts: QualityImpact" };59 private string[] multiDimensionalOrdinalVariables; 61 60 public string[] MultiDimensionalOrdinalVariables { 62 61 get { return multiDimensionalOrdinalVariables; } … … 68 67 } 69 68 70 private IStore store; 71 public IStore Store { 72 get { return store; } 73 set { 74 store = value; 75 } 76 } 69 private IModelingDatabase database; 77 70 78 71 private Dictionary<string, Dictionary<object, double>> categoricalValueIndices = new Dictionary<string, Dictionary<object, double>>(); 79 72 80 public Results(IStore store) { 81 this.store = store; 73 public Results(IModelingDatabase database) { 74 this.database = database; 75 multiDimensionalOrdinalVariables = database.GetAllResultsForInputVariables().Select(x => "VariableImpacts: " + x.Name).ToArray(); 82 76 } 83 77 … … 91 85 92 86 private IEnumerable<ResultsEntry> SelectRows() { 93 int page = 0; 94 int resultsReturned = 0; 87 database.Connect(); 95 88 entries = new List<ResultsEntry>(); 96 if (store == null) return entries; 97 do { 98 var allModels = store.Query( 99 "?Model <" + Ontology.InstanceOf + "> <" + Ontology.TypeModel + "> ." + 100 "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." + 101 "?Model <" + Ontology.TestMeanSquaredError + "> ?TestMSE .", 102 0, 3000) 103 .Select(modelBinding => new { 104 Model = ((Entity)modelBinding.Get("Model")).Uri, 105 TestMSE = (double)((Literal)modelBinding.Get("TestMSE")).Value, 106 TargetVariable = (string)((Literal)modelBinding.Get("TargetVariable")).Value 107 }) 108 .Distinct() 109 .GroupBy(m => m.TargetVariable) 110 .Select(grouping => grouping.OrderBy(m => m.TestMSE)); 111 foreach (var targetVariableBindings in allModels) { 112 resultsReturned = targetVariableBindings.Count(); 113 int nModels = Math.Max(10, resultsReturned * 10 / 100); 114 nModels = Math.Min(nModels, resultsReturned); 115 foreach (var modelBindings in targetVariableBindings.Take(nModels)) { 116 ResultsEntry entry = new ResultsEntry(); 117 entry.Uri = modelBindings.Model; 118 entries.Add(entry); 119 SetModelAttributes(entry, modelBindings.Model); 120 entry.Set("VariableImpacts", SelectVariableImpacts(modelBindings.Model)); 89 foreach (var model in database.GetAllModels()) { 90 ResultsEntry modelEntry = new ResultsEntry(); 91 foreach (var modelResult in database.GetModelResults(model)) { 92 modelEntry.Set(modelResult.Result.Name, modelResult.Value); 93 } 94 modelEntry.Set("PersistedData", database.GetModelData(model)); 95 modelEntry.Set("TargetVariable", model.TargetVariable.Name); 96 Dictionary<HeuristicLab.Modeling.Database.IVariable, ResultsEntry> inputVariableResultsEntries = 97 new Dictionary<HeuristicLab.Modeling.Database.IVariable, ResultsEntry>(); 98 99 foreach (IInputVariableResult inputVariableResult in database.GetInputVariableResults(model)) { 100 if (!inputVariableResultsEntries.ContainsKey(inputVariableResult.Variable)) { 101 inputVariableResultsEntries[inputVariableResult.Variable] = new ResultsEntry(); 102 inputVariableResultsEntries[inputVariableResult.Variable].Set("InputVariableName", inputVariableResult.Variable.Name); 121 103 } 104 inputVariableResultsEntries[inputVariableResult.Variable].Set(inputVariableResult.Result.Name, inputVariableResult.Value); 122 105 } 123 page++; 124 } while (resultsReturned == PAGE_SIZE); 106 modelEntry.Set("VariableImpacts", inputVariableResultsEntries.Values); 107 entries.Add(modelEntry); 108 } 109 database.Disconnect(); 125 110 FireChanged(); 126 111 cached = true; 127 112 return entries; 128 }129 130 private void SetModelAttributes(ResultsEntry entry, string modelUri) {131 var modelBindings = store.Query(132 "<" + modelUri + "> ?Attribute ?Value .",133 0, PAGE_SIZE);134 foreach (var binding in modelBindings) {135 if (binding.Get("Value") is Literal) {136 string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");137 if (entry.Get(name) == null) {138 object value = ((Literal)binding.Get("Value")).Value;139 entry.Set(name, value);140 }141 }142 }143 }144 145 private IEnumerable<ResultsEntry> SelectVariableImpacts(string modelUri) {146 var inputVariableNameBindings = store.Query(147 "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +148 "?InputVariable <" + Ontology.Name + "> ?InputName .",149 0, PAGE_SIZE);150 151 var qualityImpactBindings = store.Query(152 "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +153 "?InputVariable <" + Ontology.QualityImpact + "> ?QualityImpact .",154 0, PAGE_SIZE);155 156 var evaluationImpactBindings = store.Query(157 "<" + modelUri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." +158 "?InputVariable <" + Ontology.EvaluationImpact + "> ?EvaluationImpact .",159 0, PAGE_SIZE);160 Dictionary<object, ResultsEntry> inputVariableAttributes = new Dictionary<object, ResultsEntry>();161 162 foreach (var inputVariableNameBinding in inputVariableNameBindings) {163 object inputVariable = inputVariableNameBinding.Get("InputVariable");164 object name = ((Literal)inputVariableNameBinding.Get("InputName")).Value;165 if (!inputVariableAttributes.ContainsKey(inputVariable)) {166 inputVariableAttributes[inputVariable] = new ResultsEntry();167 inputVariableAttributes[inputVariable].Set("InputVariableName", name);168 }169 }170 171 foreach (var qualityImpactBinding in qualityImpactBindings) {172 double qualityImpact = (double)((Literal)qualityImpactBinding.Get("QualityImpact")).Value;173 object inputVariable = qualityImpactBinding.Get("InputVariable");174 if (!IsAlmost(qualityImpact, 1.0)) {175 if (inputVariableAttributes[inputVariable].Get("QualityImpact") == null)176 inputVariableAttributes[inputVariable].Set("QualityImpact", qualityImpact);177 } else inputVariableAttributes.Remove(inputVariable);178 }179 180 foreach (var evaluationImpactBinding in evaluationImpactBindings) {181 double evaluationImpact = (double)((Literal)evaluationImpactBinding.Get("EvaluationImpact")).Value;182 object inputVariable = evaluationImpactBinding.Get("InputVariable");183 if (!IsAlmost(evaluationImpact, 0.0)) {184 if (inputVariableAttributes.ContainsKey(inputVariable) && inputVariableAttributes[inputVariable].Get("EvaluationImpact") == null)185 inputVariableAttributes[inputVariable].Set("EvaluationImpact", evaluationImpact);186 } else inputVariableAttributes.Remove(inputVariable);187 }188 189 return inputVariableAttributes.Values;190 113 } 191 114 … … 199 122 200 123 private void LoadModelAttributes() { 201 this.ordinalVariables = 202 store 203 .Query( 204 "?ModelAttribute <" + Ontology.InstanceOf + "> <" + Ontology.TypeModelAttribute + "> ." + Environment.NewLine + 205 "?ModelAttribute <" + Ontology.InstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .", 0, 100) 206 .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, "")) 207 .Distinct() 208 .ToArray(); 209 this.categoricalVariables = 210 store 211 .Query( 212 "?ModelAttribute <" + Ontology.InstanceOf + "> <" + Ontology.TypeModelAttribute + "> ." + Environment.NewLine + 213 "?ModelAttribute <" + Ontology.InstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .", 0, 100) 214 .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, "")) 215 .Distinct() 216 .ToArray(); 124 ordinalVariables = database.GetAllResults().Select(r => r.Name).ToArray(); 125 categoricalVariables = new string[] { "TargetVariable" }; 217 126 } 218 127 -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/ResultsEntry.cs
r2139 r2223 26 26 using HeuristicLab.Core; 27 27 using System.Collections; 28 using HeuristicLab.CEDMA.DB.Interfaces;29 28 using System.Xml; 30 29 using System.Runtime.Serialization; -
trunk/sources/HeuristicLab.CEDMA.Core/3.3/TableResultsView.cs
r2139 r2223 10 10 using HeuristicLab.CEDMA.Core; 11 11 using HeuristicLab.PluginInfrastructure; 12 using HeuristicLab.CEDMA.DB.Interfaces;13 12 14 13 namespace HeuristicLab.CEDMA.Core { … … 69 68 if (e.Button == MouseButtons.Left && e.Clicks == 2) { 70 69 DataGridView.HitTestInfo hitInfo = dataGridView.HitTest(e.X, e.Y); 71 ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag; 72 string serializedData = (string)entry.Get(Ontology.SerializedData.Uri.Replace(Ontology.CedmaNameSpace, "")); 73 var model = (IItem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String(serializedData)); 70 ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag; 71 var model = (IItem)PersistenceManager.RestoreFromGZip((byte[])entry.Get("PersistedData")); 74 72 PluginManager.ControlManager.ShowControl(model.CreateView()); 75 73 }
Note: See TracChangeset
for help on using the changeset viewer.