Changeset 9419 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Operators/SymbolicExpressionTreeGenealogyGraphBuilder.cs
- Timestamp:
- 05/02/13 13:18:57 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Operators/SymbolicExpressionTreeGenealogyGraphBuilder.cs
r9247 r9419 201 201 var qualities = SymbolicExpressionTreeQualityParameter.ActualValue.ToArray(); 202 202 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!"); 204 205 205 206 // add all individuals to the evolutionary graph 206 207 int generation = Generations.Value; 207 208 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(); 209 211 210 212 if (generation == 0) { … … 214 216 var quality = pair.Quality; 215 217 graph.AddNode(new SymbolicExpressionGenealogyGraphNode { 216 SymbolicExpressionTree = tree, Quality = quality, Rank = generation 218 SymbolicExpressionTree = tree, 219 Quality = quality, 220 Rank = generation 217 221 }); 218 222 } … … 231 235 // the following query addds the intermediate nodes that were created when 232 236 // 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(); 244 250 245 251 foreach (var node in graphNodes) { … … 262 268 continue; 263 269 } 264 var parents = GlobalTraceMap[tree].Cast<ISymbolicExpressionTree>(); 270 var parents = GlobalTraceMap[tree].Cast<ISymbolicExpressionTree>().ToList(); 271 var fragment = GlobalFragmentMap[tree]; 265 272 foreach (var p in parents) { 266 273 var nodes = graph.GetGraphNodes(p); … … 272 279 throw new Exception("Source node cannot be null"); 273 280 } 274 var arc = new Arc { Source = sourceNode, Target = node, Data = GlobalFragmentMap[tree]};281 var arc = new Arc { Source = sourceNode, Target = node, Data = fragment }; 275 282 sourceNode.AddForwardArc(arc); 276 283 node.AddReverseArc(arc); 277 284 } 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); 278 289 } 290 291 // notify listeners that the genealogy graph was updated 292 graph.Updated(); 293 279 294 return base.Apply(); 280 295 }
Note: See TracChangeset
for help on using the changeset viewer.