Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11318


Ignore:
Timestamp:
08/31/14 18:28:25 (10 years ago)
Author:
bburlacu
Message:

#1772: Fixed bug and improved handling of elite individuals in the genealogy analyzer. Fixed minor bug in the tracing code. Other minor cosmetic improvements to the GenealogyGraph and FragmentGraphView.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs

    r11288 r11318  
    272272          var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite);
    273273          prevVertex.IsElite = true; // mark elites in the graph retroactively
    274           var w = (IGenealogyGraphNode<T>)prevVertex.Clone();
    275           var v = new GenealogyGraphNode<T>(prevVertex.Data) {
     274          var v = new GenealogyGraphNode<T>((IDeepCloneable)prevVertex.Data.Clone()) {
    276275            Rank = generation,
    277276            Quality = prevVertex.Quality,
    278277            IsElite = false
    279278          };
    280 
    281           object data = null;
    282           if (prevVertex.InArcs.Any())
    283             data = prevVertex.InArcs.Last().Data;
    284           var children = prevVertex.Children.ToList();
    285           var parents = prevVertex.Parents.ToList();
    286 
    287           GenealogyGraph.RemoveVertex(prevVertex);
    288           GenealogyGraph.AddVertex(w);
    289279          GenealogyGraph.AddVertex(v);
    290           GenealogyGraph.AddArc(w, v); // connect current elite with previous elite
    291 
    292           // recreate connections after prevVertex was replaced with w
    293           foreach (var c in children) GenealogyGraph.AddArc(w, c);
    294           foreach (var p in parents) GenealogyGraph.AddArc(p, w);
    295 
    296           v.InArcs.Last().Data = data;
    297 
    298           if (w.InArcs.Any())
    299             w.InArcs.Last().Data = data;
     280          GenealogyGraph.AddArc(prevVertex, v);
    300281
    301282          // inject the graph node unique id to the scope
     283          ExecutionContext.Scope.SubScopes[index].Variables[BeforeManipulatorOperator.ChildParameter.ActualName].Value = v.Data;
    302284          ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id);
    303285        }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r11257 r11318  
    3838
    3939    [Storable]
    40     private Dictionary<double, List<IGenealogyGraphNode>> ranks; // use a linked list for fast insertion/removal
     40    private Dictionary<double, List<IGenealogyGraphNode>> ranks;
     41
    4142    public Dictionary<double, List<IGenealogyGraphNode>> Ranks {
    4243      get { return ranks; }
     
    5657
    5758    [StorableConstructor]
    58     protected GenealogyGraph(bool deserializing) : base(deserializing) { }
     59    protected GenealogyGraph(bool deserializing)
     60      : base(deserializing) {
     61    }
     62
    5963    public GenealogyGraph() {
    6064      Ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
     
    8589
    8690      if (idMap.ContainsKey(node.Id))
    87         throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph.");
     91        throw new InvalidOperationException("Duplicate ids are not allowed in the genealogy graph.");
    8892      idMap[node.Id] = node;
    8993    }
     
    118122
    119123    public event EventHandler GraphUpdated;
     124
    120125    private void OnGraphUpdated(object sender, EventArgs args) {
    121126      var updated = GraphUpdated;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/FragmentGraphView.cs

    r11253 r11318  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    29 using HeuristicLab.EvolutionTracking;
    3029using HeuristicLab.MainForm;
    3130using HeuristicLab.Visualization;
     
    3837    private const int PreferredVerticalSpacing = 25;
    3938
    40     private ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine;
    41     private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine;
    42 
    43     private Dictionary<FragmentNode, TileLayoutNode> tileDictionary;
     39    private readonly ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine;
     40    private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine;
     41
     42    private readonly Dictionary<FragmentNode, TileLayoutNode> nodeToTileMap;
    4443
    4544    private SymbolicExpressionTreeTile Root { get; set; }
     
    6362        NodeHeight = 40
    6463      };
    65       tileDictionary = new Dictionary<FragmentNode, TileLayoutNode>();
     64      nodeToTileMap = new Dictionary<FragmentNode, TileLayoutNode>();
    6665    }
    6766
    6867    private void MakeTiles() {
    6968      var chart = symbolicExpressionChartControl.Chart;
    70       tileDictionary.Clear();
     69      nodeToTileMap.Clear();
    7170      foreach (var node in Content.Vertices) {
    72         var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)node.Data;
    7371        var tile = new SymbolicExpressionTreeTile(chart);
    7472        tile.LayoutEngine = symbolicExpressionEngine;
    7573        tile.Label = "Generation " + node.Data.Rank + Environment.NewLine +
    7674                     "Quality " + String.Format("{0:0.000}", node.Data.Quality);
    77         tile.Root = graphNode.Data.Root;
     75        tile.Root = node.Data.Data.Root;
    7876        var tileNode = new TileLayoutNode { Tile = tile };
    79         tileDictionary.Add(node, tileNode);
     77        nodeToTileMap.Add(node, tileNode);
    8078      }
    8179      foreach (var node in Content.Vertices.Where(n => n.OutArcs.Any())) {
    82         var layoutNode = tileDictionary[node];
    83         layoutNode.Children = new List<TileLayoutNode>(node.OutArcs.Select(a => tileDictionary[(FragmentNode)a.Target]));
     80        var layoutNode = nodeToTileMap[node];
     81        layoutNode.Children = new List<TileLayoutNode>(node.OutArcs.Select(a => nodeToTileMap[(FragmentNode)a.Target]));
    8482      }
    8583    }
     
    8987      var nodes = Content.Vertices.ToList();
    9088      var root = nodes[0];
    91       var fragmentRoot = tileDictionary[root];
     89      var fragmentRoot = nodeToTileMap[root];
    9290      int maxTileWidth = 0, maxTileHeight = 0;
    93       var tiles = nodes.Select(x => tileDictionary[x].Tile).ToList();
     91      var tiles = nodes.Select(x => nodeToTileMap[x].Tile).ToList();
    9492
    9593      foreach (var tile in tiles) {
     
    114112      // add connections between the tiles
    115113      foreach (var node in nodes) {
    116         var aTile = tileDictionary[node].Tile;
     114        var aTile = nodeToTileMap[node].Tile;
    117115        var aSize = aTile.Size;
    118116        var aPos = aTile.Position;
     
    158156
    159157        foreach (var child in node.OutArcs.Select(x => (FragmentNode)x.Target)) {
    160           var bTile = tileDictionary[child].Tile;
     158          var bTile = nodeToTileMap[child].Tile;
    161159          var bSize = bTile.Size;
    162160          var bPos = bTile.Position;
     
    169167      }
    170168      // center display on the root of the fragment graph
    171       symbolicExpressionChartControl.Chart.Move(tileDictionary[root].Tile.Position.X, tileDictionary[root].Tile.Position.Y);
     169      symbolicExpressionChartControl.Chart.Move(nodeToTileMap[root].Tile.Position.X, nodeToTileMap[root].Tile.Position.Y);
    172170      symbolicExpressionChartControl.UpdateEnabled = true;
    173171      symbolicExpressionChartControl.EnforceUpdate();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11253 r11318  
    173173  </ItemGroup>
    174174  <ItemGroup>
     175    <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" />
     176    <Compile Include="Analyzers\SymbolicDataAnalysisPhenotypicDiversityAnalyzer.cs" />
    175177    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
    176178    <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" />
     
    198200    <Compile Include="SimilarityCalculators\BottomUpSimilarityCalculator.cs" />
    199201    <Compile Include="SimilarityCalculators\MaxCommonSubtreeSimilarityCalculator.cs" />
     202    <Compile Include="SimilarityCalculators\PhenotypicSimilarityCalculator.cs" />
    200203    <Compile Include="SymbolicExpressionTreeBacktransformator.cs" />
    201204    <Compile Include="SlidingWindow\GenerationalSlidingWindowAnalyzer.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs

    r11253 r11318  
    4646      }
    4747
     48      if (fragment == null)
     49        throw new InvalidOperationException("Could not identify crossover fragment.");
     50
    4851      arcs[0].Data = null;
    4952      arcs[1].Data = fragment;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r11253 r11318  
    3232    public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) {
    3333      var graph = new FragmentGraph();
    34       var nodes = Trace(graphNode, subtreeIndex);
    35       foreach (var n in nodes) {
    36         graph.AddVertex(n);
    37       }
     34      var vertices = Trace(graphNode, subtreeIndex).ToList();
     35      graph.AddVertices(vertices);
    3836      return graph;
    3937    }
     
    5250      while (true) {
    5351        if (!node.Parents.Any()) {
    54           var fragmentNode = new FragmentNode(node) {
    55             SubtreeIndex = index,
    56           };
     52          // no tracing if there are no parents, return a fragment node representing the current trace
     53          var fragmentNode = new FragmentNode(node) { SubtreeIndex = index };
    5754          if (parent != null) {
    5855            var arc = new Arc(parent, fragmentNode);
    5956            parent.AddArc(arc);
    6057            fragmentNode.AddArc(arc);
    61 
    62             //            parent.AddForwardArc(arc);
    63             //            fragmentNode.AddReverseArc(arc);
    6458          }
    65           yield return fragmentNode; // no tracing if there are no parents
     59          yield return fragmentNode;
    6660          break;
    6761        }
    6862        var parents = node.Parents.ToList();
    69         var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;
    70 
    71         if (node.IsElite || fragment == null) {
     63        if (node.IsElite) {
    7264          // skip elite, go up the graph to original individual
    7365          node = parents[0];
    7466          continue;
    7567        }
     68        var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;
     69
     70        if (node.Rank > 1 && fragment == null)
     71          throw new ArgumentNullException("Fragment cannot be null");
     72
    7673        var fragmentLength = fragment.Root.GetLength();
    7774        var tree = node.Data;
     
    139136          if (fragment.Index1 > index) {
    140137            if (fragment.Index1 < index + subtreeLength) {
    141               // subtree contains fragment => bifurcation point in the fragment graph
     138              // subtree contains fragment => branching point in the fragment graph
    142139              var fragmentNode = new FragmentNode(node) {
    143140                SubtreeIndex = index,
Note: See TracChangeset for help on using the changeset viewer.