Changeset 11858
- Timestamp:
- 02/02/15 13:58:40 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r11852 r11858 60 60 61 61 public IEnumerable<IGenealogyGraphNode> Parents { 62 get { return InArcs.Select(a => a.Source); }62 get { return base.InArcs.Select(x => (IGenealogyGraphNode)x.Source); } 63 63 } 64 64 65 65 public IEnumerable<IGenealogyGraphNode> Children { 66 get { return OutArcs.Select(a => a.Target); }66 get { return base.OutArcs.Select(x => (IGenealogyGraphNode)x.Target); } 67 67 } 68 68 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
r11390 r11858 30 30 namespace HeuristicLab.EvolutionTracking { 31 31 [StorableClass] 32 [Item(" AfterCrossoverOperator", "A generic operator that can record genealogical relationships between crossover parents and children.")]32 [Item("BeforeCrossoverOperator", "A generic operator that can record genealogical relationships between crossover parents and children.")] 33 33 public class BeforeCrossoverOperator<T> : EvolutionTrackingOperator<T>, ICrossoverOperator<T> where T : class,IItem { 34 34 private const string ParentsParameterName = "Parents"; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r11387 r11858 53 53 public override IOperation Apply() { 54 54 // since mutation always takes place after crossover, the vertex for the current child is already in the tree 55 var childVertex= GenealogyGraph.GetByContent(ChildParameter.ActualValue);56 var clonedVertex = (IGenealogyGraphNode<T>)childVertex.Clone();57 clonedVertex.Rank = childVertex.Rank - 0.5;58 GenealogyGraph.AddVertex( clonedVertex);55 var vChild = GenealogyGraph.GetByContent(ChildParameter.ActualValue); 56 var vClone = (IGenealogyGraphNode<T>)vChild.Clone(); 57 vClone.Rank = vChild.Rank - 0.5; 58 GenealogyGraph.AddVertex(vClone); 59 59 60 var arcs = childVertex.InArcs.ToList();60 var arcs = vChild.InArcs.ToList(); 61 61 foreach (var arc in arcs) { 62 62 var p = arc.Source; 63 63 GenealogyGraph.RemoveArc(arc); 64 GenealogyGraph.AddArc(new GenealogyGraphArc(p, clonedVertex));64 GenealogyGraph.AddArc(new GenealogyGraphArc(p, vClone)); 65 65 } 66 66 // by convention, the arc connecting child with parent (non-root parent in case of crossover) 67 67 // holds fragment data when applicable. the following line of code preserves this data 68 68 // the graph arcs are now connecting parent (rank n) --> clone (rank n+0.5) --> child (rank n+1) 69 clonedVertex.InArcs.Last().Data = arcs.Last().Data;70 GenealogyGraph.AddArc(new GenealogyGraphArc( clonedVertex, childVertex));69 vClone.InArcs.Last().Data = arcs.Last().Data; 70 GenealogyGraph.AddArc(new GenealogyGraphArc(vClone, vChild)); 71 71 72 72 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11638 r11858 326 326 <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs" /> 327 327 <Compile Include="Tracking\SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs" /> 328 <Compile Include="Tracking\SymbolicDataAnalysisExpressionTracing.cs" />329 328 <None Include="HeuristicLab.snk" /> 330 329 <None Include="Plugin.cs.frame" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11855 r11858 100 100 while (g.Parents.Any()) { 101 101 Debug.Assert(si < g.Data.Length); 102 var parents = g.Parents.ToList();103 var fragment = (IFragment<ISymbolicExpressionTreeNode>) g.InArcs.Last().Data;102 var inArcs = (List<IArc>)((IVertex)g).InArcs; 103 var fragment = (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data; 104 104 if (fragment == null) { 105 105 // TODO: think about what the correct behavior should be here (seems good so far) 106 106 // the node is either an elite node or (in rare cases) no fragment was transferred 107 g = parents[0];107 g = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source; 108 108 continue; 109 109 } … … 114 114 115 115 #region trace crossover 116 if (parents.Count == 2) { 116 if (inArcs.Count == 2) { 117 var parent0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source; 118 var parent1 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[1].Source; 117 119 if (fi == si) { 118 g = parent s[1];120 g = parent1; 119 121 si = fragment.Index2; 120 122 continue; … … 123 125 if (fi + fl > si) { 124 126 // fragment contains subtree 125 g = parent s[1];127 g = parent1; 126 128 si += fragment.Index2 - fi; 127 129 } else { 128 130 // fragment distinct from subtree 129 g = parent s[0];131 g = parent0; 130 132 si += NodeAt(g.Data, fi).GetLength() - fl; 131 133 } … … 136 138 // subtree contains fragment => branching point in the fragment graph 137 139 var n = GetTraceNode(g, si, fi); 138 TraceRecursive(parent s[0], si, n);139 TraceRecursive(parent s[1], fragment.Index2, n);140 TraceRecursive(parent0, si, n); 141 TraceRecursive(parent1, fragment.Index2, n); 140 142 break; 141 143 } else { 142 144 // subtree and fragment are distinct. 143 g = parent s[0];145 g = parent0; 144 146 continue; 145 147 } … … 150 152 // mutation is handled in a simple way: we branch every time there is an overlap between the subtree and the fragment 151 153 // (since mutation effects can be quite unpredictable: replace branch, change node, shake tree, etc) 152 if (parents.Count == 1) { 154 if (inArcs.Count == 1) { 155 var parent0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[0].Source; 153 156 Debug.Assert(fragment.Index1 == fragment.Index2); 154 157 // check if the subtree and the fragment overlap => branch out … … 156 159 var n = GetTraceNode(g, si, fi); 157 160 int i = si < fi ? si : fi; 158 TraceRecursive(parent s[0], i, n);161 TraceRecursive(parent0, i, n); 159 162 break; 160 163 } else { 161 164 // if they don't overlap, go up 162 g = parent s[0];165 g = parent0; 163 166 if (fi < si) 164 167 si += NodeAt(g.Data, fi).GetLength() - fl; … … 212 215 /// <param name="last">The last added node in the trace graph</param> 213 216 private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last) { 214 IFragment<ISymbolicExpressionTreeNode> fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data : null; 217 var inArcs = (List<IArc>)((IVertex)g).InArcs; 218 var fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data : null; 215 219 int fi = fragment == null ? 0 : fragment.Index1; // fragment index 216 220 var n = GetTraceNode(g, si, fi); // will append n to the trace graph if it does not exist
Note: See TracChangeset
for help on using the changeset viewer.