Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1912 was 1898, checked in by gkronber, 16 years ago

Implemented and integrated first version of backend for execution of CEDMA runs on HL.Hive. #642 (Hive backend for CEDMA)

File size: 5.9 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;
40
41namespace HeuristicLab.CEDMA.Server {
42  public abstract class ExecuterBase : IExecuter {
43    private IDispatcher dispatcher;
44    protected IDispatcher Dispatcher {
45      get { return dispatcher; }
46    }
47    private IStore store;
48
49    private int maxActiveJobs;
50    public int MaxActiveJobs {
51      get { return maxActiveJobs; }
52      set {
53        if (value < 0) throw new ArgumentException("Only positive values are allowed for MaxActiveJobs");
54        maxActiveJobs = value;
55      }
56    }
57
58    public ExecuterBase(IDispatcher dispatcher, IStore store) {
59      maxActiveJobs = 10;
60      this.dispatcher = dispatcher;
61      this.store = store;
62    }
63
64    public void Start() {
65      new Thread(StartJobs).Start();
66    }
67
68    protected abstract void StartJobs();
69
70    protected void StoreResults(Execution finishedExecution, IEngine finishedEngine) {
71      Entity model = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
72      store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, model));
73      StoreModelAttribute(model, Ontology.TargetVariable, finishedExecution.TargetVariable);
74      StoreModelAttribute(model, Ontology.AlgorithmName, finishedExecution.Description);
75      Scope bestModelScope = finishedEngine.GlobalScope.GetVariableValue<Scope>("BestValidationSolution", false);
76      StoreModelVariable(model, Ontology.TrainingMeanSquaredError, bestModelScope, "Quality");
77      StoreModelVariable(model, Ontology.ValidationMeanSquaredError, bestModelScope, "ValidationQuality");
78      StoreModelVariable(model, Ontology.TestMeanSquaredError, bestModelScope, "TestQuality");
79      StoreModelVariable(model, Ontology.TrainingMeanAbsolutePercentageError, bestModelScope, "TrainingMAPE");
80      StoreModelVariable(model, Ontology.ValidationMeanAbsolutePercentageError, bestModelScope, "ValidationMAPE");
81      StoreModelVariable(model, Ontology.TestMeanAbsolutePercentageError, bestModelScope, "TestMAPE");
82      StoreModelVariable(model, Ontology.TrainingMeanAbsolutePercentageOfRangeError, bestModelScope, "TrainingMAPRE");
83      StoreModelVariable(model, Ontology.ValidationMeanAbsolutePercentageOfRangeError, bestModelScope, "ValidationMAPRE");
84      StoreModelVariable(model, Ontology.TestMeanAbsolutePercentageOfRangeError, bestModelScope, "TestMAPRE");
85      StoreModelVariable(model, Ontology.TrainingCoefficientOfDetermination, bestModelScope, "TrainingR2");
86      StoreModelVariable(model, Ontology.ValidationCoefficientOfDetermination, bestModelScope, "ValidationR2");
87      StoreModelVariable(model, Ontology.TestCoefficientOfDetermination, bestModelScope, "TestR2");
88      StoreModelVariable(model, Ontology.TrainingCoefficientOfDetermination, bestModelScope, "TrainingVAF");
89      StoreModelVariable(model, Ontology.ValidationCoefficientOfDetermination, bestModelScope, "ValidationVAF");
90      StoreModelVariable(model, Ontology.TestCoefficientOfDetermination, bestModelScope, "TestVAF");
91      StoreModelVariable(model, Ontology.TrainingTheilsInequalityCoefficient, bestModelScope, "TrainingTheilInequalityCoefficient");
92      StoreModelVariable(model, Ontology.ValidationTheilsInequalityCoefficient, bestModelScope, "ValidationTheilInequalityCoefficient");
93      StoreModelVariable(model, Ontology.TestTheilsInequalityCoefficient, bestModelScope, "TestTheilInequalityCoefficient");
94      StoreModelVariable(model, Ontology.TrainingAccuracy, bestModelScope, "TrainingAccuracy");
95      StoreModelVariable(model, Ontology.ValidationAccuracy, bestModelScope, "ValidationAccuracy");
96      StoreModelVariable(model, Ontology.TestAccuracy, bestModelScope, "TestAccuracy");
97      StoreModelVariable(model, Ontology.TreeSize, bestModelScope, "TreeSize");
98      StoreModelVariable(model, Ontology.TreeHeight, bestModelScope, "TreeHeight");
99      StoreModelVariable(model, Ontology.EvaluatedSolutions, bestModelScope, "EvaluatedSolutions");
100
101      byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
102      store.Add(new Statement(model, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
103    }
104
105    private void StoreModelVariable(Entity model, Entity entity, Scope scope, string variableName) {
106      if (scope.GetVariable(variableName) != null)
107        StoreModelAttribute(model, entity, scope.GetVariableValue<ObjectData>(variableName, false).Data);
108    }
109
110    private void StoreModelAttribute(Entity model, Entity predicate, object value) {
111      store.Add(new Statement(model, predicate, new Literal(value)));
112    }
113
114    public abstract string[] GetJobs();
115  }
116}
Note: See TracBrowser for help on using the repository browser.