Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs @ 2078

Last change on this file since 2078 was 2057, checked in by gkronber, 15 years ago

Improved stability of hive backend for CEDMA. #642 (Hive backend for CEDMA)

File size: 6.6 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.Text;
25using System.Windows.Forms;
26using HeuristicLab.PluginInfrastructure;
27using System.Net;
28using System.ServiceModel;
29using HeuristicLab.CEDMA.DB.Interfaces;
30using HeuristicLab.CEDMA.DB;
31using System.ServiceModel.Description;
32using System.Linq;
33using HeuristicLab.CEDMA.Core;
34using HeuristicLab.GP.StructureIdentification;
35using HeuristicLab.Data;
36using HeuristicLab.Grid;
37using System.Diagnostics;
38using HeuristicLab.Core;
39using System.Threading;
40using HeuristicLab.Modeling;
41
42namespace HeuristicLab.CEDMA.Server {
43  public abstract class ExecuterBase : IExecuter {
44    private IDispatcher dispatcher;
45    protected IDispatcher Dispatcher {
46      get { return dispatcher; }
47    }
48    private IStore store;
49
50    private int maxActiveJobs;
51    public int MaxActiveJobs {
52      get { return maxActiveJobs; }
53      set {
54        if (value < 0) throw new ArgumentException("Only positive values are allowed for MaxActiveJobs");
55        maxActiveJobs = value;
56      }
57    }
58
59    public ExecuterBase(IDispatcher dispatcher, IStore store) {
60      maxActiveJobs = 10;
61      this.dispatcher = dispatcher;
62      this.store = store;
63    }
64
65    public void Start() {
66      new Thread(StartJobs).Start();
67    }
68
69    protected abstract void StartJobs();
70
71    protected void SetResults(IScope src, IScope target) {
72      foreach (IVariable v in src.Variables) {
73        target.AddVariable(v);
74      }
75      foreach (IScope subScope in src.SubScopes) {
76        target.AddSubScope(subScope);
77      }
78      foreach (KeyValuePair<string, string> alias in src.Aliases) {
79        target.AddAlias(alias.Key, alias.Value);
80      }
81    }
82
83    protected void StoreResults(IAlgorithm finishedAlgorithm) {
84      Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
85      IModel model = finishedAlgorithm.Model;
86      List<Statement> statements = new List<Statement>();
87      statements.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel));
88      statements.Add(new Statement(modelEntity, Ontology.TargetVariable, new Literal(model.TargetVariable)));
89      statements.Add(new Statement(modelEntity, Ontology.Name, new Literal(finishedAlgorithm.Description)));
90     
91      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanSquaredError, new Literal(model.TrainingMeanSquaredError)));
92      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanSquaredError, new Literal(model.ValidationMeanSquaredError)));
93      statements.Add(new Statement(modelEntity, Ontology.TestMeanSquaredError, new Literal(model.TestMeanSquaredError)));
94      statements.Add(new Statement(modelEntity, Ontology.TrainingCoefficientOfDetermination, new Literal(model.TrainingCoefficientOfDetermination)));
95      statements.Add(new Statement(modelEntity, Ontology.ValidationCoefficientOfDetermination, new Literal(model.ValidationCoefficientOfDetermination)));
96      statements.Add(new Statement(modelEntity, Ontology.TestCoefficientOfDetermination, new Literal(model.TestCoefficientOfDetermination)));
97      statements.Add(new Statement(modelEntity, Ontology.TrainingVarianceAccountedFor, new Literal(model.TrainingVarianceAccountedFor)));
98      statements.Add(new Statement(modelEntity, Ontology.ValidationVarianceAccountedFor, new Literal(model.ValidationVarianceAccountedFor)));
99      statements.Add(new Statement(modelEntity, Ontology.TestVarianceAccountedFor, new Literal(model.TestVarianceAccountedFor)));
100      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, new Literal(model.TrainingMeanAbsolutePercentageError)));
101      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, new Literal(model.ValidationMeanAbsolutePercentageError)));
102      statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageError, new Literal(model.TestMeanAbsolutePercentageError)));
103      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, new Literal(model.TrainingMeanAbsolutePercentageOfRangeError)));
104      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, new Literal(model.ValidationMeanAbsolutePercentageOfRangeError)));
105      statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, new Literal(model.TestMeanAbsolutePercentageOfRangeError)));
106
107      for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) {
108        try {
109          string variableName = finishedAlgorithm.Dataset.GetVariableName(i);
110          double qualImpact = model.GetVariableQualityImpact(variableName);
111          double evalImpact = model.GetVariableEvaluationImpact(variableName);
112
113          Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
114          statements.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));
115          statements.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));
116          statements.Add(new Statement(inputVariableEntity, Ontology.EvaluationImpact, new Literal(evalImpact)));
117          statements.Add(new Statement(inputVariableEntity, Ontology.QualityImpact, new Literal(qualImpact)));
118          statements.Add(new Statement(inputVariableEntity, Ontology.Name, new Literal(variableName)));
119        }
120        catch (ArgumentException) {
121          // ignore
122        }
123      }
124
125      byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
126      statements.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));
127      store.AddRange(statements);
128    }
129
130    public abstract string[] GetJobs();
131  }
132}
Note: See TracBrowser for help on using the repository browser.