Changeset 10285 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterCrossoverOperator.cs
- Timestamp:
- 01/05/14 20:47:50 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/AfterCrossoverOperator.cs
r10278 r10285 33 33 where TVertex : class,IGenealogyGraphNode<TContent>, new() 34 34 where TContent : class,IItem { 35 36 private string parentsParameterName; 37 public string ParentsParameterName { 38 get { return parentsParameterName; } 39 set { 40 if (parentsParameterName != null && Parameters.ContainsKey(parentsParameterName)) Parameters.Remove(parentsParameterName); // remove old parameter 41 parentsParameterName = value; 42 if (!Parameters.ContainsKey(parentsParameterName)) Parameters.Add(new ScopeTreeLookupParameter<TContent>(parentsParameterName)); 43 } 44 } 45 private string childParameterName; 46 public string ChildParameterName { 47 get { return childParameterName; } 48 set { 49 if (childParameterName != null && Parameters.ContainsKey(childParameterName)) Parameters.Remove(childParameterName); 50 childParameterName = value; 51 if (!Parameters.ContainsKey(childParameterName)) Parameters.Add(new LookupParameter<TContent>(childParameterName)); 52 } 53 } 54 55 public IScopeTreeLookupParameter<TContent> ParentsParameter { 56 get { return (IScopeTreeLookupParameter<TContent>)Parameters[ParentsParameterName]; } 57 } 58 59 public ILookupParameter<TContent> ChildParameter { 60 get { return (ILookupParameter<TContent>)Parameters[ChildParameterName]; } 61 } 35 private const string defaultParentsParameterName = "Parents"; 36 private const string defaultChildParameterName = "Child"; 37 public IScopeTreeLookupParameter<TContent> ParentsParameter; 38 public ILookupParameter<TContent> ChildParameter; 62 39 63 40 protected AfterCrossoverOperator(AfterCrossoverOperator<TGraph, TVertex, TContent> original, Cloner cloner) 64 41 : base(original, cloner) { 65 ParentsParameterName = original.ParentsParameterName;66 ChildParameterName = original.ChildParameterName;67 42 } 68 43 public override IDeepCloneable Clone(Cloner cloner) { … … 70 45 } 71 46 72 public AfterCrossoverOperator() { } 47 public AfterCrossoverOperator() { 48 ParentsParameter = new ScopeTreeLookupParameter<TContent>(defaultParentsParameterName); 49 ChildParameter = new LookupParameter<TContent>(defaultChildParameterName); 50 Parameters.Add(ParentsParameter); 51 Parameters.Add(ChildParameter); 52 } 73 53 74 54 public override IOperation Apply() { 75 55 // var parentVertices = ParentsParameter.ActualValue.Select(x => GenealogyGraph[x].Last()).ToList(); 76 56 var lastGen = GenealogyGraph.Ranks[Generations.Value].ToList(); 77 var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => lastGen[int.Parse(s.Name)]).ToList(); 57 var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => lastGen[int.Parse(s.Name)]).ToList(); // because the individuals in the execution scope are copies of the ones in the graph 58 78 59 var childVertex = new TVertex { 79 60 Content = ChildParameter.ActualValue, … … 85 66 v.AddForwardArc(childVertex); 86 67 } 68 // if (parentVertices[0].Content == parentVertices[1].Content) 69 // throw new Exception("Self-crossover"); 87 70 return base.Apply(); 88 71 }
Note: See TracChangeset
for help on using the changeset viewer.