Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/08/14 17:26:32 (11 years ago)
Author:
bburlacu
Message:

#1772: Added default font, pen, and brush for the graphical components (the idea is to save memory by sharing default pens and brushes - not allocating new ones all the time), added support for tracing mutation operations

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
Files:
4 edited

Legend:

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

    r10755 r10827  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    2546        break;
    2647      }
    27       // if the fragment is null then it means crossover did not do anything
    28       //      if (fragment == null) throw new Exception("Could not determine fragment!");
     48      //
     49      //      if (fragment == null) {
     50      //        throw new Exception("SymbolicDataAnalysisExpressionAfterCrossoverOperator: Could not identify fragment");
     51      //      }
    2952
    3053      arcs[0].Data = null;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs

    r10822 r10827  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs

    r10755 r10827  
    1 using System.Linq;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Linq;
    223using HeuristicLab.Core;
    324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10797 r10827  
    1010using IGraphNode = HeuristicLab.EvolutionTracking.IGenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>;
    1111
    12 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     12namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    1313  public static class SymbolicDataAnalysisExpressionTracing {
    1414    public static IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>> TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) {
     
    4040          break;
    4141        }
    42 
     42        var parents = node.Parents.ToList();
    4343        if (node.IsElite) {
    44           node = node.Parents.First();
     44          // skip elite, go up the graph to original individual
     45          node = parents[0];
    4546          continue;
    46         } // skip elite, go up the graph to original individual
    47 
     47        }
     48        var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;
     49        if (fragment == null) {
     50          // the fragment can be null when crossover or mutation did not actually make any change => then we skip
     51          node = parents[0];
     52          continue;
     53        }
     54        var fragmentLength = fragment.Root.GetLength();
    4855        var tree = node.Content;
    4956        var subtree = tree.NodeAt(index);
    5057        var subtreeLength = subtree.GetLength();
    5158
    52         var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;
    53         if (fragment == null) break;
    54         var fragmentLength = fragment.Root.GetLength();
     59        if (parents.Count == 1) {
     60          // we are tracing a mutation operation
     61          var fragmentNode = new FragmentNode {
     62            Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
     63            Rank = node.Rank
     64          };
     65          if (parent != null) {
     66            var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
     67            parent.AddForwardArc(arc);
     68          }
     69          yield return fragmentNode;
     70          var up = Trace(parents[0], fragment.Index1, fragmentNode);
     71          foreach (var v in up) { yield return v; }
     72          break;
     73        }
    5574
    56         if (fragment.Index1 == index) {
    57           node = node.Parents.Last(); // take second parent which contains the fragment
    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
    65             node = node.Parents.First(); // take first parent which contains the subtree
    66             index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes
     75        if (parents.Count == 2) {
     76          // we are tracing a crossover operation
     77          if (fragment.Index1 == index) {
     78            node = parents[1]; // take second parent which contains the fragment
     79            index = fragment.Index2;
     80            continue;
    6781          }
    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);
     82
     83          if (fragment.Index1 < index) {
     84            if (fragment.Index1 + fragmentLength > index) {
     85              node = parents[1]; // fragment contains subtree, take second parent
     86              index += fragment.Index2 - fragment.Index1; // the subtree has the same index relative to the fragment
     87            } else {
     88              // fragment distinct from subtree
     89              node = parents[0]; // take first parent which contains the subtree
     90              index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes
    7891            }
    79             fragmentNode.Content.Index1 = fragment.Index1 - index;
    80             yield return fragmentNode;
     92            continue;
     93          }
    8194
    82             var left = Trace(node.Parents.First(), index, fragmentNode); // trace subtree
     95          if (fragment.Index1 > index) {
     96            if (fragment.Index1 < index + subtreeLength) {
     97              // subtree contains fragment => bifurcation point in the fragment graph
     98              var fragmentNode = new FragmentNode {
     99                Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
     100                Rank = node.Rank
     101              };
     102              if (parent != null) {
     103                var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode };
     104                parent.AddForwardArc(arc);
     105              }
     106              fragmentNode.Content.Index1 = fragment.Index1 - index;
     107              yield return fragmentNode;
    83108
    84             if (node.Parents.Last().Content.NodeAt(fragment.Index2).GetLength() != fragmentLength) {
    85               throw new Exception("Fragment lengths should match!");
     109              if (parents[1].Content.NodeAt(fragment.Index2).GetLength() != fragmentLength) {
     110                throw new Exception("Fragment lengths should match!");
     111              }
     112              // the two paths below ("left" and "right") correspond to the subtree and the fragment, respectively
     113              var left = Trace(parents[0], index, fragmentNode); // trace subtree
     114              var right = Trace(parents[1], fragment.Index2, fragmentNode); // trace fragment
     115              foreach (var v in left.Concat(right)) { yield return v; }
     116              break;
     117            } else {
     118              node = parents[0]; // fragment distinct from subtree: update node, index remains unchanged
    86119            }
    87             var right = Trace(node.Parents.Last(), fragment.Index2, fragmentNode); // trace fragment
    88             foreach (var v in left.Concat(right)) { yield return v; }
    89             break;
    90           } else {
    91             node = node.Parents.First(); // fragment distinct from subtree: update node, index remains unchanged
    92120          }
    93121        }
     
    101129    }
    102130    #region some helper methods for shortening the tracing code
    103 
    104131    private static void AddChild(this IGenealogyGraphNode parent, IGenealogyGraphNode child) {
    105132      parent.AddForwardArc(child);
Note: See TracChangeset for help on using the changeset viewer.