Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10827


Ignore:
Timestamp:
05/08/14 17:26:32 (10 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
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10797 r10827  
    4141
    4242    private const int labelHeight = 30;
     43
     44    private readonly SolidBrush defaultBrush;
     45    private readonly Pen defaultPen;
     46    private readonly Font defaultFont;
    4347
    4448    public ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> LayoutEngine { get; set; }
     
    127131      PreferredNodeHeight = 40;
    128132      Group = new Group(chart);
     133
     134      defaultBrush = new SolidBrush(Color.Transparent);
     135      defaultPen = new Pen(Color.Black);
     136      defaultFont = new Font(FontFamily.GenericSansSerif, 12, GraphicsUnit.Pixel);
    129137    }
    130138    public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree)
     
    142150      var visualNodes = LayoutEngine.CalculateLayout(actualRoot).ToList();
    143151
    144       var font = new Font(FontFamily.GenericSansSerif, 10, GraphicsUnit.Pixel);
    145 
    146152      var visualNodeMap = visualNodes.ToDictionary(x => x.Content, x => x);
    147153
     
    154160        var shortenedLabel = ShortenLabel(node);
    155161        if (node.SubtreeCount == 0) {
    156           rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) { Font = font, Text = shortenedLabel };
     162          rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) {
     163            Font = defaultFont, Text = shortenedLabel, Brush = defaultBrush, Pen = defaultPen, MaximumFontSize = 12f
     164          };
    157165        } else {
    158           rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) { Font = font, Text = shortenedLabel };
     166          rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) {
     167            Font = defaultFont, Text = shortenedLabel, Brush = defaultBrush, Pen = defaultPen, MaximumFontSize = 12f
     168          };
    159169        }
    160170
     
    189199      // draw a primitive to display the label
    190200      var labelRect = new Rectangle(this.Chart, new PointD(0, height), new PointD(width, height + labelHeight)) {
    191         Pen = new Pen(Color.Black),
    192         Brush = new SolidBrush(Color.Transparent),
     201        Pen = defaultPen,
     202        Brush = defaultBrush,
    193203        Text = Label,
    194         Font = new Font(FontFamily.GenericSansSerif, 12)
     204        Font = defaultFont
    195205      };
    196206      this.Add(labelRect);
     
    200210
    201211      var rectangle = new Rectangle(this.Chart, new PointD(0, 0), new PointD(Size.Width, Size.Height)) {
    202         Pen = new Pen(Color.Gray),
    203         Brush = new SolidBrush(Color.Transparent)
     212        Pen = defaultPen,
     213        Brush = defaultBrush
    204214      };
    205215      this.Add(rectangle);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs

    r10746 r10827  
    3737    private const double Diameter = 20;
    3838
     39    private readonly Brush defaultBrush;
     40    private readonly Pen defaultPen;
     41
    3942    public IGenealogyGraph GenealogyGraph {
    4043      get { return genealogyGraph; }
     
    9598      : base() {
    9699      InitializeComponent();
     100
     101      defaultBrush = new SolidBrush(Color.Transparent);
     102      defaultPen = new Pen(Color.DarkGray);
    97103    }
    98104
     
    111117
    112118        foreach (var node in nodes) {
    113           var pen = new Pen(Color.DarkGray);
    114119          var brush = new SolidBrush(node.GetColor());
    115120
    116           var visualNode = new VisualGenealogyGraphNode(Chart, x, y, x + diameter, y + diameter, pen, brush) {
     121          var visualNode = new VisualGenealogyGraphNode(Chart, x, y, x + diameter, y + diameter, defaultPen, brush) {
    117122            Data = node,
    118123            ToolTipText = "Rank: " + node.Rank + nl +
     
    138143          var visualParent = GetMappedNode(parent);
    139144          if (visualParent == null) continue;
    140           var pen = new Pen(Color.Transparent);
     145          var pen = Pens.Transparent;
    141146          var visualArc = AddArc(Chart, visualParent, visualNode, pen);
    142147          if (!arcMap.ContainsKey(Tuple.Create(visualParent, visualNode)))
     
    233238        var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
    234239        var end = new Point((int)arc.End.X, (int)arc.End.Y);
     240        arc.Pen = new Pen(Color.Transparent);
    235241        arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
    236         arc.Pen.Color = Color.Transparent;
    237242        DrawLineage(nodeSelector(arc), arcSelector, nodeSelector);
    238243      }
     
    266271      foreach (var primitive in Chart.Group.Primitives) {
    267272        if (primitive is VisualGenealogyGraphArc) {
    268           primitive.Pen.Brush = new SolidBrush(Color.Transparent);
     273          primitive.Pen = Pens.Transparent;
    269274        } else if (primitive is VisualGenealogyGraphNode) {
    270           var brush = (SolidBrush)primitive.Brush;
    271           brush.Color = Color.Transparent;
    272           primitive.Pen.Color = Color.DarkGray;
     275          primitive.Brush = Brushes.Transparent;
     276          primitive.Pen = Pens.DarkGray;
    273277        }
    274278      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r10823 r10827  
    237237      <DependentUpon>GraphicalSymbolicDataAnalysisModelView.cs</DependentUpon>
    238238    </Compile>
    239     <Compile Include="Symbols\ConstantView.cs" />
     239    <Compile Include="Symbols\ConstantView.cs">
     240      <SubType>UserControl</SubType>
     241    </Compile>
    240242    <Compile Include="Symbols\ConstantView.Designer.cs">
    241243      <DependentUpon>ConstantView.cs</DependentUpon>
    242244    </Compile>
    243     <Compile Include="Symbols\LaggedVariableView.cs" />
     245    <Compile Include="Symbols\LaggedVariableView.cs">
     246      <SubType>UserControl</SubType>
     247    </Compile>
    244248    <Compile Include="Symbols\LaggedVariableView.Designer.cs">
    245249      <DependentUpon>LaggedVariableView.cs</DependentUpon>
    246250    </Compile>
    247     <Compile Include="Symbols\TimeLagView.cs" />
     251    <Compile Include="Symbols\TimeLagView.cs">
     252      <SubType>UserControl</SubType>
     253    </Compile>
    248254    <Compile Include="Symbols\TimeLagView.Designer.cs">
    249255      <DependentUpon>TimeLagView.cs</DependentUpon>
    250256    </Compile>
    251     <Compile Include="Symbols\VariableConditionView.cs" />
     257    <Compile Include="Symbols\VariableConditionView.cs">
     258      <SubType>UserControl</SubType>
     259    </Compile>
    252260    <Compile Include="Symbols\VariableConditionView.Designer.cs">
    253261      <DependentUpon>VariableConditionView.cs</DependentUpon>
    254262    </Compile>
    255     <Compile Include="Symbols\VariableView.cs" />
     263    <Compile Include="Symbols\VariableView.cs">
     264      <SubType>UserControl</SubType>
     265    </Compile>
    256266    <Compile Include="Symbols\VariableView.Designer.cs">
    257267      <DependentUpon>VariableView.cs</DependentUpon>
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/FragmentGraphView.cs

    r10797 r10827  
    101101              var rpb = primitive as RectangularPrimitiveBase;
    102102              if (rpb != null) {
    103                 rpb.Pen = new Pen(Color.RoyalBlue);
     103                rpb.Pen = Pens.RoyalBlue;
    104104              }
    105105            }
     
    123123                  var rpb = primitive as RectangularPrimitiveBase;
    124124                  if (rpb != null) {
    125                     rpb.Pen = new Pen(Color.DarkOrange);
     125                    rpb.Pen = Pens.DarkOrange;
    126126                  }
    127127                }
  • 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.