Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/09 14:23:54 (16 years ago)
Author:
mkommend
Message:

reintegrated branch new heuristic.modeling database backend (ticket #712)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs

    r2222 r2223  
    2727using System.Net;
    2828using System.ServiceModel;
    29 using HeuristicLab.CEDMA.DB.Interfaces;
    30 using HeuristicLab.CEDMA.DB;
    3129using System.ServiceModel.Description;
    3230using System.Linq;
     
    3533using HeuristicLab.Core;
    3634using HeuristicLab.Modeling;
     35using HeuristicLab.Modeling.Database;
    3736
    3837namespace HeuristicLab.CEDMA.Server {
    3938  public abstract class DispatcherBase : IDispatcher {
    40     private IStore store;
    41     private DataSet dataset;
     39    private IModelingDatabase database;
    4240    private List<int> allowedTargetVariables;
    4341    private Dictionary<int, List<int>> activeInputVariables;
    44 
     42    private Problem problem;
    4543    internal event EventHandler Changed;
    4644    private object locker = new object();
     
    4846    public IEnumerable<string> TargetVariables {
    4947      get {
    50         if (dataset != null) {
    51           return dataset.Problem.AllowedTargetVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));
     48        if (problem != null) {
     49          return Enumerable.Range(0, problem.Dataset.Columns).Select(x => problem.Dataset.GetVariableName(x));
    5250        } else return new string[0];
    5351      }
     
    5654    public IEnumerable<string> InputVariables {
    5755      get {
    58         if (dataset != null) {
    59           return dataset.Problem.AllowedInputVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));
     56        if (problem != null) {
     57          return TargetVariables;
    6058        } else return new string[0];
    6159      }
    6260    }
    6361
    64     public DispatcherBase(IStore store) {
    65       this.store = store;
     62    public DispatcherBase(IModelingDatabase database, Problem problem) {
     63      this.problem = problem;
    6664      allowedTargetVariables = new List<int>();
    6765      activeInputVariables = new Dictionary<int, List<int>>();
     66      problem.Changed += (sender, args) => {
     67        lock (locker) {
     68          allowedTargetVariables.Clear();
     69          activeInputVariables.Clear();
     70        }
     71        OnChanged();
     72      };
     73      this.database = database;
    6874    }
    6975
    70     public IAlgorithm GetNextJob() {
    71       if (dataset == null) {
    72         var datasetEntities = store.Query("?DataSet <" + Ontology.InstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 1)
    73           .Select(x => (Entity)x.Get("DataSet"));
    74         if (datasetEntities.Count() == 0) return null;
    75         dataset = new DataSet(store, datasetEntities.ElementAt(0));
    76         foreach (int targetVar in dataset.Problem.AllowedTargetVariables) {
    77           activeInputVariables.Add(targetVar, new List<int>());
    78           activeInputVariables[targetVar].AddRange(dataset.Problem.AllowedInputVariables);
    79         }
    80         OnChanged();
    81       }
     76    public HeuristicLab.Modeling.IAlgorithm GetNextJob() {
    8277      if (allowedTargetVariables.Count > 0) {
    8378        int[] targetVariables, inputVariables;
     
    9287        }
    9388
    94         IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem);
     89        HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, problem);
    9590
    9691        return selectedAlgorithm;
     
    10297      return targetVariables[rand.Next(targetVariables.Length)];
    10398    }
    104     public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);
     99    public abstract HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);
    105100
    106101    #region IViewable Members
     
    114109    internal void EnableTargetVariable(string name) {
    115110      lock (locker)
    116         allowedTargetVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));
     111        allowedTargetVariables.Add(problem.Dataset.GetVariableIndex(name));
    117112    }
    118113
    119114    internal void DisableTargetVariable(string name) {
    120115      lock (locker)
    121         allowedTargetVariables.Remove(dataset.Problem.Dataset.GetVariableIndex(name));
     116        allowedTargetVariables.Remove(problem.Dataset.GetVariableIndex(name));
    122117    }
    123118
    124119    internal void EnableInputVariable(string target, string name) {
    125120      lock (locker) {
    126         int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target);
    127         int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name);
     121        int targetIndex = problem.Dataset.GetVariableIndex(target);
     122        int inputIndex = problem.Dataset.GetVariableIndex(name);
     123        if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>();
    128124        if (!activeInputVariables[targetIndex].Contains(inputIndex)) {
    129125          activeInputVariables[targetIndex].Add(inputIndex);
     
    134130    internal void DisableInputVariable(string target, string name) {
    135131      lock (locker) {
    136         int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target);
    137         int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name);
     132        int targetIndex = problem.Dataset.GetVariableIndex(target);
     133        int inputIndex = problem.Dataset.GetVariableIndex(name);
     134        if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>();
    138135        while (activeInputVariables[targetIndex].Remove(inputIndex)) { }
    139136      }
     
    145142
    146143    internal IEnumerable<string> GetInputVariables(string target) {
    147       return activeInputVariables[dataset.Problem.Dataset.GetVariableIndex(target)]
    148         .Select(i => dataset.Problem.Dataset.GetVariableName(i));
     144      int targetIndex = problem.Dataset.GetVariableIndex(target);
     145      if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>();
     146      return activeInputVariables[targetIndex]
     147        .Select(i => problem.Dataset.GetVariableName(i));
    149148    }
    150149  }
Note: See TracChangeset for help on using the changeset viewer.