Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/17 11:16:42 (8 years ago)
Author:
jkarder
Message:

#2520: worked on persistence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs

    r14549 r14594  
    3333using HeuristicLab.Algorithms.GeneticAlgorithm;
    3434using HeuristicLab.Data;
     35using HeuristicLab.Persistence;
    3536using HeuristicLab.Persistence.Auxiliary;
    3637using HeuristicLab.Persistence.Core;
     
    3940using HeuristicLab.Persistence.Default.Xml;
    4041using HeuristicLab.Persistence.Tests;
     42using HeuristicLab.Problems.TestFunctions;
    4143using HeuristicLab.Tests;
    4244using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    401403
    402404    public string Profile(Func<object> GenerateDataFunc) {
    403       int nrOfRepetitions = 100;
     405      int nrOfRepetitions = 30;
    404406      StringBuilder report = new StringBuilder();
    405407      List<PerformanceData> dataList = new List<PerformanceData>();
     
    411413      report.Append("Performance Report for " + GenerateDataFunc.Method.Name + ": " + Environment.NewLine);
    412414      report.Append(Environment.NewLine);
    413       report.AppendFormat("Avg. old vs. new time for serializing a file: {0} / {1}; Factor: {2}",
     415      report.AppendFormat("Avg. old vs. new time for serializing a file; {0};{1};{2}",
    414416              dataList.Select(x => x.OldSerializingTime).Average(),
    415417              dataList.Select(x => x.NewSerializingTime).Average(),
     
    417419              );
    418420      report.Append(Environment.NewLine);
    419       report.AppendFormat("Avg. old vs. new time for deserializing a file: {0} / {1}; Factor: {2}",
     421      report.AppendFormat("Avg. old vs. new time for deserializing a file; {0};{1};{2}",
    420422              dataList.Select(x => x.OldDeserializingTime).Average(),
    421423              dataList.Select(x => x.NewDeserializingTime).Average(),
     
    423425              );
    424426      report.Append(Environment.NewLine);
    425       report.AppendFormat("Avg. old vs. new file size (in bytes): {0} / {1}; Factor: {2}",
     427      report.AppendFormat("Avg. old vs. new file size (in bytes); {0};{1};{2}",
    426428              dataList.Select(x => x.OldFileSize).Average(),
    427429              dataList.Select(x => x.NewFileSize).Average(),
     
    429431              );
    430432      report.Append(Environment.NewLine);
    431       report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes): {0} / {1}; Factor: {2}",
     433      report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes); {0};{1};{2}",
    432434              dataList.Select(x => x.OldSerializingMemoryConsumed).Average(),
    433435              dataList.Select(x => x.NewSerializingMemoryConsumed).Average(),
     
    435437              );
    436438      report.Append(Environment.NewLine);
    437       report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes): {0} / {1}; Factor: {2}",
     439      report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes); {0};{1};{2}",
    438440              dataList.Select(x => x.OldDeserializingMemoryConsumed).Average(),
    439441              dataList.Select(x => x.NewDeserializingMemoryConsumed).Average(),
     
    944946    #region Old persistence test methods
    945947    [TestMethod]
    946     [TestCategory("Persistence4-EXEPTION")]
     948    [TestCategory("Persistence4")]
    947949    [TestProperty("Time", "short")]
    948950    public void ComplexStorable() {
     
    10341036
    10351037    [TestMethod]
    1036     [TestCategory("Persistence4-EXEPTION")]
     1038    [TestCategory("Persistence4")]
    10371039    [TestProperty("Time", "short")]
    10381040    public void SelfReferences() {
     
    10621064
    10631065    [TestMethod]
    1064     [TestCategory("Persistence4-EXEPTION")]
     1066    [TestCategory("Persistence4")]
    10651067    [TestProperty("Time", "short")]
    10661068    public void ArrayCreation() {
     
    13521354
    13531355    [TestMethod]
    1354     [TestCategory("Persistence4-EXEPTION")]
     1356    [TestCategory("Persistence4")]
    13551357    [TestProperty("Time", "short")]
    13561358    public void InstantiateParentChainReference() {
     
    15161518
    15171519    [TestMethod]
    1518     [TestCategory("Persistence4-EXEPTION")]
     1520    [TestCategory("Persistence4")]
    15191521    [TestProperty("Time", "short")]
    15201522    public void TestStreaming() {
     
    20602062    public class A {
    20612063      [Storable]
    2062       public Tuple<B> B { get; set; }
     2064      public B B { get; set; }
     2065
     2066      [Storable] public int i;
    20632067    }
    20642068    [StorableClass("6075F1E8-948A-4AD8-8F5A-942B777852EC")]
     
    20662070      [Storable]
    20672071      public A A { get; set; }
     2072
     2073      [StorableHook(HookType.AfterDeserialization)]
     2074      void PostDeserializationHook() {
     2075        //Assert.AreEqual(3, A.i);
     2076      }
    20682077    }
    20692078
     
    20732082    public void TestCyclicReferencesWithTuple() {
    20742083      var test = new Func<A>(() => {
    2075         var a = new A { };
     2084        var a = new A { i = 4 };
    20762085        var b = new B { A = a };
    2077         a.B = Tuple.Create(b);
     2086        a.B = b;
    20782087        return a;
    20792088      });
    2080       ProtoBufSerializer serializer = new ProtoBufSerializer();
    2081       serializer.Serialize(test(), tempFile);
    2082       object o = serializer.Deserialize(tempFile);
    2083       A result = (A)o;
    2084 
    2085       Assert.AreEqual(result, result.B.Item1.A);
    2086       Assert.AreSame(result, result.B.Item1.A);
    2087 
    2088       string msg = Profile(test);
    2089       Console.WriteLine(msg);
     2089
     2090      //ProtoBufSerializer serializer = new ProtoBufSerializer();
     2091      //serializer.Serialize(test(), tempFile);
     2092      //object o = serializer.Deserialize(tempFile);
     2093      //A result = (A)o;
     2094
     2095      XmlGenerator.Serialize(test(), tempFile);
     2096      object o = XmlParser.Deserialize(tempFile);
     2097
     2098      string msg = Profile(test);
     2099      Console.WriteLine(msg);
     2100    }
     2101
     2102    [TestMethod]
     2103    [TestCategory("Persistence4")]
     2104    [TestProperty("Time", "short")]
     2105    public void TestGASerializeDeserializeExecute() {
     2106      var test = new Func<GeneticAlgorithm>(() => {
     2107        var ga = new GeneticAlgorithm();
     2108        ga.Problem = new SingleObjectiveTestFunctionProblem();
     2109        ga.MaximumGenerations.Value = 100;
     2110        ga.SetSeedRandomly.Value = false;
     2111        return ga;
     2112      });
     2113      ProtoBufSerializer serializer = new ProtoBufSerializer();
     2114      serializer.Serialize(test(), tempFile);
     2115      object o = serializer.Deserialize(tempFile);
     2116      GeneticAlgorithm result = (GeneticAlgorithm)o;
     2117      SamplesUtils.RunAlgorithm(result);
     2118      GeneticAlgorithm original = test();
     2119      SamplesUtils.RunAlgorithm(original);
     2120      //Assert.AreEqual(original.Results[""], result);
     2121
     2122      //string msg = Profile(test);
     2123      //Console.WriteLine(msg);
     2124    }
     2125    [TestMethod]
     2126    [TestCategory("Persistence4")]
     2127    [TestProperty("Time", "short")]
     2128    public void TestLoadingSamples() {
     2129      var path = @"D:\Dev\HL\branches\PersistenceOverhaul\HeuristicLab.Optimizer\3.3\Documents";
     2130      var serializer = new ProtoBufSerializer();
     2131      foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
     2132        var original = XmlParser.Deserialize(fileName);
     2133        serializer.Serialize(original, fileName + ".proto");
     2134        // var newVersion = serializer.Deserialize(fileName + ".proto");
     2135        var p = Profile(() => original);
     2136        Console.WriteLine(p);
     2137      }
    20902138    }
    20912139  }
Note: See TracChangeset for help on using the changeset viewer.