Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/12 17:17:14 (12 years ago)
Author:
bburlacu
Message:

#1772: Changelog:

  • Removed GetCutIndex method, and corresponding index field in the GenealogyGraphNode.
  • Implemented tracking for mutated fragments.
  • Improved FindMatch method.
  • Added IterateNodesBreadth functionality to symbolic expression trees and nodes.
  • Added check conditions for clearing global tracking structures so that the 2 analyzers are not mutually exclusive anymore.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/TracingSymbolicExpressionTreeManipulator.cs

    r7514 r7792  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2527using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3941    private const string GlobalTraceMapParameterName = "GlobalTraceMap";
    4042    private const string GlobalCloneMapParameterName = "GlobalCloneMap";
     43    private const string GlobalFragmentMapParameterName = "GlobalFragmentMap";
    4144
    4245    #region Parameter Properties
     
    4952    public LookupParameter<TraceMapType> GlobalTraceMapParameter {
    5053      get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; }
     54    }
     55    public LookupParameter<CloneMapType> GlobalFragmentMapParameter {
     56      get { return (LookupParameter<CloneMapType>)Parameters[GlobalFragmentMapParameterName]; }
    5157    }
    5258    #endregion
     
    6268      get { return GlobalTraceMapParameter.ActualValue; }
    6369    }
     70    public CloneMapType GlobalFragmentMap {
     71      get { return GlobalFragmentMapParameter.ActualValue; }
     72    }
    6473    #endregion
    6574
     
    7281      Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection)."));
    7382      Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing tracing info."));
     83      Parameters.Add(new LookupParameter<CloneMapType>(GlobalFragmentMapParameterName, "A global map keeping track of tree fragments received via crossover."));
    7484    }
    7585
     
    7787      ISymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
    7888
    79       if (GlobalTraceMap == null) {
    80         var gScope = ExecutionContext.Scope;
    81         while (gScope.Parent != null) gScope = gScope.Parent;
     89      var gScope = ExecutionContext.Scope;
     90      while (gScope.Parent != null)
     91        gScope = gScope.Parent;
     92
     93      if (GlobalTraceMap == null)
    8294        gScope.Variables.Add(new Variable(GlobalTraceMapParameterName, new TraceMapType()));
    83       }
     95      if (GlobalFragmentMap == null)
     96        gScope.Variables.Add(new Variable(GlobalFragmentMapParameterName, new CloneMapType()));
     97
    8498      if (GlobalTraceMap.ContainsKey(tree)) {
    8599        // 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".
     100        // if the tree to be manipulated is already a product of crossover (in the current reproduction phase),
     101        // then there exists no relationship with the original "parent".
    87102        // In order to preserve information, a tree clone is created before mutation and added to the trace map.
    88103        var clone = (IItem)tree.Clone();
    89104        GlobalTraceMap[clone] = GlobalTraceMap[tree];
    90105        GlobalTraceMap[tree] = new ItemList<IItem> { clone };
     106        GlobalFragmentMap[clone] = GlobalFragmentMap[tree];
    91107      } else {
    92108        var original = GlobalCloneMap[tree];
    93109        GlobalTraceMap[tree] = new ItemList<IItem> { original };
    94110      }
     111      var nodes0 = tree.IterateNodesBreadth().ToList();
    95112      Manipulate(RandomParameter.ActualValue, tree);
     113      var nodes1 = tree.IterateNodesBreadth().ToList();
     114      int i, min = Math.Max(nodes0.Count, nodes1.Count);
     115      for (i = 0; i != min; ++i)
     116        if (nodes0[i] != nodes1[i]) break;
     117      if (i == min) i = 0;
     118      GlobalFragmentMap[tree] = new IntValue(i);
    96119
    97120      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.