Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs @ 1104

Last change on this file since 1104 was 1075, checked in by gkronber, 16 years ago

worked on presentation layer for CEDMA #419

File size: 6.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Collections;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using System.Xml;
30using System.Runtime.Serialization;
31using System.IO;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Data;
34using HeuristicLab.DataAnalysis;
35using System.Drawing;
36
37namespace HeuristicLab.CEDMA.Core {
38  public class Results : IViewable, IEnumerable<Record> {
39    private Dictionary<Record, Dataset> datasets;
40
41    private IStore store;
42    public IStore Store {
43      get { return store; }
44      set {
45        store = value;
46      }
47    }
48
49    private void ReloadList() {
50      var results = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree))
51      .Select(x => store.Select(new SelectFilter(
52        new Entity[] { new Entity(x.Subject.Uri) },
53        new Entity[] { Ontology.PredicateModelAttribute },
54          new Resource[] { Ontology.AnyEntity })));
55
56      Random random = new Random();
57      foreach(Statement[] ss in results) {
58        if(ss.Length > 0) {
59          Record r = new Record(this, ss[0].Subject.Uri);
60          r.Set(Record.X_JITTER, random.NextDouble() * 2.0 - 1.0);
61          r.Set(Record.Y_JITTER, random.NextDouble() * 2.0 - 1.0);
62          foreach(Statement s in ss) {
63            string varName;
64            predicateToVariableName.TryGetValue(s.Predicate, out varName);
65            if(varName != null) {
66              if(varName == Record.TREE_HEIGHT || varName == Record.TREE_SIZE || varName == Record.TARGET_VARIABLE) {
67                r.Set(varName, (double)(int)((Literal)s.Property).Value);
68              } else {
69                r.Set(varName, (double)((Literal)s.Property).Value);
70              }
71            }
72          }
73          lock(records) {
74            records.Add(r);
75          }
76          FireRecordAdded(r);
77        }
78      }
79      FireChanged();
80    }
81
82    public Results(IStore store)
83      : base() {
84      this.store = store;
85      records = new List<Record>();
86      datasets = new Dictionary<Record, Dataset>();
87      //predicateToVariableName = new Dictionary<Entity, string>();
88      //predicateToVariableName[targetVariablePredicate] = Record.TARGET_VARIABLE;
89      //predicateToVariableName[treeSizePredicate] = Record.TREE_SIZE;
90      //predicateToVariableName[treeHeightPredicate] = Record.TREE_HEIGHT;
91      //predicateToVariableName[selectionPressurePredicate] = Record.SELECTIONPRESSURE;
92      //predicateToVariableName[trainingMAPEPredicate] = Record.MAPE_TRAINING;
93      //predicateToVariableName[validationMAPEPredicate] = Record.MAPE_VALIDATION;
94      //predicateToVariableName[testMAPEPredicate] = Record.MAPE_TEST;
95      //predicateToVariableName[trainingR2Predicate] = Record.R2_TRAINING;
96      //predicateToVariableName[validationR2Predicate] = Record.R2_VALIDATION;
97      //predicateToVariableName[testR2Predicate] = Record.R2_TEST;
98    }
99
100    public override IView CreateView() {
101      return new ResultsView(this);
102    }
103
104    //internal void OpenModel(Record record) {
105    //  IList<Statement> modelResults = store.Select(new Statement(new Entity(record.Uri), Ontology.PredicateSerializedData, Ontology.AnyEntity));
106    //  if(modelResults.Count == 1) {
107    //    string rawData = ((SerializedLiteral)modelResults[0].Property).RawData;
108    //    XmlDocument doc = new XmlDocument();
109    //    doc.LoadXml(rawData);
110    //    IFunctionTree tree = (IFunctionTree)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
111    //    int targetVariable = (int)record.Get(Record.TARGET_VARIABLE);
112    //    Dataset dataset = GetDataset(record);
113
114    //    ModelView modelView = new ModelView(record, dataset, tree, targetVariable);
115    //    PluginManager.ControlManager.ShowControl(modelView);
116    //  }
117    //}
118
119    //private Dataset GetDataset(Record record) {
120    //  if(!datasets.ContainsKey(record)) {
121    //    IList<Statement> result = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateHasModel, new Entity(record.Uri)));
122    //    if(result.Count == 1) {
123    //      IList<Statement> datasetResult = store.Select(new Statement(result[0].Subject, Ontology.PredicateSerializedData, Ontology.AnyEntity));
124    //      if(datasetResult.Count == 1) {
125    //        string rawData = ((SerializedLiteral)datasetResult[0].Property).RawData;
126    //        XmlDocument doc = new XmlDocument();
127    //        doc.LoadXml(rawData);
128    //        Dataset dataset = (Dataset)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
129    //        datasets.Add(record, dataset);
130    //      }
131    //    }
132    //  }
133    //  return datasets[record];
134    //}
135
136    //internal void OpenAlgorithm(Record record) {
137    //  IList<Statement> generatedBy = store.Select(new Statement(new Entity(record.Uri), Ontology.PredicateGeneratedBy, Ontology.AnyEntity));
138    //  if(generatedBy.Count == 1) {
139    //    IList<Statement> algoResult = store.Select(new Statement((Entity)generatedBy[0].Property, Ontology.PredicateSerializedData, Ontology.AnyEntity));
140    //    if(algoResult.Count == 1) {
141    //      string rawData = ((SerializedLiteral)algoResult[0].Property).RawData;
142    //      XmlDocument doc = new XmlDocument();
143    //      doc.LoadXml(rawData);
144    //      IItem algo = (IItem)PersistenceManager.Restore(doc.ChildNodes[1], new Dictionary<Guid, IStorable>());
145    //      PluginManager.ControlManager.ShowControl(algo.CreateView());
146    //    }
147    //  }
148    //}
149
150    internal void FilterDataSet(Entity entity) {
151
152    }
153
154    #region IEnumerable<Record> Members
155
156    public IEnumerator<Record> GetEnumerator() {
157      throw new NotImplementedException();
158    }
159
160    #endregion
161
162    #region IEnumerable Members
163
164    IEnumerator IEnumerable.GetEnumerator() {
165      return this.GetEnumerator();
166    }
167
168    #endregion
169  }
170}
Note: See TracBrowser for help on using the repository browser.