Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/13 13:18:57 (11 years ago)
Author:
bburlacu
Message:

#1772: Refactoring of directed graph components, added code for correctly serializing vertices and edges. Added specific building blocks analyzers and new population diversity analyzer which correctly integrates with the parallel engine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Operators/SymbolicExpressionTreeGenealogyGraphBuilder.cs

    r9247 r9419  
    201201      var qualities = SymbolicExpressionTreeQualityParameter.ActualValue.ToArray();
    202202
    203       if (trees.Length != qualities.Length) throw new Exception("Error: trees and qualities array sizes do not match!");
     203      if (trees.Length != qualities.Length)
     204        throw new Exception("Error: trees and qualities array sizes do not match!");
    204205
    205206      // add all individuals to the evolutionary graph
    206207      int generation = Generations.Value;
    207208
    208       var pairs = trees.Zip(qualities, (t, q) => new { Tree = t, Quality = q.Value }).OrderByDescending(x => x.Quality).ToList();
     209      var pairs =
     210        trees.Zip(qualities, (t, q) => new { Tree = t, Quality = q.Value }).OrderByDescending(x => x.Quality).ToList();
    209211
    210212      if (generation == 0) {
     
    214216          var quality = pair.Quality;
    215217          graph.AddNode(new SymbolicExpressionGenealogyGraphNode {
    216             SymbolicExpressionTree = tree, Quality = quality, Rank = generation
     218            SymbolicExpressionTree = tree,
     219            Quality = quality,
     220            Rank = generation
    217221          });
    218222        }
     
    231235        // the following query addds the intermediate nodes that were created when
    232236        // crossover was followed by mutation (they are not present in the scope)
    233                         (from t in trees
    234                          where GlobalTraceMap.ContainsKey(t)
    235                          let parents = GlobalTraceMap[t]
    236                          where parents.Count == 1 // 1 parent means mutation
    237                          let p = (ISymbolicExpressionTree)parents[0]
    238                          select new SymbolicExpressionGenealogyGraphNode {
    239                            SymbolicExpressionTree = p,
    240                            Quality = Evaluate(p),
    241                            Rank = generation - 0.5 // an intermediate parent that would normale be 'invisible' to the evolutionary process
    242                          }
    243                         ).ToList();
     237        (from t in trees
     238         where GlobalTraceMap.ContainsKey(t)
     239         let parents = GlobalTraceMap[t]
     240         where parents.Count == 1
     241         // 1 parent means mutation
     242         let p = (ISymbolicExpressionTree)parents[0]
     243         select new SymbolicExpressionGenealogyGraphNode {
     244           SymbolicExpressionTree = p,
     245           Quality = Evaluate(p),
     246           Rank = generation - 0.5
     247           // an intermediate parent that would normale be 'invisible' to the evolutionary process
     248         }
     249        ).ToList();
    244250
    245251      foreach (var node in graphNodes) {
     
    262268          continue;
    263269        }
    264         var parents = GlobalTraceMap[tree].Cast<ISymbolicExpressionTree>();
     270        var parents = GlobalTraceMap[tree].Cast<ISymbolicExpressionTree>().ToList();
     271        var fragment = GlobalFragmentMap[tree];
    265272        foreach (var p in parents) {
    266273          var nodes = graph.GetGraphNodes(p);
     
    272279            throw new Exception("Source node cannot be null");
    273280          }
    274           var arc = new Arc { Source = sourceNode, Target = node, Data = GlobalFragmentMap[tree] };
     281          var arc = new Arc { Source = sourceNode, Target = node, Data = fragment };
    275282          sourceNode.AddForwardArc(arc);
    276283          node.AddReverseArc(arc);
    277284        }
     285        // the root parent is the one that receives the subtree/fragment from the other parent
     286        // so it does not actually pass a subtree to the child, therefore the fragment is null
     287        // so in case of crossover, we add a null fragment below
     288        if (parents.Count > 1) node.InEdges[0].Data = new Fragment(null);
    278289      }
     290
     291      // notify listeners that the genealogy graph was updated
     292      graph.Updated();
     293
    279294      return base.Apply();
    280295    }
Note: See TracChangeset for help on using the changeset viewer.