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