Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2053


Ignore:
Timestamp:
06/17/09 13:49:05 (15 years ago)
Author:
gkronber
Message:

Removed lazy loading of problem data and made adds of datasets and models atomic. #656 (CEDMA server should handle only one data set (problem) at a time)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/DataSet.cs

    r2047 r2053  
    4747    public Problem Problem {
    4848      get {
    49         // lazy loading of problem from DB
    50         if (problem == null) {
    51           var persistedData = Store.Query(
    52             "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.SerializedData.Uri + "> ?SerializedData .", 0, 10);
    53           if (persistedData.Count() == 1) {
    54             Literal persistedLiteral = (Literal)persistedData.First().Get("SerializedData");
    55             this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
    56           } else
    57             this.problem = new Problem(); // no entry in the DB => create a new problem
    58         }
    5949        return problem;
    6050      }
     
    7161      name = "Data set";
    7262      activated = false;
     63      problem = new Problem();
    7364    }
    7465
     
    7869      guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length));
    7970      name = guid.ToString();
     71      var persistedData = Store.Query(
     72        "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.SerializedData.Uri + "> ?SerializedData .", 0, 10);
     73      if (persistedData.Count() == 1) {
     74        Literal persistedLiteral = (Literal)persistedData.First().Get("SerializedData");
     75        problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
     76      } else problem = new Problem();
    8077      activated = true;
    8178    }
     
    8380    public void Activate() {
    8481      Entity myEntity = new Entity(Ontology.CedmaNameSpace + Guid);
    85       Store.Add(new Statement(myEntity, Ontology.InstanceOf, Ontology.TypeDataSet));
    86       Store.Add(new Statement(myEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(PersistenceManager.SaveToGZip(problem)))));
    87       Store.Add(new Statement(myEntity, Ontology.Name, new Literal(name)));
     82      Store.AddRange(
     83        new Statement[] {
     84          new Statement(myEntity, Ontology.InstanceOf, Ontology.TypeDataSet),
     85          new Statement(myEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(PersistenceManager.SaveToGZip(problem)))),
     86          new Statement(myEntity, Ontology.Name, new Literal(name))
     87        });
    8888      activated = true;
    8989    }
  • trunk/sources/HeuristicLab.CEDMA.Core/3.3/StoreProxy.cs

    r1858 r2053  
    7676    }
    7777
     78    public void AddRange(ICollection<Statement> statements) {
     79      ExecuteSavely(() => { store.AddRange(statements); return 1.0; });
     80    }
     81
    7882    public ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize) {
    7983      return ExecuteSavely(() => store.Query(query, page, pageSize));
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/3.3/IStore.cs

    r1529 r2053  
    3535
    3636    [OperationContract]
     37    void AddRange(ICollection<Statement> statements);
     38
     39    [OperationContract]
    3740    ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize);
    3841
  • trunk/sources/HeuristicLab.CEDMA.DB/3.3/Store.cs

    r1529 r2053  
    6161    }
    6262
     63    public void AddRange(ICollection<Statement> statements) {
     64      lock (bigLock) {
     65        foreach (Statement s in statements) {
     66          store.Add(Translate(s));
     67        }
     68      }
     69    }
     70
    6371
    6472    public ICollection<VariableBindings> Query(string query, int page, int pageSize) {
    65       MyQueryResultSink resultSink = new MyQueryResultSink();
    66       SemWeb.N3Reader n3Reader = new SemWeb.N3Reader(new StringReader(query));
    67       SemWeb.Query.GraphMatch matcher = new SemWeb.Query.GraphMatch(n3Reader);
    68       matcher.Run(store, resultSink);
    69       return resultSink.Bindings.Skip(page*pageSize).Take(pageSize).ToList();
     73      lock (bigLock) {
     74        MyQueryResultSink resultSink = new MyQueryResultSink();
     75        SemWeb.N3Reader n3Reader = new SemWeb.N3Reader(new StringReader(query));
     76        SemWeb.Query.GraphMatch matcher = new SemWeb.Query.GraphMatch(n3Reader);
     77        matcher.Run(store, resultSink);
     78        return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
     79      }
    7080    }
    7181
    7282    public ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize) {
    73       MyQueryResultSink resultSink = new MyQueryResultSink();
    74       Translate(query).Run(store, resultSink);
    75       return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
     83      lock (bigLock) {
     84        MyQueryResultSink resultSink = new MyQueryResultSink();
     85        Translate(query).Run(store, resultSink);
     86        return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
     87      }
    7688    }
    7789
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs

    r2048 r2053  
    7171    protected void StoreResults(IAlgorithm finishedAlgorithm) {
    7272      Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
    73       store.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel));
    74       StoreEntityAttribute(modelEntity, Ontology.TargetVariable, finishedAlgorithm.Model.TargetVariable);
    75       StoreEntityAttribute(modelEntity, Ontology.Name, finishedAlgorithm.Description);
     73      List<Statement> statements = new List<Statement>();
     74      statements.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel));
     75      statements.Add(new Statement(modelEntity, Ontology.TargetVariable, new Literal(finishedAlgorithm.Model.TargetVariable)));
     76      statements.Add(new Statement(modelEntity, Ontology.Name, new Literal(finishedAlgorithm.Description)));
    7677     
    7778      IModel model = finishedAlgorithm.Model;
    78       StoreEntityAttribute(modelEntity, Ontology.TrainingMeanSquaredError, model.TrainingMeanSquaredError);
    79       StoreEntityAttribute(modelEntity, Ontology.ValidationMeanSquaredError, model.ValidationMeanSquaredError);
    80       StoreEntityAttribute(modelEntity, Ontology.TestMeanSquaredError, model.TestMeanSquaredError);
    81       StoreEntityAttribute(modelEntity, Ontology.TrainingCoefficientOfDetermination, model.TrainingCoefficientOfDetermination);
    82       StoreEntityAttribute(modelEntity, Ontology.ValidationCoefficientOfDetermination, model.ValidationCoefficientOfDetermination);
    83       StoreEntityAttribute(modelEntity, Ontology.TestCoefficientOfDetermination, model.TestCoefficientOfDetermination);
    84       StoreEntityAttribute(modelEntity, Ontology.TrainingVarianceAccountedFor, model.TrainingVarianceAccountedFor);
    85       StoreEntityAttribute(modelEntity, Ontology.ValidationVarianceAccountedFor, model.ValidationVarianceAccountedFor);
    86       StoreEntityAttribute(modelEntity, Ontology.TestVarianceAccountedFor, model.TestVarianceAccountedFor);
    87       StoreEntityAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, model.TrainingMeanAbsolutePercentageError);
    88       StoreEntityAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, model.ValidationMeanAbsolutePercentageError);
    89       StoreEntityAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageError, model.TestMeanAbsolutePercentageError);
    90       StoreEntityAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, model.TrainingMeanAbsolutePercentageOfRangeError);
    91       StoreEntityAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, model.ValidationMeanAbsolutePercentageOfRangeError);
    92       StoreEntityAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, model.TestMeanAbsolutePercentageOfRangeError);
     79      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanSquaredError, new Literal(model.TrainingMeanSquaredError)));
     80      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanSquaredError, new Literal(model.ValidationMeanSquaredError)));
     81      statements.Add(new Statement(modelEntity, Ontology.TestMeanSquaredError, new Literal(model.TestMeanSquaredError)));
     82      statements.Add(new Statement(modelEntity, Ontology.TrainingCoefficientOfDetermination, new Literal(model.TrainingCoefficientOfDetermination)));
     83      statements.Add(new Statement(modelEntity, Ontology.ValidationCoefficientOfDetermination, new Literal(model.ValidationCoefficientOfDetermination)));
     84      statements.Add(new Statement(modelEntity, Ontology.TestCoefficientOfDetermination, new Literal(model.TestCoefficientOfDetermination)));
     85      statements.Add(new Statement(modelEntity, Ontology.TrainingVarianceAccountedFor, new Literal(model.TrainingVarianceAccountedFor)));
     86      statements.Add(new Statement(modelEntity, Ontology.ValidationVarianceAccountedFor, new Literal(model.ValidationVarianceAccountedFor)));
     87      statements.Add(new Statement(modelEntity, Ontology.TestVarianceAccountedFor, new Literal(model.TestVarianceAccountedFor)));
     88      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, new Literal(model.TrainingMeanAbsolutePercentageError)));
     89      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, new Literal(model.ValidationMeanAbsolutePercentageError)));
     90      statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageError, new Literal(model.TestMeanAbsolutePercentageError)));
     91      statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, new Literal(model.TrainingMeanAbsolutePercentageOfRangeError)));
     92      statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, new Literal(model.ValidationMeanAbsolutePercentageOfRangeError)));
     93      statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, new Literal(model.TestMeanAbsolutePercentageOfRangeError)));
    9394
    9495      for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) {
     
    99100
    100101          Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
    101           store.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));
    102           store.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));
    103           StoreEntityAttribute(inputVariableEntity, Ontology.EvaluationImpact, evalImpact);
    104           StoreEntityAttribute(inputVariableEntity, Ontology.QualityImpact, qualImpact);
    105           StoreEntityAttribute(inputVariableEntity, Ontology.Name, variableName);
     102          statements.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));
     103          statements.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));
     104          statements.Add(new Statement(inputVariableEntity, Ontology.EvaluationImpact, new Literal(evalImpact)));
     105          statements.Add(new Statement(inputVariableEntity, Ontology.QualityImpact, new Literal(qualImpact)));
     106          statements.Add(new Statement(inputVariableEntity, Ontology.Name, new Literal(variableName)));
    106107        }
    107108        catch (ArgumentException) {
     
    111112
    112113      byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
    113       store.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));
    114     }
    115 
    116     private void StoreEntityAttribute(Entity entity, Entity predicate, object value) {
    117       store.Add(new Statement(entity, predicate, new Literal(value)));
     114      statements.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));
     115      store.AddRange(statements);
    118116    }
    119117
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r2012 r2053  
    9494            activeOperations.Remove(readyHandle);
    9595            readyHandle.Close();
    96             ProcessingEngine finishedEngine = null;
    9796            try {
    98               finishedEngine = jobManager.EndExecuteOperation(finishedOp);
     97              ProcessingEngine finishedEngine = jobManager.EndExecuteOperation(finishedOp);
     98              StoreResults(finishedAlgorithm);
    9999            }
    100100            catch (Exception badEx) {
    101101              Trace.WriteLine("CEDMA Executer: Exception in job execution thread. " + badEx.Message);
    102             }
    103             if (finishedEngine != null) {
    104               StoreResults(finishedAlgorithm);
    105102            }
    106103          }
Note: See TracChangeset for help on using the changeset viewer.