Changeset 11233 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
- Timestamp:
- 07/30/14 01:41:54 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r11227 r11233 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 268 269 #region add elite in the graph and connect it with the previous elite 269 270 if (elite != null) { 270 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.Get Vertex(elite);271 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite); 271 272 prevVertex.IsElite = true; // mark elites in the graph retroactively 272 273 273 274 var clone = (T)elite.Clone(); 274 275 275 var v ertex= new GenealogyGraphNode<T>(prevVertex.Content) {276 var v = new GenealogyGraphNode<T>(prevVertex.Content) { 276 277 Rank = generation, 277 278 Quality = prevVertex.Quality, … … 279 280 }; 280 281 281 prevVertex.Content = clone; 282 var w = new GenealogyGraphNode<T>(clone) { 283 Rank = generation - 1, 284 Quality = prevVertex.Quality, 285 IsElite = true 286 }; 287 288 // replace previous elite with vertex w 289 List<IGenealogyGraphNode<T>> parents = null; 290 object data = null; 291 if (prevVertex.InArcs.Any()) { 292 data = prevVertex.InArcs.Last().Data; 293 parents = prevVertex.InArcs.Select(x => (IGenealogyGraphNode<T>)x.Source).ToList(); 294 // v.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one 295 // var p = prevVertex.InArcs.First().Source; 296 // GenealogyGraph.AddArc(p, w); 297 } 298 GenealogyGraph.RemoveVertex(prevVertex); 299 GenealogyGraph.AddVertex(w); 300 GenealogyGraph.AddVertex(v); 301 GenealogyGraph.AddArc(w, v); // connect current elite with previous elite 302 303 v.InArcs.Last().Data = data; 304 if (parents != null) { 305 foreach (var p in parents) 306 GenealogyGraph.AddArc(p, w); 307 } 308 282 309 // inject the graph node unique id to the scope 283 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id); 284 GenealogyGraph.AddVertex(vertex); 285 GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite 286 287 if (prevVertex.InArcs.Any()) { 288 vertex.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one 289 } 310 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id); 290 311 } 291 312 #endregion … … 295 316 // update qualities 296 317 for (int i = 0; i < population.Length; ++i) { 297 var vertex = (IGenealogyGraphNode)GenealogyGraph.Get Vertex(population[i]);318 var vertex = (IGenealogyGraphNode)GenealogyGraph.GetByContent(population[i]); 298 319 vertex.Quality = qualities[i].Value; 299 320 } … … 301 322 // remove extra graph nodes (added by the instrumented operators in the case of offspring selection) 302 323 var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Content).Except(population).ToList(); 303 foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.Get Vertex(individual))) {324 foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) { 304 325 GenealogyGraph.RemoveVertex(vertex); 305 326 } … … 313 334 // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring) 314 335 foreach (var ind in population) { 315 var v = (IGenealogyGraphNode)GenealogyGraph.Get Vertex(ind);336 var v = (IGenealogyGraphNode)GenealogyGraph.GetByContent(ind); 316 337 foreach (var p in v.Parents) 317 338 p.Weight++;
Note: See TracChangeset
for help on using the changeset viewer.