Changeset 2193 for branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
- Timestamp:
- 07/28/09 15:26:29 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r2185 r2193 36 36 using HeuristicLab.Core; 37 37 using HeuristicLab.Modeling; 38 using HeuristicLab.Modeling.Database; 38 39 39 40 namespace HeuristicLab.CEDMA.Server { 40 41 public abstract class DispatcherBase : IDispatcher { 41 42 private IModelingDatabase database; 42 private DataSet dataset;43 43 private List<int> allowedTargetVariables; 44 44 private Dictionary<int, List<int>> activeInputVariables; 45 45 private Problem problem; 46 46 internal event EventHandler Changed; 47 47 private object locker = new object(); … … 49 49 public IEnumerable<string> TargetVariables { 50 50 get { 51 if ( dataset!= null) {52 return dataset.Problem.AllowedTargetVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));51 if (problem != null) { 52 return problem.AllowedTargetVariables.Select(x => problem.Dataset.GetVariableName(x)); 53 53 } else return new string[0]; 54 54 } … … 57 57 public IEnumerable<string> InputVariables { 58 58 get { 59 if ( dataset!= null) {60 return dataset.Problem.AllowedInputVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));59 if (problem != null) { 60 return problem.AllowedInputVariables.Select(x => problem.Dataset.GetVariableName(x)); 61 61 } else return new string[0]; 62 62 } 63 63 } 64 64 65 public DispatcherBase(IModelingDatabase database) { 65 public DispatcherBase(IModelingDatabase database, Problem problem) { 66 this.problem = problem; 66 67 this.database = database; 67 68 allowedTargetVariables = new List<int>(); … … 69 70 } 70 71 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 foreach (int targetVar in dataset.Problem.AllowedTargetVariables) { 72 public HeuristicLab.Modeling.IAlgorithm GetNextJob() { 73 if (problem == null) { 74 foreach (int targetVar in problem.AllowedTargetVariables) { 78 75 activeInputVariables.Add(targetVar, new List<int>()); 79 activeInputVariables[targetVar].AddRange( dataset.Problem.AllowedInputVariables);76 activeInputVariables[targetVar].AddRange(problem.AllowedInputVariables); 80 77 } 81 78 OnChanged(); … … 93 90 } 94 91 95 IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem);92 HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, problem); 96 93 97 94 return selectedAlgorithm; … … 103 100 return targetVariables[rand.Next(targetVariables.Length)]; 104 101 } 105 public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);102 public abstract HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem); 106 103 107 104 #region IViewable Members 108 105 109 106 public IView CreateView() { 110 return new DispatcherView(this);107 return new ProblemView(this); 111 108 } 112 109 … … 115 112 internal void EnableTargetVariable(string name) { 116 113 lock (locker) 117 allowedTargetVariables.Add( dataset.Problem.Dataset.GetVariableIndex(name));114 allowedTargetVariables.Add(problem.Dataset.GetVariableIndex(name)); 118 115 } 119 116 120 117 internal void DisableTargetVariable(string name) { 121 118 lock (locker) 122 allowedTargetVariables.Remove( dataset.Problem.Dataset.GetVariableIndex(name));119 allowedTargetVariables.Remove(problem.Dataset.GetVariableIndex(name)); 123 120 } 124 121 125 122 internal void EnableInputVariable(string target, string name) { 126 123 lock (locker) { 127 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target);128 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name);124 int targetIndex = problem.Dataset.GetVariableIndex(target); 125 int inputIndex = problem.Dataset.GetVariableIndex(name); 129 126 if (!activeInputVariables[targetIndex].Contains(inputIndex)) { 130 127 activeInputVariables[targetIndex].Add(inputIndex); … … 135 132 internal void DisableInputVariable(string target, string name) { 136 133 lock (locker) { 137 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target);138 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name);134 int targetIndex = problem.Dataset.GetVariableIndex(target); 135 int inputIndex = problem.Dataset.GetVariableIndex(name); 139 136 while (activeInputVariables[targetIndex].Remove(inputIndex)) { } 140 137 } … … 146 143 147 144 internal IEnumerable<string> GetInputVariables(string target) { 148 return activeInputVariables[ dataset.Problem.Dataset.GetVariableIndex(target)]149 .Select(i => dataset.Problem.Dataset.GetVariableName(i));145 return activeInputVariables[problem.Dataset.GetVariableIndex(target)] 146 .Select(i => problem.Dataset.GetVariableName(i)); 150 147 } 151 148 }
Note: See TracChangeset
for help on using the changeset viewer.