Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10837 for branches


Ignore:
Timestamp:
05/11/14 18:29:47 (10 years ago)
Author:
bburlacu
Message:

#1772: Fixed identification of mutation fragments.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r10830 r10837  
    5858        var vClone = new GenealogyGraphNode<T> { Content = clone, Rank = vChild.Rank - 0.5 };
    5959        GenealogyGraph.AddVertex(vClone);
    60         // adjust parent-child(clone) relationship in the graph
    61         var parents = vChild.Parents;
     60        var parents = vChild.Parents; // parents of child become parents of clone
    6261        foreach (var p in parents) {
    6362          foreach (var a in p.OutArcs.Where(a => a.Target == vChild)) {
     
    6665          vClone.AddReverseArc(p);
    6766        }
    68         vClone.InArcs.Last().Data = vChild.InArcs.Last().Data;
    69         vChild.InArcs = new List<IGenealogyGraphArc>();
     67
     68        vClone.InArcs.Last().Data = vChild.InArcs.Last().Data; // fragment of child becomes fragment of clone
     69        vChild.InArcs = new List<IGenealogyGraphArc>(); // child will be connected to clone
    7070        vChild.AddReverseArc(vClone);
    7171        vClone.AddForwardArc(vChild);
     72
     73        // the following step in necessary because some mutation operators change values while the reference stays the same
     74        // so we clone in order to prevent mutations to be "shadowed" in the parent
     75        var parent = vClone.Parents.First();
     76        parent.Content = (T)parent.Content.Clone();
     77        GenealogyGraph[parent.Content] = parent;
     78
    7279      } else { // this needs to be checked
    7380        var vChild = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value };
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs

    r10833 r10837  
    4848        var a = nodesAfter[i];
    4949        var b = nodesBefore[i];
    50         if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue;
     50
     51        bool found = false;
     52        if (comparer.Equals(a, b)) {
     53          int m = 0;
     54          for (int j = 0; j < a.SubtreeCount; ++j) {
     55            if (!AreSimilar(a.GetSubtree(j), b.GetSubtree(j), comparer)) { ++m; }
     56            if (m > 1) {
     57              found = true;
     58              break;
     59            }
     60          }
     61          if (m == 0) {
     62            // everything is similar so we skip the whole subtree
     63            i += a.GetLength();
     64          }
     65          if (!found) continue;
     66        }
    5167        fragment = new Fragment<ISymbolicExpressionTreeNode> {
    5268          Root = a,
     
    6076      return base.Apply();
    6177    }
     78
     79    private bool AreSimilar(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) {
     80      int length = a.GetLength();
     81      return comparer.Equals(a, b) && length.Equals(b.GetLength()) && SymbolicExpressionTreeMatching.Match(a, b, comp) == length;
     82    }
    6283  }
    6384}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs

    r10833 r10837  
    3131
    3232      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
    33       vChild.InArcs.First().Data = vChild.Content.IterateNodesPrefix().ToList();
     33      var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source;
     34      vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList();
    3435
    35       var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source;
    3636      var fragment = (IFragment<ISymbolicExpressionTreeNode>)vClone.InArcs.Last().Data;
    3737      if (fragment != null) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10833 r10837  
    3636            var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
    3737            parent.AddForwardArc(arc);
    38             //            fragmentNode.Content.Index1 = parent.Content.Index1;
    3938          }
    4039          yield return fragmentNode; // no tracing if there are no parents
     
    6261          var fragmentNode = new FragmentNode {
    6362            Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
    64             Rank = node.Rank
     63            Rank = node.Rank,
     64            Quality = node.Quality
    6565          };
    6666          if (parent != null) {
Note: See TracChangeset for help on using the changeset viewer.