Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1215)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1216)
@@ -57,5 +57,5 @@
       };
 
-      var dataSetBindings = store.Query("?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> .");
+      var dataSetBindings = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .");
 
       // no datasets => do nothing
@@ -65,38 +65,13 @@
       // find and select all results for this dataset
       var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet");
-      var targetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("TargetVariable");
-      var modelVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("Model");
-      var modelMAPE = new HeuristicLab.CEDMA.DB.Interfaces.Variable("ModelMAPE");
-
-      var query = "<" + dataSetEntity.Uri + "> <" + Ontology.PredicateHasModel.Uri + "> ?Model ." + Environment.NewLine +
-        "?Model <" + Ontology.TargetVariable.Uri + "> ?TargetVariable ." + Environment.NewLine +
-        "?Model <" + Ontology.ValidationMeanAbsolutePercentageError.Uri + "> ?ModelMAPE .";
-
-
-
-      var bindings = store.Query(query);
       DataSet dataSet = new DataSet(store, dataSetEntity);
-      double[] utilization = new double[dataSet.Problem.AllowedTargetVariables.Count];
-      int i = 0;
-      int totalN = bindings.Count();
-      foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables) {
-        var targetVarBindings = bindings.Where(x => (int)((Literal)x.Get("TargetVariable")).Value == targetVariable);
-        if (targetVarBindings.Count() == 0) {
-          utilization[i++] = double.PositiveInfinity;
-        } else {
-          double averageMape = targetVarBindings.Average(x => (double)((Literal)x.Get("ModelMAPE")).Value);
-          double n = targetVarBindings.Count();
-          utilization[i++] = -averageMape + Math.Sqrt(Math.Log(totalN) / n) * 0.1;
-        }
-      }
-      int[] idx = Enumerable.Range(0, utilization.Length).ToArray();
-      Array.Sort(utilization, idx);
-      int nConfigurations = utilization.Length;
-      for (int j = nConfigurations - 1; j > nConfigurations * 0.8; j--) {
-        int targetVariable = dataSet.Problem.AllowedTargetVariables[idx[j]];
-        IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
-        if (engine != null) {
-          QueueJob(new Execution(dataSetEntity, engine, targetVariable));
-        }
+      Random random = new Random();
+      int targetVariable = dataSet.Problem.AllowedInputVariables[random.Next(0, dataSet.Problem.AllowedInputVariables.Count)];
+      string targetVariableName = dataSet.Problem.GetVariableName(targetVariable);
+      Execution exec = CreateExecution(dataSet.Problem, targetVariable);
+      if (exec != null) {
+        exec.DataSetEntity = dataSetEntity;
+        exec.TargetVariable = targetVariableName;
+        QueueJob(exec);
       }
     }
@@ -122,9 +97,9 @@
     }
 
-    private IEngine CreateEngine(Problem problem, int targetVariable) {
+    private Execution CreateExecution(Problem problem, int targetVariable) {
       switch (problem.LearningTask) {
         case LearningTask.Classification: return null;
         case LearningTask.Regression: {
-            return CreateStandardGp(problem, targetVariable).Engine;
+            return CreateStandardGpExecution(problem, targetVariable, 100, 10);
           }
         case LearningTask.TimeSeries: return null;
@@ -134,14 +109,18 @@
     }
 
-    private StandardGP CreateStandardGp(Problem problem, int targetVariable) {
+    private Execution CreateStandardGpExecution(Problem problem, int targetVariable, int maxTreeSize, int maxTreeHeight) {
       ProblemInjector probInjector = new ProblemInjector(problem);
       probInjector.TargetVariable = targetVariable;
       StandardGP sgp = new StandardGP();
       sgp.SetSeedRandomly = true;
-      sgp.MaxGenerations = 300;
-      sgp.PopulationSize = 10000;
+      sgp.MaxGenerations = 2;
+      sgp.PopulationSize = 100;
       sgp.Elites = 1;
       sgp.ProblemInjector = probInjector;
-      return sgp;
+      sgp.MaxTreeHeight = maxTreeHeight;
+      sgp.MaxTreeSize = maxTreeSize;
+      Execution exec = new Execution(sgp.Engine);
+      exec.Description = "StandardGP - Medium Complexity";
+      return exec;
     }
   }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1215)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1216)
@@ -41,12 +41,29 @@
 namespace HeuristicLab.CEDMA.Server {
   public class Executer {
-    private static int MaxActiveJobs {
-      get { return 100; }
-    }
     private Dispatcher dispatcher;
     private JobManager jobManager;
     private IStore store;
+    private Dictionary<WaitHandle, Execution> activeExecutions;
+
+    private TimeSpan StartJobInterval {
+      get { return TimeSpan.FromMilliseconds(500); }
+    }
+
+    private TimeSpan WaitForFinishedJobsTimeout {
+      get { return TimeSpan.FromMilliseconds(100); }
+    }
+
+    private int maxActiveJobs;
+    public int MaxActiveJobs {
+      get { return maxActiveJobs; }
+      set {
+        if (value < 0) throw new ArgumentException("Only positive values are allowed for MaxActiveJobs");
+        maxActiveJobs = value;
+      }
+    }
 
     public Executer(Dispatcher dispatcher, IStore store, string gridUrl) {
+      activeExecutions = new Dictionary<WaitHandle, Execution>();
+      maxActiveJobs = 10;
       this.dispatcher = dispatcher;
       this.store = store;
@@ -61,10 +78,10 @@
     private void StartJobs() {
       List<WaitHandle> wh = new List<WaitHandle>();
-      Dictionary<WaitHandle, AtomicOperation> activeOperations = new Dictionary<WaitHandle,AtomicOperation>();
-      Dictionary<WaitHandle, Execution> activeExecutions = new Dictionary<WaitHandle,Execution>();
+      Dictionary<WaitHandle, AtomicOperation> activeOperations = new Dictionary<WaitHandle, AtomicOperation>();
       while (true) {
         try {
           // start new jobs as long as there are less than MaxActiveJobs 
           while (wh.Count < MaxActiveJobs) {
+            Thread.Sleep(StartJobInterval);
             // get an execution from the dispatcher and execute in grid via job-manager
             Execution execution = dispatcher.GetNextJob();
@@ -74,24 +91,32 @@
               wh.Add(opWh);
               activeOperations.Add(opWh, op);
-              activeExecutions.Add(opWh, execution);
+              lock (activeExecutions) {
+                activeExecutions.Add(opWh, execution);
+              }
             }
           }
           // wait until any job is finished
           WaitHandle[] whArr = wh.ToArray();
-          int readyHandleIndex = WaitHandle.WaitAny(whArr);
-          WaitHandle readyHandle = whArr[readyHandleIndex];
-          AtomicOperation finishedOp = activeOperations[readyHandle];
-          Execution finishedExecution = activeExecutions[readyHandle];
-          wh.Remove(readyHandle);
-          activeExecutions.Remove(readyHandle);
-          activeOperations.Remove(readyHandle);
-          ProcessingEngine finishedEngine = null;
-          try {
-            finishedEngine = jobManager.EndExecuteOperation(finishedOp);
-          } catch (Exception badEx) {
-            Trace.WriteLine("CEDMA Executer: Exception in job execution thread. " + badEx.Message);
-          }
-          if (finishedEngine != null) {
-            StoreResults(finishedExecution, finishedEngine);
+          int readyHandleIndex = WaitHandle.WaitAny(whArr, WaitForFinishedJobsTimeout);
+          if (readyHandleIndex != WaitHandle.WaitTimeout) {
+            WaitHandle readyHandle = whArr[readyHandleIndex];
+            AtomicOperation finishedOp = activeOperations[readyHandle];
+            wh.Remove(readyHandle);
+            Execution finishedExecution = null;
+            lock (activeExecutions) {
+              finishedExecution = activeExecutions[readyHandle];
+              activeExecutions.Remove(readyHandle);
+            }
+            activeOperations.Remove(readyHandle);
+            ProcessingEngine finishedEngine = null;
+            try {
+              finishedEngine = jobManager.EndExecuteOperation(finishedOp);
+            }
+            catch (Exception badEx) {
+              Trace.WriteLine("CEDMA Executer: Exception in job execution thread. " + badEx.Message);
+            }
+            if (finishedEngine != null) {
+              StoreResults(finishedExecution, finishedEngine);
+            }
           }
         }
@@ -115,12 +140,23 @@
       StoreModelAttribute(model, Ontology.TreeHeight, bestModelScope.GetVariableValue<IntData>("TreeHeight", false).Data);
       StoreModelAttribute(model, Ontology.EvaluatedSolutions, bestModelScope.GetVariableValue<IntData>("EvaluatedSolutions", false).Data);
-       
+
       byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
       store.Add(new Statement(model, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
-   }
+    }
 
     private void StoreModelAttribute(Entity model, Entity predicate, object value) {
       store.Add(new Statement(model, predicate, new Literal(value)));
     }
+
+    internal string[] GetJobs() {
+      lock (activeExecutions) {
+        string[] retVal = new string[activeExecutions.Count];
+        int i = 0;
+        foreach (Execution e in activeExecutions.Values) {
+          retVal[i++] = "Target-Variable: "+e.TargetVariable+" "+e.Description;
+        }
+        return retVal;
+      }
+    }
   }
 }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Execution.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Execution.cs	(revision 1215)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Execution.cs	(revision 1216)
@@ -59,8 +59,12 @@
     }
 
-    public Execution(Entity dataSetEntity, IEngine engine, string targetVariable) {
-      this.dataSetEntity = dataSetEntity;
+    private string description;
+    public string Description {
+      get { return description; }
+      set { description = value; }
+    }
+
+    public Execution(IEngine engine) {
       this.engine = engine;
-      this.targetVariable = targetVariable;
     }
   }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 1215)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 1216)
@@ -49,5 +49,5 @@
     private static readonly string rdfFile = AppDomain.CurrentDomain.BaseDirectory + "rdf_store.db3";
     private static readonly string rdfConnectionString = "sqlite:rdf:Data Source=\"" + rdfFile + "\"";
-    
+
     public ServerForm() {
       InitializeComponent();
@@ -56,16 +56,23 @@
       server.Start();
       addressTextBox.Text = server.CedmaServiceUrl;
-      dispatcher = new Dispatcher(store);
-      dispatcher.Start();
     }
 
     private void refreshTimer_Tick(object sender, EventArgs e) {
-      listBox.DataSource = dispatcher.DispatchQueue;
+      listBox.DataSource = executer.GetJobs();
     }
 
     private void connectButton_Click(object sender, EventArgs e) {
+      dispatcher = new Dispatcher(store);
+      dispatcher.Start();
       executer = new Executer(dispatcher, store, gridAddress.Text);
       executer.Start();
+      maxActiveJobsUpDown.Enabled = true;
+      maxActiveJobsUpDown.Value = executer.MaxActiveJobs;
       connectButton.Enabled = false;
+      refreshTimer.Start();
+    }
+
+    private void maxActiveJobsUpDown_ValueChanged(object sender, EventArgs e) {
+      executer.MaxActiveJobs = Convert.ToInt32(maxActiveJobsUpDown.Value);
     }
   }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 1215)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 1216)
@@ -53,4 +53,7 @@
       this.listBox = new System.Windows.Forms.ListBox();
       this.refreshTimer = new System.Windows.Forms.Timer(this.components);
+      this.maxActiveJobsUpDown = new System.Windows.Forms.NumericUpDown();
+      this.label1 = new System.Windows.Forms.Label();
+      ((System.ComponentModel.ISupportInitialize)(this.maxActiveJobsUpDown)).BeginInit();
       this.SuspendLayout();
       // 
@@ -104,14 +107,37 @@
                   | System.Windows.Forms.AnchorStyles.Right)));
       this.listBox.FormattingEnabled = true;
-      this.listBox.Location = new System.Drawing.Point(12, 58);
+      this.listBox.Location = new System.Drawing.Point(12, 84);
       this.listBox.Name = "listBox";
-      this.listBox.Size = new System.Drawing.Size(350, 277);
+      this.listBox.Size = new System.Drawing.Size(350, 251);
       this.listBox.TabIndex = 11;
       // 
       // refreshTimer
       // 
-      this.refreshTimer.Enabled = true;
       this.refreshTimer.Interval = 1000;
       this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick);
+      // 
+      // maxActiveJobsUpDown
+      // 
+      this.maxActiveJobsUpDown.Enabled = false;
+      this.maxActiveJobsUpDown.Location = new System.Drawing.Point(106, 59);
+      this.maxActiveJobsUpDown.Maximum = new decimal(new int[] {
+            64,
+            0,
+            0,
+            0});
+      this.maxActiveJobsUpDown.Name = "maxActiveJobsUpDown";
+      this.maxActiveJobsUpDown.Size = new System.Drawing.Size(120, 20);
+      this.maxActiveJobsUpDown.TabIndex = 12;
+      this.maxActiveJobsUpDown.ValueChanged += new System.EventHandler(this.maxActiveJobsUpDown_ValueChanged);
+      // 
+      // label1
+      // 
+      this.label1.AutoSize = true;
+      this.label1.Enabled = false;
+      this.label1.Location = new System.Drawing.Point(12, 61);
+      this.label1.Name = "label1";
+      this.label1.Size = new System.Drawing.Size(84, 13);
+      this.label1.TabIndex = 13;
+      this.label1.Text = "&Max active jobs:";
       // 
       // ServerForm
@@ -120,4 +146,6 @@
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
       this.ClientSize = new System.Drawing.Size(374, 342);
+      this.Controls.Add(this.label1);
+      this.Controls.Add(this.maxActiveJobsUpDown);
       this.Controls.Add(this.listBox);
       this.Controls.Add(this.connectButton);
@@ -128,4 +156,5 @@
       this.Name = "ServerForm";
       this.Text = "CEDMA Server";
+      ((System.ComponentModel.ISupportInitialize)(this.maxActiveJobsUpDown)).EndInit();
       this.ResumeLayout(false);
       this.PerformLayout();
@@ -142,4 +171,6 @@
     private System.Windows.Forms.ListBox listBox;
     private System.Windows.Forms.Timer refreshTimer;
+    private System.Windows.Forms.NumericUpDown maxActiveJobsUpDown;
+    private System.Windows.Forms.Label label1;
   }
 }
