Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/09 15:26:29 (15 years ago)
Author:
gkronber
Message:

Added problem view for the cedma server. #712

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs

    r2185 r2193  
    3636using HeuristicLab.Core;
    3737using HeuristicLab.Modeling;
     38using HeuristicLab.Modeling.Database;
    3839
    3940namespace HeuristicLab.CEDMA.Server {
    4041  public abstract class DispatcherBase : IDispatcher {
    4142    private IModelingDatabase database;
    42     private DataSet dataset;
    4343    private List<int> allowedTargetVariables;
    4444    private Dictionary<int, List<int>> activeInputVariables;
    45 
     45    private Problem problem;
    4646    internal event EventHandler Changed;
    4747    private object locker = new object();
     
    4949    public IEnumerable<string> TargetVariables {
    5050      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));
    5353        } else return new string[0];
    5454      }
     
    5757    public IEnumerable<string> InputVariables {
    5858      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));
    6161        } else return new string[0];
    6262      }
    6363    }
    6464
    65     public DispatcherBase(IModelingDatabase database) {
     65    public DispatcherBase(IModelingDatabase database, Problem problem) {
     66      this.problem = problem;
    6667      this.database = database;
    6768      allowedTargetVariables = new List<int>();
     
    6970    }
    7071
    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) {
    7875          activeInputVariables.Add(targetVar, new List<int>());
    79           activeInputVariables[targetVar].AddRange(dataset.Problem.AllowedInputVariables);
     76          activeInputVariables[targetVar].AddRange(problem.AllowedInputVariables);
    8077        }
    8178        OnChanged();
     
    9390        }
    9491
    95         IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem);
     92        HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, problem);
    9693
    9794        return selectedAlgorithm;
     
    103100      return targetVariables[rand.Next(targetVariables.Length)];
    104101    }
    105     public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);
     102    public abstract HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);
    106103
    107104    #region IViewable Members
    108105
    109106    public IView CreateView() {
    110       return new DispatcherView(this);
     107      return new ProblemView(this);
    111108    }
    112109
     
    115112    internal void EnableTargetVariable(string name) {
    116113      lock (locker)
    117         allowedTargetVariables.Add(dataset.Problem.Dataset.GetVariableIndex(name));
     114        allowedTargetVariables.Add(problem.Dataset.GetVariableIndex(name));
    118115    }
    119116
    120117    internal void DisableTargetVariable(string name) {
    121118      lock (locker)
    122         allowedTargetVariables.Remove(dataset.Problem.Dataset.GetVariableIndex(name));
     119        allowedTargetVariables.Remove(problem.Dataset.GetVariableIndex(name));
    123120    }
    124121
    125122    internal void EnableInputVariable(string target, string name) {
    126123      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);
    129126        if (!activeInputVariables[targetIndex].Contains(inputIndex)) {
    130127          activeInputVariables[targetIndex].Add(inputIndex);
     
    135132    internal void DisableInputVariable(string target, string name) {
    136133      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);
    139136        while (activeInputVariables[targetIndex].Remove(inputIndex)) { }
    140137      }
     
    146143
    147144    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));
    150147    }
    151148  }
Note: See TracChangeset for help on using the changeset viewer.