Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2258


Ignore:
Timestamp:
08/07/09 16:50:07 (15 years ago)
Author:
gkronber
Message:
  • Reimplemented method to read a list of already executed algorithms and configurations from the results DB
  • Fixed a bug in the GridExecuter
  • Added a button in the dispatcher view to speed up configuration of input variables

#712

Location:
trunk/sources/HeuristicLab.CEDMA.Server/3.3
Files:
5 edited

Legend:

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

    r2223 r2258  
    3838  public abstract class DispatcherBase : IDispatcher {
    3939    private IModelingDatabase database;
     40    public IModelingDatabase Database {
     41      get {
     42        return database;
     43      }
     44    }
    4045    private List<int> allowedTargetVariables;
    4146    private Dictionary<int, List<int>> activeInputVariables;
    4247    private Problem problem;
     48    public Problem Problem {
     49      get {
     50        return problem;
     51      }
     52    }
    4353    internal event EventHandler Changed;
    4454    private object locker = new object();
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.Designer.cs

    r2153 r2258  
    2929      this.inputVariablesLabel = new System.Windows.Forms.Label();
    3030      this.splitContainer = new System.Windows.Forms.SplitContainer();
     31      this.setAllButton = new System.Windows.Forms.Button();
    3132      this.splitContainer.Panel1.SuspendLayout();
    3233      this.splitContainer.Panel2.SuspendLayout();
     
    5758      this.inputVariableList.Location = new System.Drawing.Point(2, 16);
    5859      this.inputVariableList.Name = "inputVariableList";
    59       this.inputVariableList.Size = new System.Drawing.Size(221, 454);
     60      this.inputVariableList.Size = new System.Drawing.Size(221, 439);
    6061      this.inputVariableList.TabIndex = 1;
    6162      this.inputVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputVariableList_ItemCheck);
     
    9293      // splitContainer.Panel2
    9394      //
     95      this.splitContainer.Panel2.Controls.Add(this.setAllButton);
    9496      this.splitContainer.Panel2.Controls.Add(this.inputVariablesLabel);
    9597      this.splitContainer.Panel2.Controls.Add(this.inputVariableList);
     
    98100      this.splitContainer.SplitterWidth = 1;
    99101      this.splitContainer.TabIndex = 4;
     102      //
     103      // setAllButton
     104      //
     105      this.setAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     106      this.setAllButton.Location = new System.Drawing.Point(3, 456);
     107      this.setAllButton.Name = "setAllButton";
     108      this.setAllButton.Size = new System.Drawing.Size(91, 23);
     109      this.setAllButton.TabIndex = 4;
     110      this.setAllButton.Text = "Use as default";
     111      this.setAllButton.UseVisualStyleBackColor = true;
     112      this.setAllButton.Click += new System.EventHandler(this.setAllButton_Click);
    100113      //
    101114      // DispatcherView
     
    122135    private System.Windows.Forms.Label inputVariablesLabel;
    123136    private System.Windows.Forms.SplitContainer splitContainer;
     137    private System.Windows.Forms.Button setAllButton;
    124138  }
    125139}
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs

    r2223 r2258  
    7171      inputVariableList.Enabled = true;
    7272    }
     73
     74    private void setAllButton_Click(object sender, EventArgs e) {     
     75      foreach (string targetVar in dispatcher.TargetVariables) {
     76        for (int i = 0; i < inputVariableList.Items.Count; i++) {
     77          if (inputVariableList.GetItemChecked(i)) {
     78            dispatcher.EnableInputVariable(targetVar, (string)inputVariableList.Items[i]);
     79          } else {
     80            dispatcher.DisableInputVariable(targetVar, (string)inputVariableList.Items[i]);
     81          }
     82        }
     83      }
     84    }
    7385  }
    7486}
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r2223 r2258  
    4444
    4545    private TimeSpan StartJobInterval {
    46       get { return TimeSpan.FromMilliseconds(500); }
     46      get { return TimeSpan.FromMilliseconds(3000); }
    4747    }
    4848
     
    5151    }
    5252
    53     private TimeSpan WaitForNewJobsInterval {
    54       get { return TimeSpan.FromSeconds(3); }
    55     }
    56 
    57     public GridExecuter(IDispatcher dispatcher,  IGridServer server, IModelingDatabase databaseService)
     53    public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService)
    5854      : base(dispatcher, databaseService) {
    5955      this.jobManager = new JobManager(server);
     
    6460    protected override void StartJobs() {
    6561      Dictionary<WaitHandle, AsyncGridResult> asyncResults = new Dictionary<WaitHandle, AsyncGridResult>();
     62      // inifinite loop:
     63      // 1. try to dispatch one algo
     64      // 2. when at least one run is dispatched try to get the result
     65      // 3. sleep
    6666      while (true) {
    6767        try {
    68           // start new jobs as long as there are less than MaxActiveJobs
    69           while (asyncResults.Count < MaxActiveJobs) {
    70             Thread.Sleep(StartJobInterval);
     68          // if allowed then try to dispatch another run
     69          if (asyncResults.Count < MaxActiveJobs) {
    7170            // get an execution from the dispatcher and execute in grid via job-manager
    7271            HeuristicLab.Modeling.IAlgorithm algorithm = Dispatcher.GetNextJob();
     
    8584            }
    8685          }
     86          // when there are active runs
    8787          if (asyncResults.Count > 0) {
    8888            WaitHandle[] whArr = asyncResults.Keys.ToArray();
    8989            int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout);
     90            // if the wait didn't timeout, a new result is ready
    9091            if (readyHandleIndex != WaitHandle.WaitTimeout) {
     92              // request the finished run and clean up
    9193              WaitHandle readyHandle = whArr[readyHandleIndex];
     94              AsyncGridResult finishedResult = asyncResults[readyHandle];
     95              asyncResults.Remove(readyHandle);
    9296              HeuristicLab.Modeling.IAlgorithm finishedAlgorithm = null;
    93               AsyncGridResult finishedResult = null;
    9497              lock (activeAlgorithms) {
    95                 finishedResult = asyncResults[readyHandle];
    9698                finishedAlgorithm = activeAlgorithms[finishedResult];
    9799                activeAlgorithms.Remove(finishedResult);
    98                 asyncResults.Remove(readyHandle);
    99100              }
    100101              OnChanged();
     
    105106              }
    106107              catch (Exception badEx) {
    107                 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message+Environment.NewLine+badEx.StackTrace);
     108                HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message + Environment.NewLine + badEx.StackTrace);
    108109              }
    109110            }
    110           } else {
    111             Thread.Sleep(WaitForNewJobsInterval);
    112111          }
     112          // when there are no active runs then sleep until we try to start a new run (to prevent excessive looping)
     113          Thread.Sleep(StartJobInterval);
    113114        }
    114 
    115115        catch (Exception ex) {
    116116          HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message + Environment.NewLine + ex.StackTrace);
    117117        }
    118       }
     118      } // end while(true)
    119119    }
    120120
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs

    r2223 r2258  
    6060        case LearningTask.Regression: {
    6161            var regressionAlgos = algos.Where(a => (a as IClassificationAlgorithm) == null && (a as ITimeSeriesAlgorithm) == null);
    62             selectedAlgorithm = ChooseDeterministic(targetVariable, inputVariables, regressionAlgos) ?? ChooseStochastic(regressionAlgos);
     62            selectedAlgorithm = ChooseDeterministic(targetVariable, inputVariables, regressionAlgos); // ?? ChooseStochastic(regressionAlgos);
    6363            break;
    6464          }
     
    9999
    100100    private void PopulateFinishedRuns() {
    101       //Dictionary<Entity, Entity> processedModels = new Dictionary<Entity, Entity>();
    102       //var datasetBindings = store
    103       //  .Query(
    104       //  "?Dataset <" + Ontology.InstanceOf + "> <" + Ontology.TypeDataSet + "> .", 0, 1)
    105       //  .Select(x => (Entity)x.Get("Dataset"));
    106 
    107       //if (datasetBindings.Count() > 0) {
    108       //  var datasetEntity = datasetBindings.ElementAt(0);
    109 
    110       //  DataSet ds = new DataSet(store, datasetEntity);
    111       //  var result = store
    112       //    .Query(
    113       //    "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." + Environment.NewLine +
    114       //    "?Model <" + Ontology.Name + "> ?AlgoName .",
    115       //    0, 1000)
    116       //    .Select(x => new Resource[] { (Literal)x.Get("TargetVariable"), (Literal)x.Get("AlgoName"), (Entity)x.Get("Model") });
    117 
    118       //  foreach (Resource[] row in result) {
    119       //    Entity model = ((Entity)row[2]);
    120       //    if (!processedModels.ContainsKey(model)) {
    121       //      processedModels.Add(model, model);
    122 
    123       //      string targetVariable = (string)((Literal)row[0]).Value;
    124       //      string algoName = (string)((Literal)row[1]).Value;
    125       //      int targetVariableIndex = ds.Problem.Dataset.GetVariableIndex(targetVariable);
    126 
    127       //      var inputVariableLiterals = store
    128       //        .Query(
    129       //          "<" + model.Uri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." + Environment.NewLine +
    130       //          "?InputVariable <" + Ontology.Name + "> ?Name .",
    131       //          0, 1000)
    132       //        .Select(x => (Literal)x.Get("Name"))
    133       //        .Select(l => (string)l.Value)
    134       //        .Distinct();
    135 
    136       //      List<int> inputVariables = new List<int>();
    137       //      foreach (string variableName in inputVariableLiterals) {
    138       //        int variableIndex = ds.Problem.Dataset.GetVariableIndex(variableName);
    139       //        inputVariables.Add(variableIndex);
    140       //      }
    141       //      if (!AlgorithmFinishedOrDispatched(targetVariableIndex, inputVariables.ToArray(), algoName)) {
    142       //        AddDispatchedRun(targetVariableIndex, inputVariables.ToArray(), algoName);
    143       //      }
    144       //    }
    145       //  }
    146       //}
     101      var dispatchedAlgos = from model in Database.GetAllModels()
     102                            select new {
     103                              TargetVariable = model.TargetVariable.Name,
     104                              Algorithm = model.Algorithm.Name,
     105                              Inputvariables = Database.GetInputVariableResults(model).Select(x => x.Variable.Name).Distinct() };
     106      foreach (var algo in dispatchedAlgos) {
     107        AddDispatchedRun(algo.TargetVariable, algo.Inputvariables, algo.Algorithm);
     108      }
    147109    }
    148110
     
    180142    }
    181143
     144    private void AddDispatchedRun(string targetVariable, IEnumerable<string> inputVariables, string algorithm) {
     145      AddDispatchedRun(
     146        Problem.Dataset.GetVariableIndex(targetVariable),
     147        inputVariables.Select(x => Problem.Dataset.GetVariableIndex(x)).ToArray(),
     148        algorithm);
     149    }
     150
    182151    private void AddDispatchedRun(int targetVariable, int[] inputVariables, string algoName) {
    183152      if (!finishedAndDispatchedRuns.ContainsKey(targetVariable)) {
Note: See TracChangeset for help on using the changeset viewer.