Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2352 was 2290, checked in by gkronber, 15 years ago
  • introduced a variablename to index mapping for SVM models (to make sure we can use the model for prediction in the model analyzer)
  • added support to enable and disable algorithms in the dispatcher and removed DispatcherBase
  • fixed bugs when calculating variable impacts and reading the final model of GP algorithms

#722 (IModel should provide a Predict() method to get predicted values for an input vector)

File size: 3.3 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 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;
37using HeuristicLab.Modeling;
38using HeuristicLab.Modeling.Database;
39
40namespace HeuristicLab.CEDMA.Server {
41  public abstract class ExecuterBase : IExecuter {
42    internal event EventHandler Changed;
43
44    private IDispatcher dispatcher;
45    protected IDispatcher Dispatcher {
46      get { return dispatcher; }
47    }
48    private IModelingDatabase databaseService;
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        OnChanged();
57      }
58    }
59
60    public int CalculatedJobs {
61      get;
62      set;
63    }
64    public int StoredJobs {
65      get;
66      set;
67    }
68
69    public ExecuterBase(IDispatcher dispatcher, IModelingDatabase databaseService) {
70      CalculatedJobs = 0;
71      maxActiveJobs = 10;
72      this.dispatcher = dispatcher;
73      this.databaseService = databaseService;
74      StoredJobs = databaseService.GetAllModels().Count();
75    }
76
77    public void Start() {
78      new Thread(StartJobs).Start();
79    }
80
81    protected abstract void StartJobs();
82
83    protected void SetResults(IScope src, IScope target) {
84      foreach (HeuristicLab.Core.IVariable v in src.Variables) {
85        target.AddVariable(v);
86      }
87      foreach (IScope subScope in src.SubScopes) {
88        target.AddSubScope(subScope);
89      }
90      foreach (KeyValuePair<string, string> alias in src.Aliases) {
91        target.AddAlias(alias.Key, alias.Value);
92      }
93    }
94
95    protected void StoreResults(HeuristicLab.Modeling.IAlgorithm finishedAlgorithm) {
96      CalculatedJobs++;
97      databaseService.Persist(finishedAlgorithm);
98      StoredJobs++;
99      OnChanged();
100    }
101
102    public abstract string[] GetJobs();
103
104    protected internal void OnChanged() {
105      if (Changed != null) Changed(this, new EventArgs());
106    }
107
108    #region IViewable Members
109
110    public IView CreateView() {
111      return new ExecuterView(this);
112    }
113
114    #endregion
115  }
116}
Note: See TracBrowser for help on using the repository browser.