Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1129)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1130)
@@ -51,36 +51,59 @@
 
     private void FillDispatchQueue() {
-      //Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
-      //var datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
-      //foreach (Statement datasetStatement in datasetStatements) {
-      //  numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
-      //  var modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
-      //  foreach (Statement modelStatement in modelStatements) {
-      //    var modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
-      //    foreach (Statement modelAttrStatement in modelAttributeStatements) {
-      //      var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
-      //         .Where(t => (string)((Literal)t.Property).Value == "TargetVariable")
-      //         .SelectMany(t => store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity)))
-      //         .GroupBy(t => (int)((Literal)t.Property).Value);
-      //      foreach (var targetVariable in targetVariableStatements) {
-      //        if (numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].ContainsKey(targetVariable.Key)) {
-      //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject][targetVariable.Key] = targetVariable.Count();
-      //        } else {
-      //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].Add(targetVariable.Key, targetVariable.Count());
-      //        }
-      //      }
-      //    }
-      //  }
-      //}
-      //foreach (KeyValuePair<Entity, Dictionary<int, int>> dataSetEntry in numberOfModelsOfTargetVariableOfDataSet) {
-      //  DataSet dataSet = new DataSet(store, dataSetEntry.Key);
-      //  foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables)
-      //    if (!dataSetEntry.Value.ContainsKey(targetVariable) || dataSetEntry.Value[targetVariable] < 10) {
-      //      IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
-      //      if (engine != null) {
-      //        QueueJob(new Execution(dataSetEntry.Key, engine, targetVariable));
-      //      }
-      //    }
-      //}
+      // find and select a dataset
+      var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet");
+      var dataSetQuery = new Statement[] {
+        new Statement(dataSetVar, Ontology.PredicateInstanceOf, Ontology.TypeDataSet)
+      };
+
+      var dataSetBindings = store.Query("?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> .");
+
+      // no datasets => do nothing
+      if (dataSetBindings.Count() == 0) return;
+
+      // assume last dataset is the most interesting one
+      // 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 = new Statement[] {
+      //  new Statement(dataSetEntity, Ontology.PredicateHasModel, modelVar),
+      //  new Statement(modelVar, Ontology.TargetVariable, targetVar),
+      //  new Statement(modelVar, Ontology.ValidationMeanAbsolutePercentageError, 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[j];
+        IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
+        if (engine != null) {
+          QueueJob(new Execution(dataSetEntity, engine, targetVariable));
+        }
+      }
     }
 
@@ -90,5 +113,7 @@
 
     public Execution GetNextJob() {
-      if (dispatchQueue.Count == 0) FillDispatchQueue();
+      if (dispatchQueue.Count == 0) {
+        FillDispatchQueue();
+      }
       if (dispatchQueue.Count > 0) {
         Execution next = dispatchQueue[0];
@@ -120,6 +145,6 @@
       StandardGP sgp = new StandardGP();
       sgp.SetSeedRandomly = true;
-      sgp.MaxGenerations = 100;
-      sgp.PopulationSize = 1000;
+      sgp.MaxGenerations = 300;
+      sgp.PopulationSize = 10000;
       sgp.Elites = 1;
       sgp.ProblemInjector = probInjector;
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1129)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1130)
@@ -103,28 +103,23 @@
 
     private void StoreResults(Execution finishedExecution, ProcessingEngine finishedEngine) {
-      Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
-      store.Add(new Statement(modelEntity, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree));
-      store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, modelEntity));
-      StoreModelAttribute(modelEntity, "TargetVariable", finishedExecution.TargetVariable);
+      Entity model = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
+      store.Add(new Statement(model, Ontology.PredicateInstanceOf, Ontology.TypeGeneticProgrammingFunctionTree));
+      store.Add(new Statement(finishedExecution.DataSetEntity, Ontology.PredicateHasModel, model));
+      StoreModelAttribute(model, Ontology.TargetVariable, finishedExecution.TargetVariable);
       Scope bestModelScope = finishedEngine.GlobalScope.GetVariableValue<Scope>("BestValidationSolution", false);
-      StoreModelAttribute(modelEntity, "TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
-      StoreModelAttribute(modelEntity, "ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
-      StoreModelAttribute(modelEntity, "TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
-      StoreModelAttribute(modelEntity, "ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
-      StoreModelAttribute(modelEntity, "TreeSize", bestModelScope.GetVariableValue<IntData>("TreeSize", false).Data);
-      StoreModelAttribute(modelEntity, "TreeHeight", bestModelScope.GetVariableValue<IntData>("TreeHeight", false).Data);
-      StoreModelAttribute(modelEntity, "EvaluatedSolutions", bestModelScope.GetVariableValue<IntData>("EvaluatedSolutions", false).Data);
+      StoreModelAttribute(model, Ontology.TrainingMeanSquaredError, bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
+      StoreModelAttribute(model, Ontology.ValidationMeanSquaredError, bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
+      StoreModelAttribute(model, Ontology.TrainingMeanAbsolutePercentageError, bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
+      StoreModelAttribute(model, Ontology.ValidationMeanAbsolutePercentageError, bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
+      StoreModelAttribute(model, Ontology.TreeSize, bestModelScope.GetVariableValue<IntData>("TreeSize", false).Data);
+      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(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
+      store.Add(new Statement(model, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
+   }
 
-    }
-
-    private void StoreModelAttribute(Entity model, string name, object value) {
-      Entity attr = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
-      store.Add(new Statement(model, Ontology.PredicateModelAttribute, attr));
-      store.Add(new Statement(attr, Ontology.PredicateModelAttributeName, new Literal(name)));
-      store.Add(new Statement(attr, Ontology.PredicateModelAttributeValue, new Literal(value)));
-      store.Add(new Statement(attr, Ontology.PredicateModelAttributeType, Ontology.TypeOrdinalAttribute));
+    private void StoreModelAttribute(Entity model, Entity predicate, object value) {
+      store.Add(new Statement(model, predicate, new Literal(value)));
     }
   }
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs	(revision 1129)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs	(revision 1130)
@@ -75,6 +75,4 @@
         binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
         binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
-        binding.Security.Mode = SecurityMode.None;
-
         host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
         host.Open();
