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.Core;
|
---|
37 | using HeuristicLab.Modeling;
|
---|
38 |
|
---|
39 | namespace 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 | }
|
---|