Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2227 was 2223, checked in by mkommend, 15 years ago

reintegrated branch new heuristic.modeling database backend (ticket #712)

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