Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/24/12 10:58:22 (13 years ago)
Author:
bburlacu
Message:

#1772: Merged latest trunk changes to SymbolicExpressionTreeEncoding. Deleted unneeded obj folder.

Location:
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4

    • Property svn:ignore set to
      bin
      obj
      HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs
      *.user
      *.vs10x
      Plugin.cs
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs

    r7439 r7514  
    2828  [StorableClass]
    2929  [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")]
    30   public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {
     30  public sealed class ChangeNodeTypeManipulation : TracingSymbolicExpressionTreeManipulator {
    3131    [StorableConstructor]
    3232    private ChangeNodeTypeManipulation(bool deserializing) : base(deserializing) { }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs

    r7439 r7514  
    3131  [StorableClass]
    3232  [Item("OnePointShaker", "Selects a random node with local parameters and manipulates the selected node.")]
    33   public sealed class OnePointShaker : SymbolicExpressionTreeManipulator {
     33  public sealed class OnePointShaker : TracingSymbolicExpressionTreeManipulator {
    3434    private const string ShakingFactorParameterName = "ShakingFactor";
    3535    #region parameter properties
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r7439 r7514  
    3030  [StorableClass]
    3131  [Item("ReplaceBranchManipulation", "Selects a branch of the tree randomly and replaces it with a newly initialized branch (using PTC2).")]
    32   public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator {
     32  public sealed class ReplaceBranchManipulation : TracingSymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator {
    3333    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    3434    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/TracingSymbolicExpressionTreeManipulator.cs

    r7479 r7514  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>;
     29using TraceMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItemList<HeuristicLab.Core.IItem>>;
    2730
    2831namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3437  public abstract class TracingSymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator {
    3538    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    36     private const string GlobalTraceCacheParameterName = "GlobalTraceCache";
    37     private const string GlobalTreeMapParameterName = "GlobalTreeMap";
     39    private const string GlobalTraceMapParameterName = "GlobalTraceMap";
     40    private const string GlobalCloneMapParameterName = "GlobalCloneMap";
    3841
    3942    #region Parameter Properties
     
    4144      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    4245    }
    43     public LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>> GlobalTreeMapParameter {
    44       get {
    45         return (LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>>)Parameters[GlobalTreeMapParameterName];
    46       }
     46    public LookupParameter<CloneMapType> GlobalCloneMapParameter {
     47      get { return (LookupParameter<CloneMapType>)Parameters[GlobalCloneMapParameterName]; }
     48    }
     49    public LookupParameter<TraceMapType> GlobalTraceMapParameter {
     50      get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; }
    4751    }
    4852    #endregion
     
    5256      get { return SymbolicExpressionTreeParameter.ActualValue; }
    5357    }
    54     public ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree> GlobalTreeMap {
    55       get { return GlobalTreeMapParameter.ActualValue; }
     58    public CloneMapType GlobalCloneMap {
     59      get { return GlobalCloneMapParameter.ActualValue; }
     60    }
     61    public TraceMapType GlobalTraceMap {
     62      get { return GlobalTraceMapParameter.ActualValue; }
    5663    }
    5764    #endregion
     
    6370      : base() {
    6471      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
    65       Parameters.Add(new LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>>(GlobalTreeMapParameterName, "A global map keeping track of trees and their clones (made during selection)."));
     72      Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection)."));
     73      Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing tracing info."));
    6674    }
    6775
     
    6977      ISymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
    7078
     79      if (GlobalTraceMap == null) {
     80        var gScope = ExecutionContext.Scope;
     81        while (gScope.Parent != null) gScope = gScope.Parent;
     82        gScope.Variables.Add(new Variable(GlobalTraceMapParameterName, new TraceMapType()));
     83      }
     84      if (GlobalTraceMap.ContainsKey(tree)) {
     85        // tree was affected by crossover before mutation
     86        // if the tree to be manipulated is already a product of crossover (in the current reproduction phase), then there exists no relationship with the original "parent".
     87        // In order to preserve information, a tree clone is created before mutation and added to the trace map.
     88        var clone = (IItem)tree.Clone();
     89        GlobalTraceMap[clone] = GlobalTraceMap[tree];
     90        GlobalTraceMap[tree] = new ItemList<IItem> { clone };
     91      } else {
     92        var original = GlobalCloneMap[tree];
     93        GlobalTraceMap[tree] = new ItemList<IItem> { original };
     94      }
    7195      Manipulate(RandomParameter.ActualValue, tree);
    7296
    73       //AddTraceInfoToGlobalCache();
    74 
    7597      return base.Apply();
    76     }
    77 
    78     private void AddTraceInfoToGlobalCache() {
    79       var globalScope = ExecutionContext.Scope;
    80       while (globalScope.Parent != null) globalScope = globalScope.Parent;
    81 
    82       Variable globalTraceCache;
    83       if (!globalScope.Variables.ContainsKey(GlobalTraceCacheParameterName)) {
    84         globalTraceCache = new Variable(GlobalTraceCacheParameterName, new ItemDictionary<ISymbolicExpressionTree, IItemArray<ISymbolicExpressionTree>>());
    85         globalScope.Variables.Add(globalTraceCache);
    86       } else
    87         globalTraceCache = (Variable)globalScope.Variables[GlobalTraceCacheParameterName];
    88 
    89       var traceCache = (ItemDictionary<ISymbolicExpressionTree, IItemArray<ISymbolicExpressionTree>>)globalTraceCache.Value;
    90 
    91       traceCache.Add(SymbolicExpressionTree, new ItemArray<ISymbolicExpressionTree>(new[] { GlobalTreeMap[SymbolicExpressionTree] }));
    9298    }
    9399
Note: See TracChangeset for help on using the changeset viewer.