Changeset 2153 for trunk/sources
- Timestamp:
- 07/09/09 14:22:30 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.CEDMA.Server/3.3
- Files:
-
- 5 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 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.Designer.cs
r2119 r2153 28 28 this.targetVariablesLabel = new System.Windows.Forms.Label(); 29 29 this.inputVariablesLabel = new System.Windows.Forms.Label(); 30 this.splitContainer = new System.Windows.Forms.SplitContainer(); 31 this.splitContainer.Panel1.SuspendLayout(); 32 this.splitContainer.Panel2.SuspendLayout(); 33 this.splitContainer.SuspendLayout(); 30 34 this.SuspendLayout(); 31 35 // 32 36 // targetVariableList 33 37 // 38 this.targetVariableList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 39 | System.Windows.Forms.AnchorStyles.Left) 40 | System.Windows.Forms.AnchorStyles.Right))); 34 41 this.targetVariableList.FormattingEnabled = true; 35 this.targetVariableList.Location = new System.Drawing.Point(3, 16); 42 this.targetVariableList.HorizontalScrollbar = true; 43 this.targetVariableList.Location = new System.Drawing.Point(6, 16); 36 44 this.targetVariableList.Name = "targetVariableList"; 37 this.targetVariableList.Size = new System.Drawing.Size(1 71, 409);45 this.targetVariableList.Size = new System.Drawing.Size(193, 454); 38 46 this.targetVariableList.TabIndex = 0; 39 47 this.targetVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.targetVariableList_ItemCheck); 48 this.targetVariableList.SelectedValueChanged += new System.EventHandler(this.targetVariableList_SelectedValueChanged); 40 49 // 41 50 // inputVariableList 42 51 // 52 this.inputVariableList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 53 | System.Windows.Forms.AnchorStyles.Left) 54 | System.Windows.Forms.AnchorStyles.Right))); 43 55 this.inputVariableList.FormattingEnabled = true; 44 this.inputVariableList.Location = new System.Drawing.Point(194, 16); 56 this.inputVariableList.HorizontalScrollbar = true; 57 this.inputVariableList.Location = new System.Drawing.Point(2, 16); 45 58 this.inputVariableList.Name = "inputVariableList"; 46 this.inputVariableList.Size = new System.Drawing.Size( 170, 409);59 this.inputVariableList.Size = new System.Drawing.Size(221, 454); 47 60 this.inputVariableList.TabIndex = 1; 48 61 this.inputVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputVariableList_ItemCheck); … … 60 73 // 61 74 this.inputVariablesLabel.AutoSize = true; 62 this.inputVariablesLabel.Location = new System.Drawing.Point( 191, 0);75 this.inputVariablesLabel.Location = new System.Drawing.Point(3, 0); 63 76 this.inputVariablesLabel.Name = "inputVariablesLabel"; 64 77 this.inputVariablesLabel.Size = new System.Drawing.Size(79, 13); … … 66 79 this.inputVariablesLabel.Text = "Input variables:"; 67 80 // 81 // splitContainer 82 // 83 this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; 84 this.splitContainer.Location = new System.Drawing.Point(0, 0); 85 this.splitContainer.Name = "splitContainer"; 86 // 87 // splitContainer.Panel1 88 // 89 this.splitContainer.Panel1.Controls.Add(this.targetVariablesLabel); 90 this.splitContainer.Panel1.Controls.Add(this.targetVariableList); 91 // 92 // splitContainer.Panel2 93 // 94 this.splitContainer.Panel2.Controls.Add(this.inputVariablesLabel); 95 this.splitContainer.Panel2.Controls.Add(this.inputVariableList); 96 this.splitContainer.Size = new System.Drawing.Size(429, 482); 97 this.splitContainer.SplitterDistance = 202; 98 this.splitContainer.SplitterWidth = 1; 99 this.splitContainer.TabIndex = 4; 100 // 68 101 // DispatcherView 69 102 // 70 103 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 71 104 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 72 this.Controls.Add(this.inputVariablesLabel); 73 this.Controls.Add(this.targetVariablesLabel); 74 this.Controls.Add(this.inputVariableList); 75 this.Controls.Add(this.targetVariableList); 105 this.Controls.Add(this.splitContainer); 76 106 this.Name = "DispatcherView"; 77 107 this.Size = new System.Drawing.Size(429, 482); 108 this.splitContainer.Panel1.ResumeLayout(false); 109 this.splitContainer.Panel1.PerformLayout(); 110 this.splitContainer.Panel2.ResumeLayout(false); 111 this.splitContainer.Panel2.PerformLayout(); 112 this.splitContainer.ResumeLayout(false); 78 113 this.ResumeLayout(false); 79 this.PerformLayout();80 114 81 115 } … … 87 121 private System.Windows.Forms.Label targetVariablesLabel; 88 122 private System.Windows.Forms.Label inputVariablesLabel; 123 private System.Windows.Forms.SplitContainer splitContainer; 89 124 } 90 125 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs
r2119 r2153 20 20 21 21 protected override void UpdateControls() { 22 base.UpdateControls(); 22 if (InvokeRequired) { 23 Invoke((Action)UpdateControls); 24 } else { 25 base.UpdateControls(); 26 targetVariableList.Items.Clear(); 27 inputVariableList.Items.Clear(); 23 28 24 foreach (string targetVar in dispatcher.TargetVariables) {25 targetVariableList.Items.Add(targetVar);26 }29 foreach (string targetVar in dispatcher.TargetVariables) { 30 targetVariableList.Items.Add(targetVar, false); 31 } 27 32 28 foreach (string inputVar in dispatcher.InputVariables) { 29 inputVariableList.Items.Add(inputVar); 33 foreach (string inputVar in dispatcher.InputVariables) { 34 inputVariableList.Items.Add(inputVar, false); 35 } 36 targetVariableList.ClearSelected(); 37 inputVariableList.Enabled = false; 30 38 } 31 39 } … … 40 48 41 49 private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) { 50 string selectedTarget = (string)targetVariableList.SelectedItem; 42 51 if (e.NewValue == CheckState.Checked) { 43 dispatcher.EnableInputVariable( (string)inputVariableList.Items[e.Index]);52 dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]); 44 53 } else if (e.NewValue == CheckState.Unchecked) { 45 dispatcher.DisableInputVariable( (string)inputVariableList.Items[e.Index]);54 dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]); 46 55 } 56 } 57 58 private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) { 59 string selectedTarget = (string)targetVariableList.SelectedItem; 60 UpdateInputVariableList(selectedTarget); 61 } 62 63 private void UpdateInputVariableList(string target) { 64 inputVariableList.Items.Clear(); 65 var activatedInputVariables = dispatcher.GetInputVariables(target); 66 foreach (string inputVar in dispatcher.InputVariables) { 67 inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar)); 68 } 69 inputVariableList.Enabled = true; 47 70 } 48 71 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2152 r2153 116 116 117 117 catch (Exception ex) { 118 HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message );118 HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message + Environment.NewLine + ex.StackTrace); 119 119 } 120 120 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs
r2152 r2153 57 57 } 58 58 59 public override IAlgorithm SelectAndConfigureAlgorithm(int[] targetVariables, int[] inputVariables, Problem problem) { 60 int targetVariable = SelectTargetVariable(targetVariables); 61 59 public override IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem) { 62 60 DiscoveryService ds = new DiscoveryService(); 63 61 IAlgorithm[] algos = ds.GetInstances<IAlgorithm>(); … … 102 100 if (stochasticAlgos.Count() == 0) return null; 103 101 return stochasticAlgos.ElementAt(random.Next(stochasticAlgos.Count())); 104 }105 106 public int SelectTargetVariable(int[] targetVariables) {107 return targetVariables[random.Next(targetVariables.Length)];108 102 } 109 103
Note: See TracChangeset
for help on using the changeset viewer.