- Timestamp:
- 07/09/09 14:22:30 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r2119 r2153 41 41 private IStore store; 42 42 private DataSet dataset; 43 private List<int> allowedTargetVariables; 44 private Dictionary<int, List<int>> activeInputVariables; 45 43 46 internal event EventHandler Changed; 44 47 private object locker = new object(); … … 60 63 } 61 64 62 private List<int> allowedInputVariables;63 private List<int> allowedTargetVariables;64 65 65 public DispatcherBase(IStore store) { 66 66 this.store = store; 67 allowedInputVariables = new List<int>();68 67 allowedTargetVariables = new List<int>(); 68 activeInputVariables = new Dictionary<int, List<int>>(); 69 69 } 70 70 … … 75 75 if (datasetEntities.Count() == 0) return null; 76 76 dataset = new DataSet(store, datasetEntities.ElementAt(0)); 77 foreach (int targetVar in dataset.Problem.AllowedTargetVariables) { 78 activeInputVariables.Add(targetVar, new List<int>()); 79 activeInputVariables[targetVar].AddRange(dataset.Problem.AllowedInputVariables); 80 } 77 81 OnChanged(); 78 82 } 79 if (allowedTargetVariables.Count > 0 && allowedInputVariables.Count > 0) {83 if (allowedTargetVariables.Count > 0) { 80 84 int[] targetVariables, inputVariables; 81 85 lock (locker) { 82 86 targetVariables = allowedTargetVariables.ToArray(); 83 inputVariables = allowedInputVariables.ToArray();84 87 } 85 88 86 IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariables, inputVariables, dataset.Problem); 87 89 int targetVariable = SelectTargetVariable(targetVariables); 90 91 lock (locker) { 92 inputVariables = activeInputVariables[targetVariable].ToArray(); 93 } 94 95 IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem); 96 88 97 return selectedAlgorithm; 89 98 } else return null; 90 99 } 91 100 92 public abstract IAlgorithm SelectAndConfigureAlgorithm(int[] targetVariables, int[] inputVariables, Problem problem); 101 public virtual int SelectTargetVariable(int[] targetVariables) { 102 Random rand = new Random(); 103 return targetVariables[rand.Next(targetVariables.Length)]; 104 } 105 public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem); 93 106 94 107 #region IViewable Members … … 99 112 100 113 #endregion 101 102 internal void EnableInputVariable(string name) {103 lock (locker)104 allowedInputVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));105 }106 114 107 115 internal void EnableTargetVariable(string name) { … … 115 123 } 116 124 117 internal void DisableInputVariable(string name) { 118 lock (locker) 119 allowedInputVariables.Remove(dataset.Problem.Dataset.GetVariableIndex(name)); 125 internal void EnableInputVariable(string target, string name) { 126 lock (locker) { 127 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 128 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 129 if (!activeInputVariables[targetIndex].Contains(inputIndex)) { 130 activeInputVariables[targetIndex].Add(inputIndex); 131 } 132 } 133 } 134 135 internal void DisableInputVariable(string target, string name) { 136 lock (locker) { 137 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 138 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 139 while (activeInputVariables[targetIndex].Remove(inputIndex)) { } 140 } 120 141 } 121 142 … … 123 144 if (Changed != null) Changed(this, new EventArgs()); 124 145 } 146 147 internal IEnumerable<string> GetInputVariables(string target) { 148 return activeInputVariables[dataset.Problem.Dataset.GetVariableIndex(target)] 149 .Select(i => dataset.Problem.Dataset.GetVariableName(i)); 150 } 125 151 } 126 152 }
Note: See TracChangeset
for help on using the changeset viewer.