Changeset 10674 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 03/26/14 17:14:14 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10650 r10674 211 211 ConfigureTrackingOperators(); 212 212 213 foreach (var individual in population) { 213 for (int i = 0; i < population.Count; ++i) { 214 var individual = population[i]; 214 215 var vertex = new GenealogyGraphNode<T> { Content = individual, Rank = Generations.Value, }; 215 216 GenealogyGraph.AddVertex(vertex); 217 // save the vertex id in the individual scope (so that we can identify graph indices) 218 ExecutionContext.Scope.SubScopes[i].Variables.Add(new Variable("Id", new StringValue(vertex.Id))); 216 219 } 217 220 } else { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
r10650 r10674 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 63 64 if (CurrentGeneration == null) throw new Exception(); 64 65 // we get the parents by parsing the scope name because the individuals in the execution scope are clones of the ones saved in the graph 65 var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration[int.Parse(s.Name)]).ToList(); 66 // var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration.Find(x => x.Id == ((StringValue)s.Variables["Id"].Value)).ToList(); 67 var parentVertices = (from s in ExecutionContext.Scope.SubScopes 68 let id = ((StringValue)s.Variables["Id"].Value).Value 69 select CurrentGeneration.First(x => x.Id == id)).ToList(); // the id is unique 66 70 67 71 var parents = ParentsParameter.ActualValue.ToList(); … … 77 81 v.AddForwardArc(childVertex); 78 82 } 83 ExecutionContext.Scope.Variables.Add(new Variable("Id", new StringValue(childVertex.Id))); 79 84 80 85 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymboldDataAnalysisGenealogyView.cs
r10656 r10674 177 177 // the subtree must belong to the currently displayed tree which in turn must belong to the currently selected graph node 178 178 var tree = graphNode.Content; 179 var index = tree.IterateNodesPrefix().ToList().IndexOf(subtree);180 var length = subtree.GetLength();179 var subtreeIndex = tree.IterateNodesPrefix().ToList().IndexOf(subtree); 180 var subtreeLength = subtree.GetLength(); 181 181 182 182 var fragment = (IFragment<ISymbolicExpressionTreeNode>)graphNode.InArcs.Last().Data; … … 184 184 var fragmentLength = fragment.Root.GetLength(); 185 185 186 FragmentNode node = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank }; 187 if (parentNode != null) { 188 AddChild(parentNode, node); 189 } 190 fragmentGraph.AddVertex(node); 186 191 187 192 // below, we consider three cases: … … 190 195 // 3) the fragment is contained by the selected subtree 191 196 // In each case, the idea is to isolate and individually track the fragment and the rest of the subtree (for cases 2 and 3) 192 if (fragment.Index == index) {197 if (fragment.Index == subtreeIndex) { 193 198 // the selected subtree is the actual fragment 194 if (fragmentLength != length) throw new Exception("Fragment and subtree lengths should be the same!"); 195 196 var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank }; 197 198 if (parentNode != null) { 199 AddChild(parentNode, node); 200 } 201 202 fragmentGraph.AddVertex(node); 199 if (fragmentLength != subtreeLength) throw new Exception("Fragment and subtree lengths should be the same!"); 203 200 204 201 var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 205 202 var s = g.Content.IterateNodesPrefix().ToList()[fragment.OldIndex]; 206 203 Trace(g, s, fragmentGraph, node); 207 } else if (fragment.Index < index && index < fragment.Index + fragmentLength) { 204 205 } else if (fragment.Index < subtreeIndex && subtreeIndex < fragment.Index + fragmentLength) { 208 206 // the fragment contains the selected subtree 209 if (length >= fragmentLength) throw new Exception("Fragment contains subtree, so subtree length should be less than the fragment length."); 210 211 var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank }; 212 if (parentNode != null) { 213 AddChild(parentNode, node); 214 } 215 216 fragmentGraph.AddVertex(node); 207 if (subtreeLength >= fragmentLength) throw new Exception("Fragment contains subtree, so subtree length should be less than the fragment length."); 217 208 218 209 var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 219 var i = fragment.Root.IterateNodesPrefix().ToList().IndexOf(subtree); 210 var i = fragment.Root.IterateNodesPrefix().ToList().IndexOf(subtree); // get the index of the selected subtree, relative to the fragment root 220 211 var s = g.Content.IterateNodesPrefix().ToList()[fragment.OldIndex + i]; 221 212 Trace(g, s, fragmentGraph, node); 222 213 223 } else if ( index < fragment.Index && fragment.Index < index + length) {214 } else if (subtreeIndex < fragment.Index && fragment.Index < subtreeIndex + subtreeLength) { 224 215 // the selected subtree contains the fragment 225 if (fragmentLength >= length) 226 throw new Exception("Subtree contains fragment, so fragment length should be less than the subtree length."); 227 228 var node = new FragmentNode { 229 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 230 Rank = graphNode.Rank 231 }; 232 233 if (parentNode != null) { 234 AddChild(parentNode, node); 235 } 236 fragmentGraph.AddVertex(node); 216 if (fragmentLength >= subtreeLength) throw new Exception("Subtree contains fragment, so fragment length should be less than the subtree length."); 237 217 238 218 var g0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source; 239 var s0 = g0.Content.IterateNodesPrefix().ToList()[ index];219 var s0 = g0.Content.IterateNodesPrefix().ToList()[subtreeIndex]; 240 220 Trace(g0, s0, fragmentGraph, node); 241 221 … … 247 227 } else { 248 228 // fragment and subtree are completely distinct, therefore we will track the subtree 249 var node = new FragmentNode {250 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },251 Rank = graphNode.Rank252 };253 254 if (parentNode != null) {255 AddChild(parentNode, node);256 }257 fragmentGraph.AddVertex(node);258 229 var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source; 259 var s = graphNode.Content.IterateNodesPrefix().ToList()[ index];230 var s = graphNode.Content.IterateNodesPrefix().ToList()[subtreeIndex]; 260 231 Trace(g, s, fragmentGraph, node); 261 232 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10654 r10674 1 using System.Linq; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 23 using System.Linq; 2 24 using HeuristicLab.Core; 3 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 9 31 var result = base.Apply(); // the child will be added to the graph before the crossover 10 32 var parents = ParentsParameter.ActualValue.ToList(); 11 var childVertex = GenealogyGraph[parents[0]].Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet) 12 // var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration[int.Parse(s.Name)]).ToList(); 33 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[parents[0]].Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet) 13 34 14 // we add the breadth list of nodes of each parent as the data element of the arc from the parent to the child15 35 for (int i = 0; i < parents.Count; ++i) { 16 36 var nodes = parents[i].IterateNodesPrefix().ToList(); 17 var arc = (IGenealogyGraphArc)childVertex.InArcs[i];37 var arc = childVertex.InArcs[i]; 18 38 arc.Data = nodes; 39 } 40 var parentVertices = childVertex.InArcs.Select(x => (IGenealogyGraphNode<ISymbolicExpressionTree>)x.Source).ToList(); 41 if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) { 42 throw new Exception("Inconsistency detected in GenealogyGraph."); 19 43 } 20 44
Note: See TracChangeset
for help on using the changeset viewer.