Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/13/14 13:03:24 (10 years ago)
Author:
bburlacu
Message:

#1772: HeuristicLab.Problems.DataAnalysis.Symbolic:

  • Merged trunk changes (SymbolicExpressionImporter)
  • Added Passthrough symbol (does not perform an operation, just transfers the input), adjusted interpreter and opcodes accordingly
  • Added diversity preserving crossover
  • Replaced IDistanceCalculator interface with ISymbolicDataAnalysisExpressionSimilarityCalculator and adjusted similarity calculators
  • Refactored tracing, moved functionality to the TraceCalculator (when this is complete the old code will be removed)
Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4

    • Property svn:ignore
      •  

        old new  
        55TreeDistance
        66SymbolicDataAnalysisExpressionTreeMatching.cs
         7Importer
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r11388 r11458  
    4848      var parent = parentNode; // current parent
    4949
     50      IGenealogyGraphNode<ISymbolicExpressionTree> n1 = null;
     51      int i1 = -1;
     52
    5053      while (true) {
     54        if (node == n1 && index == i1)
     55          throw new InvalidOperationException("Infinite loop detected");
     56
     57        n1 = node;
     58        i1 = index;
     59
    5160        if (!node.Parents.Any()) {
    5261          // no tracing if there are no parents, return a fragment node representing the current trace
    53           var fragmentNode = new FragmentNode(node) { SubtreeIndex = index };
     62          var fragmentNode = new FragmentNode(node.Data) { SubtreeIndex = index };
    5463          if (parent != null) {
    55             var arc = new Arc(parent, fragmentNode);
     64            var arc = new GenealogyGraphArc(parent, fragmentNode);
    5665            parent.AddArc(arc);
    5766            fragmentNode.AddArc(arc);
     
    8291        if (parents.Count == 1) {
    8392          // we are tracing a mutation operation
    84           var fragmentNode = new FragmentNode(node) {
     93          var fragmentNode = new FragmentNode(node.Data) {
    8594            SubtreeIndex = index,
    8695            FragmentIndex = fragment.Index1
     
    91100            fragmentNode.AddArc(arc);
    92101          }
     102          if (node == parents[0])
     103            throw new InvalidOperationException("Node == parents[0]");
     104
    93105          node = parents[0];
    94           if (subtreeIndex == fragment.Index1) {
     106
     107          if (index == fragment.Index1) {
    95108            // index stays the same
    96           } else if (fragment.Index1 < subtreeIndex) {
    97             if (subtreeIndex < fragment.Index1 + fragmentLength) {
     109          } else if (fragment.Index1 < index) {
     110            if (index < fragment.Index1 + fragmentLength) {
    98111              // in the case of mutation, the fragment could have been introduced via a node replacement
    99112              // there is no guarantee the subtree exists above this level, therefore the index is set to the fragment index
     
    103116              index += node.Data.NodeAt(fragment.Index1).GetLength() - fragmentLength;
    104117            }
    105           } else if (subtreeIndex < fragment.Index1) {
    106             if (fragment.Index1 < subtreeIndex + subtreeLength) {
     118          } else if (index < fragment.Index1) {
     119            if (fragment.Index1 < index + subtreeLength) {
    107120              // subtree contains fragment
    108121              index = fragment.Index1;
     
    111124            }
    112125          }
    113 
    114126          yield return fragmentNode;
    115           var up = Trace(node, index, fragmentNode); // force immediate query execution
     127          if (node == graphNode && index == subtreeIndex)
     128            throw new ArgumentException("Infinite recursion detected");
     129          var up = Trace(node, index, fragmentNode).ToList(); // force immediate query execution
    116130          foreach (var v in up) { yield return v; }
    117131          break;
     
    121135        #region crossover tracing
    122136        if (parents.Count == 2) {
     137          if (node == parents[0])
     138            throw new InvalidOperationException("Node == parents[0]");
     139          if (node == parents[1])
     140            throw new InvalidOperationException("Node == parents[1]");
    123141          // we are tracing a crossover operation
    124142          if (fragment.Index1 == index) {
     
    143161            if (fragment.Index1 < index + subtreeLength) {
    144162              // subtree contains fragment => branching point in the fragment graph
    145               var fragmentNode = new FragmentNode(node) {
     163              var fragmentNode = new FragmentNode(node.Data) {
    146164                SubtreeIndex = index,
    147165                FragmentIndex = fragment.Index1
    148166              };
    149167              if (parent != null) {
    150                 var arc = new Arc(parent, fragmentNode);
     168                var arc = new GenealogyGraphArc(parent, fragmentNode);
    151169                parent.AddArc(arc);
    152170                fragmentNode.AddArc(arc);
     
    176194      return writer.ToString();
    177195    }
    178     #region some helper methods for shortening the tracing code
    179     private static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) {
    180       return NodeAt(tree.Root, position);
    181     }
    182     private static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTreeNode root, int position) {
    183       return root.IterateNodesPrefix().ElementAt(position);
    184     }
    185     #endregion
    186196  }
    187197}
Note: See TracChangeset for help on using the changeset viewer.