Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2153 for trunk


Ignore:
Timestamp:
07/09/09 14:22:30 (15 years ago)
Author:
gkronber
Message:

Changed CEDMA dispatcher to allow different input variable sets for each target variable. #676 (Cockpit for the CEDMA Server to control algorithm settings)

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  
    4141    private IStore store;
    4242    private DataSet dataset;
     43    private List<int> allowedTargetVariables;
     44    private Dictionary<int, List<int>> activeInputVariables;
     45
    4346    internal event EventHandler Changed;
    4447    private object locker = new object();
     
    6063    }
    6164
    62     private List<int> allowedInputVariables;
    63     private List<int> allowedTargetVariables;
    64 
    6565    public DispatcherBase(IStore store) {
    6666      this.store = store;
    67       allowedInputVariables = new List<int>();
    6867      allowedTargetVariables = new List<int>();
     68      activeInputVariables = new Dictionary<int, List<int>>();
    6969    }
    7070
     
    7575        if (datasetEntities.Count() == 0) return null;
    7676        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        }
    7781        OnChanged();
    7882      }
    79       if (allowedTargetVariables.Count > 0 && allowedInputVariables.Count > 0) {
     83      if (allowedTargetVariables.Count > 0) {
    8084        int[] targetVariables, inputVariables;
    8185        lock (locker) {
    8286          targetVariables = allowedTargetVariables.ToArray();
    83           inputVariables = allowedInputVariables.ToArray();
    8487        }
    8588
    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
    8897        return selectedAlgorithm;
    8998      } else return null;
    9099    }
    91100
    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);
    93106
    94107    #region IViewable Members
     
    99112
    100113    #endregion
    101 
    102     internal void EnableInputVariable(string name) {
    103       lock (locker)
    104         allowedInputVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));
    105     }
    106114
    107115    internal void EnableTargetVariable(string name) {
     
    115123    }
    116124
    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      }
    120141    }
    121142
     
    123144      if (Changed != null) Changed(this, new EventArgs());
    124145    }
     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    }
    125151  }
    126152}
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.Designer.cs

    r2119 r2153  
    2828      this.targetVariablesLabel = new System.Windows.Forms.Label();
    2929      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();
    3034      this.SuspendLayout();
    3135      //
    3236      // targetVariableList
    3337      //
     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)));
    3441      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);
    3644      this.targetVariableList.Name = "targetVariableList";
    37       this.targetVariableList.Size = new System.Drawing.Size(171, 409);
     45      this.targetVariableList.Size = new System.Drawing.Size(193, 454);
    3846      this.targetVariableList.TabIndex = 0;
    3947      this.targetVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.targetVariableList_ItemCheck);
     48      this.targetVariableList.SelectedValueChanged += new System.EventHandler(this.targetVariableList_SelectedValueChanged);
    4049      //
    4150      // inputVariableList
    4251      //
     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)));
    4355      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);
    4558      this.inputVariableList.Name = "inputVariableList";
    46       this.inputVariableList.Size = new System.Drawing.Size(170, 409);
     59      this.inputVariableList.Size = new System.Drawing.Size(221, 454);
    4760      this.inputVariableList.TabIndex = 1;
    4861      this.inputVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputVariableList_ItemCheck);
     
    6073      //
    6174      this.inputVariablesLabel.AutoSize = true;
    62       this.inputVariablesLabel.Location = new System.Drawing.Point(191, 0);
     75      this.inputVariablesLabel.Location = new System.Drawing.Point(3, 0);
    6376      this.inputVariablesLabel.Name = "inputVariablesLabel";
    6477      this.inputVariablesLabel.Size = new System.Drawing.Size(79, 13);
     
    6679      this.inputVariablesLabel.Text = "Input variables:";
    6780      //
     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      //
    68101      // DispatcherView
    69102      //
    70103      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    71104      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);
    76106      this.Name = "DispatcherView";
    77107      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);
    78113      this.ResumeLayout(false);
    79       this.PerformLayout();
    80114
    81115    }
     
    87121    private System.Windows.Forms.Label targetVariablesLabel;
    88122    private System.Windows.Forms.Label inputVariablesLabel;
     123    private System.Windows.Forms.SplitContainer splitContainer;
    89124  }
    90125}
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs

    r2119 r2153  
    2020
    2121    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();
    2328
    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        }
    2732
    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;
    3038      }
    3139    }
     
    4048
    4149    private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
     50      string selectedTarget = (string)targetVariableList.SelectedItem;
    4251      if (e.NewValue == CheckState.Checked) {
    43         dispatcher.EnableInputVariable((string)inputVariableList.Items[e.Index]);
     52        dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
    4453      } else if (e.NewValue == CheckState.Unchecked) {
    45         dispatcher.DisableInputVariable((string)inputVariableList.Items[e.Index]);
     54        dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
    4655      }
     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;
    4770    }
    4871  }
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r2152 r2153  
    116116
    117117        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);
    119119        }
    120120      }
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs

    r2152 r2153  
    5757    }
    5858
    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) {
    6260      DiscoveryService ds = new DiscoveryService();
    6361      IAlgorithm[] algos = ds.GetInstances<IAlgorithm>();
     
    102100      if (stochasticAlgos.Count() == 0) return null;
    103101      return stochasticAlgos.ElementAt(random.Next(stochasticAlgos.Count()));
    104     }
    105 
    106     public int SelectTargetVariable(int[] targetVariables) {
    107       return targetVariables[random.Next(targetVariables.Length)];
    108102    }
    109103
Note: See TracChangeset for help on using the changeset viewer.