Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs @ 2144

Last change on this file since 2144 was 2119, checked in by gkronber, 15 years ago

Changed dispatcher to configure algorithms to use only the allowed input variables and changed dispatching to dispatch deterministic algorithms again when the input variable set is different.

#676 (Cockpit for the CEDMA Server to control algorithm settings)

File size: 4.2 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.Core;
37using HeuristicLab.Modeling;
38
39namespace HeuristicLab.CEDMA.Server {
40  public abstract class DispatcherBase : IDispatcher {
41    private IStore store;
42    private DataSet dataset;
43    internal event EventHandler Changed;
44    private object locker = new object();
45
46    public IEnumerable<string> TargetVariables {
47      get {
48        if (dataset != null) {
49          return dataset.Problem.AllowedTargetVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));
50        } else return new string[0];
51      }
52    }
53
54    public IEnumerable<string> InputVariables {
55      get {
56        if (dataset != null) {
57          return dataset.Problem.AllowedInputVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));
58        } else return new string[0];
59      }
60    }
61
62    private List<int> allowedInputVariables;
63    private List<int> allowedTargetVariables;
64
65    public DispatcherBase(IStore store) {
66      this.store = store;
67      allowedInputVariables = new List<int>();
68      allowedTargetVariables = new List<int>();
69    }
70
71    public IAlgorithm GetNextJob() {
72      if (dataset == null) {
73        var datasetEntities = store.Query("?DataSet <" + Ontology.InstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 1)
74          .Select(x => (Entity)x.Get("DataSet"));
75        if (datasetEntities.Count() == 0) return null;
76        dataset = new DataSet(store, datasetEntities.ElementAt(0));
77        OnChanged();
78      }
79      if (allowedTargetVariables.Count > 0 && allowedInputVariables.Count > 0) {
80        int[] targetVariables, inputVariables;
81        lock (locker) {
82          targetVariables = allowedTargetVariables.ToArray();
83          inputVariables = allowedInputVariables.ToArray();
84        }
85
86        IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariables, inputVariables, dataset.Problem);
87       
88        return selectedAlgorithm;
89      } else return null;
90    }
91
92    public abstract IAlgorithm SelectAndConfigureAlgorithm(int[] targetVariables, int[] inputVariables, Problem problem);
93
94    #region IViewable Members
95
96    public IView CreateView() {
97      return new DispatcherView(this);
98    }
99
100    #endregion
101
102    internal void EnableInputVariable(string name) {
103      lock (locker)
104        allowedInputVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));
105    }
106
107    internal void EnableTargetVariable(string name) {
108      lock (locker)
109        allowedTargetVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));
110    }
111
112    internal void DisableTargetVariable(string name) {
113      lock (locker)
114        allowedTargetVariables.Remove(dataset.Problem.Dataset.GetVariableIndex(name));
115    }
116
117    internal void DisableInputVariable(string name) {
118      lock (locker)
119        allowedInputVariables.Remove(dataset.Problem.Dataset.GetVariableIndex(name));
120    }
121
122    private void OnChanged() {
123      if (Changed != null) Changed(this, new EventArgs());
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.