Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/14 17:15:33 (11 years ago)
Author:
bburlacu
Message:

#1772: Simplified genealogy graph and fragment graph creation:

  • the genealogy graph now has a 1-1 mapping between content and vertices (as opposed to 1-n as it was previously, to account for elites); this required changes to the directed graph implementation
  • the fragment graph only contains bifurcation points (where the subtree contains the fragment so tracing must be done both ways (in the root parent AND in the other parent). in the other cases, tracing is restarted from the parent genealogy graph node.
Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
Files:
5 edited

Legend:

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

    r10752 r10755  
    1010    public override IOperation Apply() {
    1111      var child = ChildParameter.ActualValue;
    12       var childVertex = (IGenealogyGraphNode)GenealogyGraph[child].Last();
     12      var childVertex = (IGenealogyGraphNode)GenealogyGraph[child];
    1313      var arcs = childVertex.InArcs.ToList();
    1414      var nodes0 = (List<ISymbolicExpressionTreeNode>)arcs[0].Data;
     
    2020        fragment = new Fragment<ISymbolicExpressionTreeNode> {
    2121          Root = childNodes[i],
    22           Index = i,
     22          Index1 = i,
    2323        };
    24         fragment.OldIndex = nodes1.IndexOf(fragment.Root);
     24        fragment.Index2 = nodes1.IndexOf(fragment.Root);
    2525        break;
    2626      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs

    r10677 r10755  
    77
    88namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    9   public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : BeforeManipulatorOperator<ISymbolicExpressionTree> {
     9  public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : AfterManipulatorOperator<ISymbolicExpressionTree> {
    1010    private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer;
    1111
     
    1919
    2020    public override IOperation Apply() {
    21       var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue].First();
     21      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
    2222      var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data;
    23       var nodesAfter = ChildParameter.ActualValue.IterateNodesBreadth().ToList();
     23      var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList();
    2424      IFragment<ISymbolicExpressionTreeNode> fragment = null;
    2525
    2626      for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) {
    27         if (comparer.Equals(nodesAfter[i], nodesBefore[i])) continue;
     27        var a = nodesAfter[i];
     28        var b = nodesBefore[i];
     29        if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue;
    2830        fragment = new Fragment<ISymbolicExpressionTreeNode> {
    29           Root = nodesAfter[i],
    30           Index = i
     31          Root = a,
     32          Index1 = i
    3133        };
    3234      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs

    r10752 r10755  
    3131      var result = base.Apply(); // the base operator will add the child to the graph before the actual crossover operation takes place
    3232      var parents = ParentsParameter.ActualValue.ToList();
    33       var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[parents[0]].Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)
     33      var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[parents[0]]; // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)
    3434      var arcs = childVertex.InArcs.ToList();
    3535
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs

    r10677 r10755  
    77  public class SymbolicDataAnalysisExpressionBeforeManipulatorOperator : BeforeManipulatorOperator<ISymbolicExpressionTree> {
    88    public override IOperation Apply() {
    9       var result = base.Apply();
     9      var result = base.Apply(); // add the vertex in the genealogy graph
    1010
    11       var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue].Last();
    12       vChild.InArcs.First().Data = vChild.Content.IterateNodesBreadth().ToList();
     11      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
     12      vChild.InArcs.First().Data = vChild.Content.IterateNodesPrefix().ToList();
    1313
    1414      return result;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10752 r10755  
    11
     2using System;
    23using System.Collections.Generic;
    34using System.IO;
     
    2425      var index = subtreeIndex; // current index
    2526      var parent = parentNode; // current parent
     27
    2628      while (true) {
     29        if (!node.Parents.Any()) {
     30          var fragmentNode = new FragmentNode {
     31            Content = new Fragment<ISymbolicExpressionTreeNode> { Root = node.Content.NodeAt(index) },
     32            Rank = node.Rank
     33          };
     34          if (parent != null) {
     35            var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
     36            parent.AddForwardArc(arc);
     37            //            fragmentNode.Content.Index1 = parent.Content.Index1;
     38          }
     39          yield return fragmentNode; // no tracing if there are no parents
     40          break;
     41        }
     42
     43        if (node.IsElite) {
     44          node = node.Parents.First();
     45          continue;
     46        } // skip elite, go up the graph to original individual
     47
    2748        var tree = node.Content;
    2849        var subtree = tree.NodeAt(index);
    2950        var subtreeLength = subtree.GetLength();
    30         var fragmentNode = new FragmentNode {
    31           Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
    32           Rank = node.Rank
    33         };
    34         if (parent != null) {
    35           var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
    36           parent.AddForwardArc(arc);
    37         }
    38         parent = fragmentNode;
    39         yield return fragmentNode;
    40         if (!node.Parents.Any()) break;
    41         if (node.IsElite) {
    42           node = node.Parents.First();
    43           continue;
    44         }
     51
    4552        var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;
    4653        if (fragment == null) break;
    4754        var fragmentLength = fragment.Root.GetLength();
    48         if (fragment.Index == index) {
     55
     56        if (fragment.Index1 == index) {
    4957          node = node.Parents.Last(); // take second parent which contains the fragment
    50           index = fragment.OldIndex;
    51         } else if (fragment.Index < index) {
    52           if (fragment.Index + fragmentLength > index) { // fragment contains subtree
    53             node = node.Parents.Last(); // take second parent
    54             index += fragment.OldIndex - fragment.Index;
    55           } else { // fragment distinct from subtree
     58          index = fragment.Index2;
     59        } else if (fragment.Index1 < index) {
     60          if (fragment.Index1 + fragmentLength > index) {
     61            node = node.Parents.Last(); // fragment contains subtree, take second parent
     62            index += fragment.Index2 - fragment.Index1; // the subtree has the same index relative to the fragment
     63          } else {
     64            // fragment distinct from subtree
    5665            node = node.Parents.First(); // take first parent which contains the subtree
    57             index += node.Content.NodeAt(fragment.Index).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes
     66            index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes
    5867          }
    59         } else if (fragment.Index > index) {
    60           if (fragment.Index < index + subtreeLength) { // subtree contains fragment => bifurcation point in the fragment graph
    61             fragmentNode.Content.Index = fragment.Index - index;
     68        } else if (fragment.Index1 > index) {
     69          if (fragment.Index1 < index + subtreeLength) {
     70            // subtree contains fragment => bifurcation point in the fragment graph
     71            var fragmentNode = new FragmentNode {
     72              Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
     73              Rank = node.Rank
     74            };
     75            if (parent != null) {
     76              var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
     77              parent.AddForwardArc(arc);
     78            }
     79            fragmentNode.Content.Index1 = fragment.Index1 - index;
     80            yield return fragmentNode;
     81
    6282            var left = Trace(node.Parents.First(), index, fragmentNode); // trace subtree
    63             var right = Trace(node.Parents.Last(), fragment.OldIndex, fragmentNode); // trace fragment
    64             foreach (var v in left.Concat(right)) { yield return v; }
     83
     84            if (node.Parents.Last().Content.NodeAt(fragment.Index2).GetLength() != fragmentLength) {
     85              throw new Exception("Fragment lengths should match!");
     86            }
     87            var right = Trace(node.Parents.Last(), fragment.Index2, fragmentNode); // trace fragment
     88            foreach (var v in left.Concat(right)) {
     89              yield return v;
     90            }
    6591            break;
     92          } else {
     93            node = node.Parents.First(); // fragment distinct from subtree: update node, index remains unchanged
    6694          }
    67           node = node.Parents.First(); // fragment distinct from subtree: update node, index remains unchanged
    6895        }
    6996      }
Note: See TracChangeset for help on using the changeset viewer.