Ignore:
Timestamp:
01/14/09 20:48:04 (12 years ago)
Author:
gkronber
Message:
  • re-enabled security for all WCF services;
  • debugged rdf queries
  • added tracing for WCF services
  • implemented simple version of quality based dispatching
  • extended ontology to include a number of predefined model-attributes (quality, size, evaluated solutions etc.)

ticket: #419 (Refactor CEDMA plugins)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs

    r1129 r1130  
    5151
    5252    private void FillDispatchQueue() {
    53       //Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
    54       //var datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
    55       //foreach (Statement datasetStatement in datasetStatements) {
    56       //  numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
    57       //  var modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
    58       //  foreach (Statement modelStatement in modelStatements) {
    59       //    var modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
    60       //    foreach (Statement modelAttrStatement in modelAttributeStatements) {
    61       //      var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
    62       //         .Where(t => (string)((Literal)t.Property).Value == "TargetVariable")
    63       //         .SelectMany(t => store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity)))
    64       //         .GroupBy(t => (int)((Literal)t.Property).Value);
    65       //      foreach (var targetVariable in targetVariableStatements) {
    66       //        if (numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].ContainsKey(targetVariable.Key)) {
    67       //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject][targetVariable.Key] = targetVariable.Count();
    68       //        } else {
    69       //          numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].Add(targetVariable.Key, targetVariable.Count());
    70       //        }
    71       //      }
    72       //    }
    73       //  }
    74       //}
    75       //foreach (KeyValuePair<Entity, Dictionary<int, int>> dataSetEntry in numberOfModelsOfTargetVariableOfDataSet) {
    76       //  DataSet dataSet = new DataSet(store, dataSetEntry.Key);
    77       //  foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables)
    78       //    if (!dataSetEntry.Value.ContainsKey(targetVariable) || dataSetEntry.Value[targetVariable] < 10) {
    79       //      IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
    80       //      if (engine != null) {
    81       //        QueueJob(new Execution(dataSetEntry.Key, engine, targetVariable));
    82       //      }
    83       //    }
    84       //}
     53      // find and select a dataset
     54      var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet");
     55      var dataSetQuery = new Statement[] {
     56        new Statement(dataSetVar, Ontology.PredicateInstanceOf, Ontology.TypeDataSet)
     57      };
     58
     59      var dataSetBindings = store.Query("?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> .");
     60
     61      // no datasets => do nothing
     62      if (dataSetBindings.Count() == 0) return;
     63
     64      // assume last dataset is the most interesting one
     65      // find and select all results for this dataset
     66      var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet");
     67      var targetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("TargetVariable");
     68      var modelVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("Model");
     69      var modelMAPE = new HeuristicLab.CEDMA.DB.Interfaces.Variable("ModelMAPE");
     70
     71      //var query = new Statement[] {
     72      //  new Statement(dataSetEntity, Ontology.PredicateHasModel, modelVar),
     73      //  new Statement(modelVar, Ontology.TargetVariable, targetVar),
     74      //  new Statement(modelVar, Ontology.ValidationMeanAbsolutePercentageError, modelMAPE)
     75      //};
     76
     77      var query = "<" + dataSetEntity.Uri + "> <" + Ontology.PredicateHasModel.Uri + "> ?Model ." + Environment.NewLine +
     78        "?Model <" + Ontology.TargetVariable.Uri + "> ?TargetVariable ." + Environment.NewLine +
     79        "?Model <" + Ontology.ValidationMeanAbsolutePercentageError.Uri + "> ?ModelMAPE .";
     80
     81
     82
     83      var bindings = store.Query(query);
     84      DataSet dataSet = new DataSet(store, dataSetEntity);
     85      double[] utilization = new double[dataSet.Problem.AllowedTargetVariables.Count];
     86      int i = 0;
     87      int totalN = bindings.Count();
     88      foreach (int targetVariable in dataSet.Problem.AllowedTargetVariables) {
     89        var targetVarBindings = bindings.Where(x => (int)((Literal)x.Get("TargetVariable")).Value == targetVariable);
     90        if (targetVarBindings.Count() == 0) {
     91          utilization[i++] = double.PositiveInfinity;
     92        } else {
     93          double averageMape = targetVarBindings.Average(x => (double)((Literal)x.Get("ModelMAPE")).Value);
     94          double n = targetVarBindings.Count();
     95          utilization[i++] = -averageMape + Math.Sqrt(Math.Log(totalN) / n) * 0.1;
     96        }
     97      }
     98      int[] idx = Enumerable.Range(0, utilization.Length).ToArray();
     99      Array.Sort(utilization, idx);
     100      int nConfigurations = utilization.Length;
     101      for (int j = nConfigurations - 1; j > nConfigurations * 0.8; j--) {
     102        int targetVariable = dataSet.Problem.AllowedTargetVariables[j];
     103        IEngine engine = CreateEngine(dataSet.Problem, targetVariable);
     104        if (engine != null) {
     105          QueueJob(new Execution(dataSetEntity, engine, targetVariable));
     106        }
     107      }
    85108    }
    86109
     
    90113
    91114    public Execution GetNextJob() {
    92       if (dispatchQueue.Count == 0) FillDispatchQueue();
     115      if (dispatchQueue.Count == 0) {
     116        FillDispatchQueue();
     117      }
    93118      if (dispatchQueue.Count > 0) {
    94119        Execution next = dispatchQueue[0];
     
    120145      StandardGP sgp = new StandardGP();
    121146      sgp.SetSeedRandomly = true;
    122       sgp.MaxGenerations = 100;
    123       sgp.PopulationSize = 1000;
     147      sgp.MaxGenerations = 300;
     148      sgp.PopulationSize = 10000;
    124149      sgp.Elites = 1;
    125150      sgp.ProblemInjector = probInjector;
Note: See TracChangeset for help on using the changeset viewer.