Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5712


Ignore:
Timestamp:
03/16/11 14:47:32 (13 years ago)
Author:
mkommend
Message:

#1418: Fixed persistence of SymbolicExpressionGrammars.

Location:
branches/DataAnalysis Refactoring
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r5695 r5712  
    5151    [Storable(Name = "AllowedChildSymbols")]
    5252    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
    53       get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(y => GetSymbol(y)))).ToArray(); ; }
     53      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(y => GetSymbol(y)).ToArray())).ToArray(); }
    5454      set { allowedChildSymbols = value.ToDictionary(x => x.Key.Name, x => x.Value.Select(y => y.Name).ToList()); }
    5555    }
     
    5757    [Storable(Name = "AllowedChildSymbolsPerIndex")]
    5858    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex {
    59       get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(y => GetSymbol(y)))).ToArray(); }
     59      get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create<ISymbol, int>(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(y => GetSymbol(y)).ToArray())).ToArray(); }
    6060      set { allowedChildSymbolsPerIndex = value.ToDictionary(x => Tuple.Create(x.Key.Item1.Name, x.Key.Item2), x => x.Value.Select(y => y.Name).ToList()); }
    6161    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/TupleSerializer.cs

    r5698 r5712  
    6363    public IEnumerable<Tag> CreateMetaInfo(object obj) {
    6464      Type t = obj.GetType();
    65       for (int i = 1; i<=t.GetGenericArguments().Length; i++) {
     65      for (int i = 1; i <= t.GetGenericArguments().Length; i++) {
    6666        string name = string.Format("Item{0}", i);
    6767        yield return new Tag(name, t.GetProperty(name).GetValue(obj, null));
     
    7979    static TupleSerializer() {
    8080      foreach (MethodInfo mi in typeof(Tuple).GetMethods(public_static).Where(mi => mi.Name == "Create")) {
    81         CreateMethods[mi.GetGenericArguments().Length-1] = mi;
     81        CreateMethods[mi.GetGenericArguments().Length - 1] = mi;
    8282      }
    8383    }
     
    8585    public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
    8686      var values = metaInfo.Select(t => t.Value).ToArray();
    87       MethodInfo createMethod = CreateMethods[values.Length-1].MakeGenericMethod(values.Select(v => v.GetType()).ToArray());
     87
     88      MethodInfo createMethod = CreateMethods[values.Length - 1].MakeGenericMethod(type.GetGenericArguments());
    8889      return createMethod.Invoke(null, values.ToArray());
    8990    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj

    r5290 r5712  
    142142    <Compile Include="Default\CompositeSerializers\CompactNumberArray2StringSerializer.cs" />
    143143    <Compile Include="Default\CompositeSerializers\ConcreteDictionarySerializer.cs" />
     144    <Compile Include="Default\CompositeSerializers\TupleSerializer.cs" />
    144145    <Compile Include="Default\CompositeSerializers\HashSetSerializer.cs" />
    145146    <Compile Include="Default\CompositeSerializers\DictionarySerializer.cs" />
  • branches/DataAnalysis Refactoring/HeuristicLab.Persistence/3.3/Tests/UseCases.cs

    r5445 r5712  
    12431243    }
    12441244
     1245    [TestMethod]
     1246    public void TupleTest() {
     1247      var t1 = Tuple.Create(1);
     1248      var t2 = Tuple.Create('1', "2");
     1249      var t3 = Tuple.Create(3.0, 3f, 5);
     1250      var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10));
     1251      var tuple = Tuple.Create(t1, t2, t3, t4);
     1252      XmlGenerator.Serialize(tuple, tempFile);
     1253      var newTuple = XmlParser.Deserialize<Tuple<Tuple<int>, Tuple<char, string>, Tuple<double, float, int>, Tuple<Tuple<int, int, int>, Tuple<int, int, int>, Tuple<int, int, int>>>>(tempFile);
     1254      Assert.AreEqual(tuple, newTuple);
     1255    }
     1256
    12451257
    12461258
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs

    r5686 r5712  
    105105    }
    106106    public IValueParameter<IntValue> MaxExpressionLengthParameter {
    107       get { return (IValueParameter<IntValue>)Parameters["MaxExpressionLength"]; }
     107      get { return (IValueParameter<IntValue>)Parameters["MaximumExpressionLength"]; }
    108108    }
    109109    public IValueParameter<IntValue> MaxExpressionDepthParameter {
    110       get { return (IValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
     110      get { return (IValueParameter<IntValue>)Parameters["MaximumExpressionDepth"]; }
    111111    }
    112112    public IValueParameter<IntValue> MaxFunctionDefinitionsParameter {
    113       get { return (IValueParameter<IntValue>)Parameters["MaxFunctionDefinitions"]; }
     113      get { return (IValueParameter<IntValue>)Parameters["MaximumFunctionDefinitions"]; }
    114114    }
    115115    public IValueParameter<IntValue> MaxFunctionArgumentsParameter {
    116       get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }
     116      get { return (ValueParameter<IntValue>)Parameters["MaximumFunctionArguments"]; }
    117117    }
    118118    public IValueParameter<BoolMatrix> WorldParameter {
     
    120120    }
    121121    public IValueParameter<IntValue> MaxTimeStepsParameter {
    122       get { return (IValueParameter<IntValue>)Parameters["MaxTimeSteps"]; }
     122      get { return (IValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
    123123    }
    124124
     
    215215      Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator));
    216216      Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this artificial ant instance.", new DoubleValue(89)));
    217       Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
    218       Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
    219       Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
    220       Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
     217      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
     218      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
     219      Parameters.Add(new ValueParameter<IntValue>("MaximumFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
     220      Parameters.Add(new ValueParameter<IntValue>("MaximumFunctionArguments", "Maximal number of arguments of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
    221221      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
    222222      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
    223       Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
     223      Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
    224224
    225225      creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
Note: See TracChangeset for help on using the changeset viewer.