Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11858


Ignore:
Timestamp:
02/02/15 13:58:40 (10 years ago)
Author:
bburlacu
Message:

#1772: Micro optimization inside the TraceCalculator and inside the GenealogyGraphNode (Children and Parents properties), resulting in maybe 25% speed gain. Corrected item name for the BeforeCrossoverOperator, very minor refactoring inside the BeforeManipulatorOperator. Updated project file.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs

    r11852 r11858  
    6060
    6161    public IEnumerable<IGenealogyGraphNode> Parents {
    62       get { return InArcs.Select(a => a.Source); }
     62      get { return base.InArcs.Select(x => (IGenealogyGraphNode)x.Source); }
    6363    }
    6464
    6565    public IEnumerable<IGenealogyGraphNode> Children {
    66       get { return OutArcs.Select(a => a.Target); }
     66      get { return base.OutArcs.Select(x => (IGenealogyGraphNode)x.Target); }
    6767    }
    6868
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs

    r11390 r11858  
    3030namespace HeuristicLab.EvolutionTracking {
    3131  [StorableClass]
    32   [Item("AfterCrossoverOperator", "A generic operator that can record genealogical relationships between crossover parents and children.")]
     32  [Item("BeforeCrossoverOperator", "A generic operator that can record genealogical relationships between crossover parents and children.")]
    3333  public class BeforeCrossoverOperator<T> : EvolutionTrackingOperator<T>, ICrossoverOperator<T> where T : class,IItem {
    3434    private const string ParentsParameterName = "Parents";
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r11387 r11858  
    5353    public override IOperation Apply() {
    5454      // since mutation always takes place after crossover, the vertex for the current child is already in the tree
    55       var childVertex = GenealogyGraph.GetByContent(ChildParameter.ActualValue);
    56       var clonedVertex = (IGenealogyGraphNode<T>)childVertex.Clone();
    57       clonedVertex.Rank = childVertex.Rank - 0.5;
    58       GenealogyGraph.AddVertex(clonedVertex);
     55      var vChild = GenealogyGraph.GetByContent(ChildParameter.ActualValue);
     56      var vClone = (IGenealogyGraphNode<T>)vChild.Clone();
     57      vClone.Rank = vChild.Rank - 0.5;
     58      GenealogyGraph.AddVertex(vClone);
    5959
    60       var arcs = childVertex.InArcs.ToList();
     60      var arcs = vChild.InArcs.ToList();
    6161      foreach (var arc in arcs) {
    6262        var p = arc.Source;
    6363        GenealogyGraph.RemoveArc(arc);
    64         GenealogyGraph.AddArc(new GenealogyGraphArc(p, clonedVertex));
     64        GenealogyGraph.AddArc(new GenealogyGraphArc(p, vClone));
    6565      }
    6666      // by convention, the arc connecting child with parent (non-root parent in case of crossover)
    6767      // holds fragment data when applicable. the following line of code preserves this data
    6868      // the graph arcs are now connecting parent (rank n) --> clone (rank n+0.5) --> child (rank n+1)
    69       clonedVertex.InArcs.Last().Data = arcs.Last().Data;
    70       GenealogyGraph.AddArc(new GenealogyGraphArc(clonedVertex, childVertex));
     69      vClone.InArcs.Last().Data = arcs.Last().Data;
     70      GenealogyGraph.AddArc(new GenealogyGraphArc(vClone, vChild));
    7171
    7272      return base.Apply();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11638 r11858  
    326326    <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs" />
    327327    <Compile Include="Tracking\SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs" />
    328     <Compile Include="Tracking\SymbolicDataAnalysisExpressionTracing.cs" />
    329328    <None Include="HeuristicLab.snk" />
    330329    <None Include="Plugin.cs.frame" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r11855 r11858  
    100100      while (g.Parents.Any()) {
    101101        Debug.Assert(si < g.Data.Length);
    102         var parents = g.Parents.ToList();
    103         var fragment = (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data;
     102        var inArcs = (List<IArc>)((IVertex)g).InArcs;
     103        var fragment = (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data;
    104104        if (fragment == null) {
    105105          // TODO: think about what the correct behavior should be here (seems good so far)
    106106          // the node is either an elite node or (in rare cases) no fragment was transferred
    107           g = parents[0];
     107          g = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
    108108          continue;
    109109        }
     
    114114
    115115        #region trace crossover
    116         if (parents.Count == 2) {
     116        if (inArcs.Count == 2) {
     117          var parent0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
     118          var parent1 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[1].Source;
    117119          if (fi == si) {
    118             g = parents[1];
     120            g = parent1;
    119121            si = fragment.Index2;
    120122            continue;
     
    123125            if (fi + fl > si) {
    124126              // fragment contains subtree
    125               g = parents[1];
     127              g = parent1;
    126128              si += fragment.Index2 - fi;
    127129            } else {
    128130              // fragment distinct from subtree
    129               g = parents[0];
     131              g = parent0;
    130132              si += NodeAt(g.Data, fi).GetLength() - fl;
    131133            }
     
    136138              // subtree contains fragment => branching point in the fragment graph
    137139              var n = GetTraceNode(g, si, fi);
    138               TraceRecursive(parents[0], si, n);
    139               TraceRecursive(parents[1], fragment.Index2, n);
     140              TraceRecursive(parent0, si, n);
     141              TraceRecursive(parent1, fragment.Index2, n);
    140142              break;
    141143            } else {
    142144              // subtree and fragment are distinct.
    143               g = parents[0];
     145              g = parent0;
    144146              continue;
    145147            }
     
    150152        // mutation is handled in a simple way: we branch every time there is an overlap between the subtree and the fragment
    151153        // (since mutation effects can be quite unpredictable: replace branch, change node, shake tree, etc)
    152         if (parents.Count == 1) {
     154        if (inArcs.Count == 1) {
     155          var parent0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source;
    153156          Debug.Assert(fragment.Index1 == fragment.Index2);
    154157          // check if the subtree and the fragment overlap => branch out
     
    156159            var n = GetTraceNode(g, si, fi);
    157160            int i = si < fi ? si : fi;
    158             TraceRecursive(parents[0], i, n);
     161            TraceRecursive(parent0, i, n);
    159162            break;
    160163          } else {
    161164            // if they don't overlap, go up
    162             g = parents[0];
     165            g = parent0;
    163166            if (fi < si)
    164167              si += NodeAt(g.Data, fi).GetLength() - fl;
     
    212215    /// <param name="last">The last added node in the trace graph</param>
    213216    private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last) {
    214       IFragment<ISymbolicExpressionTreeNode> fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data : null;
     217      var inArcs = (List<IArc>)((IVertex)g).InArcs;
     218      var fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data : null;
    215219      int fi = fragment == null ? 0 : fragment.Index1; // fragment index
    216220      var n = GetTraceNode(g, si, fi); // will append n to the trace graph if it does not exist
Note: See TracChangeset for help on using the changeset viewer.