Changeset 10462 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 02/19/14 08:25:37 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10347 r10462 1 using System.Collections.Generic; 2 using System.Linq; 1 using System.Linq; 3 2 using HeuristicLab.Common; 4 3 using HeuristicLab.Core; … … 167 166 } 168 167 169 public override IOperation Apply() { 170 if (Generations.Value == 0) { 171 foreach (var individual in PopulationParameter.ActualValue) { 172 var vertex = new GenealogyGraphNode<T> { 173 Content = individual, 174 Rank = Generations.Value 175 }; 176 GenealogyGraph.AddVertex(vertex); 177 } 178 // at the beginning we add the before/after operators to the instrumented operators 168 private void ConfigureTrackingOperators() { 169 // at the beginning we add the before/after operators to the instrumented operators 170 if (Crossover != null) { 171 var instrumentedCrossover = (InstrumentedOperator)Crossover; 172 instrumentedCrossover.AfterExecutionOperators.Clear(); 173 instrumentedCrossover.BeforeExecutionOperators.Clear(); 174 179 175 if (EnableCrossoverTracking.Value) { 180 176 if (BeforeCrossoverOperator != null) { 181 177 BeforeCrossoverOperator.ParentsParameter.ActualName = CrossoverParentsParameterName; 182 178 BeforeCrossoverOperator.ChildParameter.ActualName = CrossoverChildParameterName; 183 var instrumentedCrossover = (InstrumentedOperator)Crossover;184 179 instrumentedCrossover.BeforeExecutionOperators.Add(BeforeCrossoverOperator); 185 180 } … … 187 182 AfterCrossoverOperator.ParentsParameter.ActualName = CrossoverParentsParameterName; 188 183 AfterCrossoverOperator.ChildParameter.ActualName = CrossoverChildParameterName; 189 var instrumentedCrossover = (InstrumentedOperator)Crossover;190 184 instrumentedCrossover.AfterExecutionOperators.Add(AfterCrossoverOperator); 191 185 } 192 186 } 193 187 } 188 189 if (Manipulator != null) { 190 var instrumentedManipulator = (InstrumentedOperator)Manipulator; 191 instrumentedManipulator.AfterExecutionOperators.Clear(); 192 instrumentedManipulator.BeforeExecutionOperators.Clear(); 194 193 if (EnableManipulatorTracking.Value && Manipulator != null) { 195 if (BeforeManipulatorOperator == null) { 196 BeforeManipulatorOperator = new BeforeManipulatorOperator<T>(); 194 if (BeforeManipulatorOperator != null) { 197 195 BeforeManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName; 198 var instrumentedManipulator = (InstrumentedOperator)Manipulator;199 196 instrumentedManipulator.BeforeExecutionOperators.Add(BeforeManipulatorOperator); 200 197 } 201 if (AfterManipulatorOperator == null) { 202 AfterManipulatorOperator = new AfterManipulatorOperator<T>(); 198 if (AfterManipulatorOperator != null) { 203 199 AfterManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName; 204 var instrumentedManipulator = (InstrumentedOperator)Manipulator;205 200 instrumentedManipulator.AfterExecutionOperators.Add(AfterManipulatorOperator); 206 201 } 207 202 } 203 } 204 } 205 206 public override IOperation Apply() { 207 var population = PopulationParameter.ActualValue.ToList(); 208 var qualities = QualityParameter.ActualValue.ToList(); 209 210 if (Generations.Value == 0) { 211 ConfigureTrackingOperators(); 212 213 foreach (var individual in population) { 214 var vertex = new GenealogyGraphNode<T> { Content = individual, Rank = Generations.Value, }; 215 GenealogyGraph.AddVertex(vertex); 216 } 208 217 } else { 209 // add missing elite individuals in the current generation 210 // TODO: optimize for speed 211 var currGen = new HashSet<T>(GenealogyGraph.Ranks[Generations.Value].Cast<IGenealogyGraphNode<T>>().Select(x => x.Content)); 212 foreach (var individual in PopulationParameter.ActualValue) { 213 if (currGen.Contains(individual)) continue; 214 // it is an elite which was already added to the graph in the previous generation 218 var elite = population.FirstOrDefault(x => GenealogyGraph.Contains(x)); 219 if (elite != null) { 215 220 var vertex = new GenealogyGraphNode<T> { 216 Content = individual,221 Content = elite, 217 222 Rank = Generations.Value, 218 223 IsElite = true 219 224 }; 225 var previousVertex = GenealogyGraph[elite].Last(); 220 226 GenealogyGraph.AddVertex(vertex); 221 }222 }223 // update qualities for the nodes in the graph224 var population = PopulationParameter.ActualValue.ToList();225 var qualities = QualityParameter.ActualValue.ToList();227 previousVertex.AddForwardArc(vertex); 228 vertex.AddReverseArc(previousVertex); 229 } 230 } 231 // update qualities 226 232 for (int i = 0; i < population.Count; ++i) { 227 foreach (var v in GenealogyGraph[population[i]].Cast<IGenealogyGraphNode<T>>()) { 228 v.Quality = qualities[i].Value; 233 var individual = population[i]; 234 foreach (var vertex in GenealogyGraph[individual].Cast<IGenealogyGraphNode<T>>()) { 235 vertex.Quality = qualities[i].Value; 229 236 } 230 237 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterCrossoverOperator.cs
r10347 r10462 29 29 [Item("AfterCrossoverOperator", "A generic operator that can record genealogical relationships between crossover parents and children.")] 30 30 public class AfterCrossoverOperator<T> : EvolutionTrackingOperator, ICrossoverOperator<T> where T : class,IItem { 31 private const string defaultParentsParameterName = "Parents";32 private const string defaultChildParameterName = "Child";31 private const string DefaultParentsParameterName = "Parents"; 32 private const string DefaultChildParameterName = "Child"; 33 33 public IScopeTreeLookupParameter<T> ParentsParameter { get; set; } 34 34 public ILookupParameter<T> ChildParameter { get; set; } … … 42 42 43 43 public AfterCrossoverOperator() { 44 ParentsParameter = new ScopeTreeLookupParameter<T>( defaultParentsParameterName);45 ChildParameter = new LookupParameter<T>( defaultChildParameterName);44 ParentsParameter = new ScopeTreeLookupParameter<T>(DefaultParentsParameterName); 45 ChildParameter = new LookupParameter<T>(DefaultChildParameterName); 46 46 Parameters.Add(ParentsParameter); 47 47 Parameters.Add(ChildParameter); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisGenealogyGraphView.cs
r10347 r10462 17 17 var visualNode = (VisualGenealogyGraphNode)sender; 18 18 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)visualNode.Data; 19 var fragment = (IFragment<ISymbolicExpressionTreeNode>)graphNode.InArcs.Last().Data; 20 var treeView = (GraphicalSymbolicExpressionTreeView)viewHost.ActiveView; 21 treeView.HighlightSubtree(fragment.Root, Color.RoyalBlue); 19 IFragment<ISymbolicExpressionTreeNode> fragment = null; 20 if (graphNode.InArcs != null) 21 fragment = (IFragment<ISymbolicExpressionTreeNode>)graphNode.InArcs.Last().Data; 22 if (fragment != null) { 23 var treeView = (GraphicalSymbolicExpressionTreeView)viewHost.ActiveView; 24 treeView.HighlightSubtree(fragment.Root, Color.RoyalBlue); 25 } 22 26 } 23 27 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r10459 r10462 356 356 // add tracking analyzer 357 357 foreach (var op in operators.OfType<SymbolicDataAnalysisGenealogyAnalyzer>()) { 358 // op.BeforeCrossoverOperator = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator(); 359 // op.AfterCrossoverOperator = new SymbolicDataAnalysisExpressionAfterCrossoverOperator(); 360 op.BeforeCrossoverOperator = new BeforeCrossoverOperator<ISymbolicExpressionTree>(); 361 op.AfterCrossoverOperator = new AfterCrossoverOperator<ISymbolicExpressionTree>(); 358 op.BeforeCrossoverOperator = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator(); 359 op.AfterCrossoverOperator = new SymbolicDataAnalysisExpressionAfterCrossoverOperator(); 362 360 op.BeforeManipulatorOperator = new BeforeManipulatorOperator<ISymbolicExpressionTree>(); 363 361 op.AfterManipulatorOperator = new AfterManipulatorOperator<ISymbolicExpressionTree>(); … … 373 371 op.ManipulatorChildParameterName = manipulator.SymbolicExpressionTreeParameter.Name; 374 372 } 375 op.PopulationParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 373 var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault(); 374 if (creator != null) { 375 op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName; 376 } 376 377 } 377 378 }
Note: See TracChangeset
for help on using the changeset viewer.