Free cookie consent management tool by TermsFeed Policy Generator

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)

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.