Free cookie consent management tool by TermsFeed Policy Generator

source: branches/plugins/HeuristicLab.CEDMA.Core/3.2/Results.cs @ 4105

Last change on this file since 4105 was 1156, checked in by gkronber, 16 years ago

worked on #419

  • added function to open and display any model
  • added 'hard-coded' implementation of offspring selection GP (work in progress)
  • added properties for max. size and max. height in StandardGP
File size: 4.0 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 : ItemBase {
39    private string[] categoricalVariables = null;
40    public string[] CategoricalVariables {
41      get {
42        if (categoricalVariables == null) {
43          LoadModelAttributes();
44        }
45        return categoricalVariables;
46      }
47    }
48
49    private string[] ordinalVariables = null;
50    public string[] OrdinalVariables {
51      get {
52        if (ordinalVariables == null) {
53          LoadModelAttributes();
54        }
55        return ordinalVariables;
56      }
57    }
58
59    private IStore store;
60    public IStore Store {
61      get { return store; }
62      set {
63        store = value;
64      }
65    }
66
67    private Entity dataSetEntity;
68
69    public Results(IStore store) {
70      this.store = store;
71    }
72
73    internal void FilterDataSet(Entity entity) {
74      this.dataSetEntity = entity;
75    }
76
77    private List<ResultsEntry> entries = null;
78    private bool cached = false;
79    public IEnumerable<ResultsEntry> GetEntries() {
80      if (!cached)
81        return SelectRows();
82      return entries.AsEnumerable();
83    }
84
85    private IEnumerable<ResultsEntry> SelectRows() {
86      if (store == null) yield break;
87      entries = new List<ResultsEntry>();
88      var results = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
89        "?Model ?Attribute ?Value .")
90        .GroupBy(x => (Entity)x.Get("Model"));
91      foreach (var modelBindings in results) {
92        ResultsEntry entry = new ResultsEntry(modelBindings.Key.Uri);
93        foreach (var binding in modelBindings) {
94          if (binding.Get("Value") is Literal) {
95            string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
96            if (entry.Get(name) == null) {
97              object value = ((Literal)binding.Get("Value")).Value;
98              entry.Set(name, value);
99            }
100          }
101        }
102        entries.Add(entry);
103        yield return entry;
104      }
105
106      FireChanged();
107      cached = true;
108    }
109
110    internal IEnumerable<string> SelectModelAttributes() {
111      return CategoricalVariables.Concat(OrdinalVariables);
112    }
113
114    private void LoadModelAttributes() {
115      this.ordinalVariables =
116        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .")
117        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
118        .ToArray();
119      this.categoricalVariables =
120        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .")
121        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
122        .ToArray();
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.