- Timestamp:
- 04/16/14 17:15:33 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10677 r10755 191 191 instrumentedManipulator.AfterExecutionOperators.Clear(); 192 192 instrumentedManipulator.BeforeExecutionOperators.Clear(); 193 if (EnableManipulatorTracking.Value && Manipulator != null) { 193 194 if (EnableManipulatorTracking.Value) { 194 195 if (BeforeManipulatorOperator != null) { 195 196 BeforeManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName; … … 222 223 if (elite != null) { 223 224 var vertex = new GenealogyGraphNode<T> { 224 Content = elite,225 Content = (T)elite.Clone(), 225 226 Rank = Generations.Value, 226 227 IsElite = true 227 228 }; 228 var previousVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite] .Last();229 var previousVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite]; 229 230 GenealogyGraph.AddVertex(vertex); 230 231 previousVertex.AddForwardArc(vertex); 231 232 vertex.AddReverseArc(previousVertex); 232 233 vertex.Id = previousVertex.Id; // another way would be to introduce the vertex.Id into the scope of the elite 234 vertex.Quality = previousVertex.Quality; 235 233 236 if (previousVertex.InArcs.Any()) { 234 237 vertex.InArcs.Last().Data = previousVertex.InArcs.Last().Data; // save the fragment in case there is one … … 238 241 // update qualities 239 242 for (int i = 0; i < population.Count; ++i) { 240 var individual = population[i]; 241 foreach (var vertex in GenealogyGraph[individual].Cast<IGenealogyGraphNode<T>>()) { 242 vertex.Quality = qualities[i].Value; 243 } 243 var vertex = (IGenealogyGraphNode)GenealogyGraph[population[i]]; 244 vertex.Quality = qualities[i].Value; 244 245 } 245 246 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r10677 r10755 38 38 } 39 39 [Storable] 40 private readonly Dictionary<object, List<IVertex>> contentMap;40 private readonly Dictionary<object, IVertex> contentMap; 41 41 public DirectedGraph() { 42 42 nodes = new List<IVertex>(); 43 contentMap = new Dictionary<object, List<IVertex>>();43 contentMap = new Dictionary<object, IVertex>(); 44 44 } 45 45 [StorableConstructor] … … 50 50 : base(original, cloner) { 51 51 nodes = new List<IVertex>(original.Nodes); 52 contentMap = new Dictionary<object, List<IVertex>>(original.contentMap);52 contentMap = new Dictionary<object, IVertex>(original.contentMap); 53 53 } 54 54 public override IDeepCloneable Clone(Cloner cloner) { … … 62 62 return contentMap.ContainsKey(content); 63 63 } 64 public List<IVertex>this[object key] {64 public IVertex this[object key] { 65 65 get { 66 List<IVertex>result;66 IVertex result; 67 67 contentMap.TryGetValue(key, out result); 68 68 return result; … … 80 80 } 81 81 public virtual void AddVertex(IVertex vertex) { 82 if (contentMap.ContainsKey(vertex.Content)) { 83 throw new Exception("Content already exists in the graph."); 84 } 85 contentMap[vertex.Content] = vertex; 82 86 Nodes.Add(vertex); 83 if (!contentMap.ContainsKey(vertex.Content))84 contentMap[vertex.Content] = new List<IVertex>();85 contentMap[vertex.Content].Add(vertex);86 87 } 87 88 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs
r10300 r10755 32 32 void RemoveVertex(IVertex vertex); 33 33 List<IVertex> Nodes { get; } 34 List<IVertex>this[object content] { get; }34 IVertex this[object content] { get; } 35 35 bool Contains(object content); 36 36 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Fragment.cs
r10650 r10755 8 8 public class Fragment : Item, IFragment { 9 9 [Storable] 10 public int Index { get; set; }10 public int Index1 { get; set; } 11 11 12 12 [Storable] 13 public int OldIndex{ get; set; }13 public int Index2 { get; set; } 14 14 15 15 [Storable] … … 23 23 : base(original, cloner) { 24 24 Root = original.Root; 25 Index = original.Index;26 OldIndex = original.OldIndex;25 Index1 = original.Index1; 26 Index2 = original.Index2; 27 27 } 28 28 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r10677 r10755 71 71 } 72 72 73 public new List<IGenealogyGraphNode>this[object content] {73 public new IGenealogyGraphNode this[object content] { 74 74 get { 75 75 var result = base[content]; 76 return result != null ? result.Cast<IGenealogyGraphNode>().ToList() : null;76 return result == null ? null : (IGenealogyGraphNode)result; 77 77 } 78 78 } … … 112 112 public override void AddVertex(IVertex vertex) { 113 113 var node = (IGenealogyGraphNode<T>)vertex; 114 if (!Ranks.ContainsKey(node.Rank)) 114 if (!Ranks.ContainsKey(node.Rank)) { 115 115 Ranks[node.Rank] = new LinkedList<IGenealogyGraphNode>(); 116 } 116 117 Ranks[node.Rank].AddLast(node); 117 118 base.AddVertex(vertex); … … 134 135 if (updated != null) updated(sender, args); 135 136 } 136 public new List<IGenealogyGraphNode<T>> this[object content] {137 public new IGenealogyGraphNode<T> this[object content] { 137 138 get { 138 139 var result = base[content]; 139 return result != null ? result.Cast<IGenealogyGraphNode<T>>().ToList() : null;140 return result == null ? null : (IGenealogyGraphNode<T>)result; 140 141 } 141 142 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Interfaces/IFragment.cs
r10650 r10755 25 25 public interface IFragment : IItem { 26 26 object Root { get; set; } 27 int Index { get; set; }28 int OldIndex{ get; set; }27 int Index1 { get; set; } 28 int Index2 { get; set; } 29 29 } 30 30 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10677 r10755 49 49 public override IOperation Apply() { 50 50 if (GenealogyGraph.Contains(ChildParameter.ActualValue)) { 51 // if the graph already contains a vertex representing the child, it means that the child is a product of crossover 52 // when mutation follows after crossover, some changes need to be made 51 53 var child = ChildParameter.ActualValue; 52 54 var clone = (T)child.Clone(); 53 var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child] .Last();55 var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child]; 54 56 var vClone = new GenealogyGraphNode<T> { Content = clone, Rank = vChild.Rank - 0.5 }; 55 57 GenealogyGraph.AddVertex(vClone); 56 58 // adjust parent-child(clone) relationship in the graph 57 var parents = vChild.InArcs.Select(a => a.Source); 59 var parents = vChild.Parents; 60 // if there's a fragment, save it 61 IFragment fragment = null; 62 if (vChild.InArcs.Last().Data != null) { 63 fragment = (IFragment<T>)vChild.InArcs.Last().Data; 64 } 58 65 vChild.InArcs = new List<IGenealogyGraphArc>(); 59 66 foreach (var p in parents) { 60 foreach (var a in p.OutArcs) { 61 if (a.Target == vChild) 62 a.Target = vClone; 67 foreach (var a in p.OutArcs.Where(a => a.Target == vChild)) { 68 a.Target = vClone; 63 69 } 64 70 vClone.AddReverseArc(p); … … 66 72 vChild.AddReverseArc(vClone); 67 73 vClone.AddForwardArc(vChild); 74 vClone.InArcs.Last().Data = fragment; 68 75 } else { // this needs to be checked 69 76 var vChild = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value };
Note: See TracChangeset
for help on using the changeset viewer.