Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10674


Ignore:
Timestamp:
03/26/14 17:14:14 (10 years ago)
Author:
bburlacu
Message:

#1772: Found bug in GenealogyGraph creation, attempted fix by injecting vertex guid's in the individual scopes.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
4 edited

Legend:

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

    r10650 r10674  
    211211        ConfigureTrackingOperators();
    212212
    213         foreach (var individual in population) {
     213        for (int i = 0; i < population.Count; ++i) {
     214          var individual = population[i];
    214215          var vertex = new GenealogyGraphNode<T> { Content = individual, Rank = Generations.Value, };
    215216          GenealogyGraph.AddVertex(vertex);
     217          // save the vertex id in the individual scope (so that we can identify graph indices)
     218          ExecutionContext.Scope.SubScopes[i].Variables.Add(new Variable("Id", new StringValue(vertex.Id)));
    216219        }
    217220      } else {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs

    r10650 r10674  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2728using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6364      if (CurrentGeneration == null) throw new Exception();
    6465      // we get the parents by parsing the scope name because the individuals in the execution scope are clones of the ones saved in the graph
    65       var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration[int.Parse(s.Name)]).ToList();
     66      //      var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration.Find(x => x.Id == ((StringValue)s.Variables["Id"].Value)).ToList();
     67      var parentVertices = (from s in ExecutionContext.Scope.SubScopes
     68                            let id = ((StringValue)s.Variables["Id"].Value).Value
     69                            select CurrentGeneration.First(x => x.Id == id)).ToList(); // the id is unique
    6670
    6771      var parents = ParentsParameter.ActualValue.ToList();
     
    7781        v.AddForwardArc(childVertex);
    7882      }
     83      ExecutionContext.Scope.Variables.Add(new Variable("Id", new StringValue(childVertex.Id)));
    7984
    8085      return base.Apply();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymboldDataAnalysisGenealogyView.cs

    r10656 r10674  
    177177      // the subtree must belong to the currently displayed tree which in turn must belong to the currently selected graph node
    178178      var tree = graphNode.Content;
    179       var index = tree.IterateNodesPrefix().ToList().IndexOf(subtree);
    180       var length = subtree.GetLength();
     179      var subtreeIndex = tree.IterateNodesPrefix().ToList().IndexOf(subtree);
     180      var subtreeLength = subtree.GetLength();
    181181
    182182      var fragment = (IFragment<ISymbolicExpressionTreeNode>)graphNode.InArcs.Last().Data;
     
    184184      var fragmentLength = fragment.Root.GetLength();
    185185
     186      FragmentNode node = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank };
     187      if (parentNode != null) {
     188        AddChild(parentNode, node);
     189      }
     190      fragmentGraph.AddVertex(node);
    186191
    187192      // below, we consider three cases:
     
    190195      // 3) the fragment is contained by the selected subtree
    191196      // In each case, the idea is to isolate and individually track the fragment and the rest of the subtree (for cases 2 and 3)
    192       if (fragment.Index == index) {
     197      if (fragment.Index == subtreeIndex) {
    193198        // the selected subtree is the actual fragment
    194         if (fragmentLength != length) throw new Exception("Fragment and subtree lengths should be the same!");
    195 
    196         var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank };
    197 
    198         if (parentNode != null) {
    199           AddChild(parentNode, node);
    200         }
    201 
    202         fragmentGraph.AddVertex(node);
     199        if (fragmentLength != subtreeLength) throw new Exception("Fragment and subtree lengths should be the same!");
    203200
    204201        var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source;
    205202        var s = g.Content.IterateNodesPrefix().ToList()[fragment.OldIndex];
    206203        Trace(g, s, fragmentGraph, node);
    207       } else if (fragment.Index < index && index < fragment.Index + fragmentLength) {
     204
     205      } else if (fragment.Index < subtreeIndex && subtreeIndex < fragment.Index + fragmentLength) {
    208206        // the fragment contains the selected subtree
    209         if (length >= fragmentLength) throw new Exception("Fragment contains subtree, so subtree length should be less than the fragment length.");
    210 
    211         var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank };
    212         if (parentNode != null) {
    213           AddChild(parentNode, node);
    214         }
    215 
    216         fragmentGraph.AddVertex(node);
     207        if (subtreeLength >= fragmentLength) throw new Exception("Fragment contains subtree, so subtree length should be less than the fragment length.");
    217208
    218209        var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source;
    219         var i = fragment.Root.IterateNodesPrefix().ToList().IndexOf(subtree);
     210        var i = fragment.Root.IterateNodesPrefix().ToList().IndexOf(subtree); // get the index of the selected subtree, relative to the fragment root
    220211        var s = g.Content.IterateNodesPrefix().ToList()[fragment.OldIndex + i];
    221212        Trace(g, s, fragmentGraph, node);
    222213
    223       } else if (index < fragment.Index && fragment.Index < index + length) {
     214      } else if (subtreeIndex < fragment.Index && fragment.Index < subtreeIndex + subtreeLength) {
    224215        // the selected subtree contains the fragment
    225         if (fragmentLength >= length)
    226           throw new Exception("Subtree contains fragment, so fragment length should be less than the subtree length.");
    227 
    228         var node = new FragmentNode {
    229           Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
    230           Rank = graphNode.Rank
    231         };
    232 
    233         if (parentNode != null) {
    234           AddChild(parentNode, node);
    235         }
    236         fragmentGraph.AddVertex(node);
     216        if (fragmentLength >= subtreeLength) throw new Exception("Subtree contains fragment, so fragment length should be less than the subtree length.");
    237217
    238218        var g0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source;
    239         var s0 = g0.Content.IterateNodesPrefix().ToList()[index];
     219        var s0 = g0.Content.IterateNodesPrefix().ToList()[subtreeIndex];
    240220        Trace(g0, s0, fragmentGraph, node);
    241221
     
    247227      } else {
    248228        // fragment and subtree are completely distinct, therefore we will track the subtree
    249         var node = new FragmentNode {
    250           Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
    251           Rank = graphNode.Rank
    252         };
    253 
    254         if (parentNode != null) {
    255           AddChild(parentNode, node);
    256         }
    257         fragmentGraph.AddVertex(node);
    258229        var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source;
    259         var s = graphNode.Content.IterateNodesPrefix().ToList()[index];
     230        var s = graphNode.Content.IterateNodesPrefix().ToList()[subtreeIndex];
    260231        Trace(g, s, fragmentGraph, node);
    261232      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs

    r10654 r10674  
    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;
     23using System.Linq;
    224using HeuristicLab.Core;
    325using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    931      var result = base.Apply(); // the child will be added to the graph before the crossover
    1032      var parents = ParentsParameter.ActualValue.ToList();
    11       var childVertex = GenealogyGraph[parents[0]].Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)
    12       //      var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration[int.Parse(s.Name)]).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)
    1334
    14       // we add the breadth list of nodes of each parent as the data element of the arc from the parent to the child
    1535      for (int i = 0; i < parents.Count; ++i) {
    1636        var nodes = parents[i].IterateNodesPrefix().ToList();
    17         var arc = (IGenealogyGraphArc)childVertex.InArcs[i];
     37        var arc = childVertex.InArcs[i];
    1838        arc.Data = nodes;
     39      }
     40      var parentVertices = childVertex.InArcs.Select(x => (IGenealogyGraphNode<ISymbolicExpressionTree>)x.Source).ToList();
     41      if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) {
     42        throw new Exception("Inconsistency detected in GenealogyGraph.");
    1943      }
    2044
Note: See TracChangeset for help on using the changeset viewer.