- Timestamp:
- 08/03/09 14:23:54 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r2222 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using System.Linq; … … 35 33 using HeuristicLab.Core; 36 34 using HeuristicLab.Modeling; 35 using HeuristicLab.Modeling.Database; 37 36 38 37 namespace HeuristicLab.CEDMA.Server { 39 38 public abstract class DispatcherBase : IDispatcher { 40 private IStore store; 41 private DataSet dataset; 39 private IModelingDatabase database; 42 40 private List<int> allowedTargetVariables; 43 41 private Dictionary<int, List<int>> activeInputVariables; 44 42 private Problem problem; 45 43 internal event EventHandler Changed; 46 44 private object locker = new object(); … … 48 46 public IEnumerable<string> TargetVariables { 49 47 get { 50 if ( dataset!= null) {51 return dataset.Problem.AllowedTargetVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));48 if (problem != null) { 49 return Enumerable.Range(0, problem.Dataset.Columns).Select(x => problem.Dataset.GetVariableName(x)); 52 50 } else return new string[0]; 53 51 } … … 56 54 public IEnumerable<string> InputVariables { 57 55 get { 58 if ( dataset!= null) {59 return dataset.Problem.AllowedInputVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));56 if (problem != null) { 57 return TargetVariables; 60 58 } else return new string[0]; 61 59 } 62 60 } 63 61 64 public DispatcherBase(I Store store) {65 this. store = store;62 public DispatcherBase(IModelingDatabase database, Problem problem) { 63 this.problem = problem; 66 64 allowedTargetVariables = new List<int>(); 67 65 activeInputVariables = new Dictionary<int, List<int>>(); 66 problem.Changed += (sender, args) => { 67 lock (locker) { 68 allowedTargetVariables.Clear(); 69 activeInputVariables.Clear(); 70 } 71 OnChanged(); 72 }; 73 this.database = database; 68 74 } 69 75 70 public IAlgorithm GetNextJob() { 71 if (dataset == null) { 72 var datasetEntities = store.Query("?DataSet <" + Ontology.InstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 1) 73 .Select(x => (Entity)x.Get("DataSet")); 74 if (datasetEntities.Count() == 0) return null; 75 dataset = new DataSet(store, datasetEntities.ElementAt(0)); 76 foreach (int targetVar in dataset.Problem.AllowedTargetVariables) { 77 activeInputVariables.Add(targetVar, new List<int>()); 78 activeInputVariables[targetVar].AddRange(dataset.Problem.AllowedInputVariables); 79 } 80 OnChanged(); 81 } 76 public HeuristicLab.Modeling.IAlgorithm GetNextJob() { 82 77 if (allowedTargetVariables.Count > 0) { 83 78 int[] targetVariables, inputVariables; … … 92 87 } 93 88 94 IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem);89 HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, problem); 95 90 96 91 return selectedAlgorithm; … … 102 97 return targetVariables[rand.Next(targetVariables.Length)]; 103 98 } 104 public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);99 public abstract HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem); 105 100 106 101 #region IViewable Members … … 114 109 internal void EnableTargetVariable(string name) { 115 110 lock (locker) 116 allowedTargetVariables.Add( dataset.Problem.Dataset.GetVariableIndex(name));111 allowedTargetVariables.Add(problem.Dataset.GetVariableIndex(name)); 117 112 } 118 113 119 114 internal void DisableTargetVariable(string name) { 120 115 lock (locker) 121 allowedTargetVariables.Remove( dataset.Problem.Dataset.GetVariableIndex(name));116 allowedTargetVariables.Remove(problem.Dataset.GetVariableIndex(name)); 122 117 } 123 118 124 119 internal void EnableInputVariable(string target, string name) { 125 120 lock (locker) { 126 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 127 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 121 int targetIndex = problem.Dataset.GetVariableIndex(target); 122 int inputIndex = problem.Dataset.GetVariableIndex(name); 123 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 128 124 if (!activeInputVariables[targetIndex].Contains(inputIndex)) { 129 125 activeInputVariables[targetIndex].Add(inputIndex); … … 134 130 internal void DisableInputVariable(string target, string name) { 135 131 lock (locker) { 136 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 137 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 132 int targetIndex = problem.Dataset.GetVariableIndex(target); 133 int inputIndex = problem.Dataset.GetVariableIndex(name); 134 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 138 135 while (activeInputVariables[targetIndex].Remove(inputIndex)) { } 139 136 } … … 145 142 146 143 internal IEnumerable<string> GetInputVariables(string target) { 147 return activeInputVariables[dataset.Problem.Dataset.GetVariableIndex(target)] 148 .Select(i => dataset.Problem.Dataset.GetVariableName(i)); 144 int targetIndex = problem.Dataset.GetVariableIndex(target); 145 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 146 return activeInputVariables[targetIndex] 147 .Select(i => problem.Dataset.GetVariableName(i)); 149 148 } 150 149 }
Note: See TracChangeset
for help on using the changeset viewer.