Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/14 20:47:50 (10 years ago)
Author:
bburlacu
Message:

#1772: Added SymbolicDataAnalysisGenealogyView, updated generic analyzer and operators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r10278 r10285  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
     
    3234    where TVertex : class,IGenealogyGraphNode<TContent>, new()
    3335    where TContent : class,IItem {
    34     private string childParameterName;
    35     public string ChildParameterName {
    36       get { return childParameterName; }
    37       set {
    38         if (childParameterName != null && Parameters.ContainsKey(childParameterName)) Parameters.Remove(childParameterName);
    39         childParameterName = value;
    40         if (!Parameters.ContainsKey(childParameterName)) Parameters.Add(new LookupParameter<TContent>(childParameterName));
    41       }
    42     }
    4336
    44     #region parameter properties
    45     public ILookupParameter<TContent> ChildParameter {
    46       get { return (ILookupParameter<TContent>)Parameters[ChildParameterName]; }
    47     }
    48     #endregion
     37    private const string ChildParameterName = "Child";
     38    public ILookupParameter<TContent> ChildParameter;
     39
    4940    protected BeforeManipulatorOperator(BeforeManipulatorOperator<TGraph, TVertex, TContent> original, Cloner cloner)
    5041      : base(original, cloner) {
     
    5445    }
    5546
    56     public BeforeManipulatorOperator() { }
     47    public BeforeManipulatorOperator() {
     48      ChildParameter = new LookupParameter<TContent>(ChildParameterName);
     49      Parameters.Add(ChildParameter);
     50    }
    5751
    5852    public override IOperation Apply() {
    5953      if (GenealogyGraph.Contains(ChildParameter.ActualValue)) {
    6054        // if the individual has been affected by crossover before mutation, we keep it in the graph and feed a clone of it to the mutation operator
    61         ChildParameter.ActualValue = (TContent)ChildParameter.ActualValue.Clone();
     55        var child = ChildParameter.ActualValue;
     56        var clone = (TContent)child.Clone();
     57        var vertex = GenealogyGraph[child].Last();
     58        vertex.Content = clone;
     59        GenealogyGraph.Ranks[vertex.Rank].Remove(vertex);
     60        var newVertex = new TVertex {
     61          Content = child,
     62          Rank = vertex.Rank
     63        };
     64        vertex.Rank -= 0.5;
     65        if (!GenealogyGraph.Ranks.ContainsKey(vertex.Rank)) {
     66          GenealogyGraph.Ranks[vertex.Rank] = new LinkedList<TVertex>();
     67        }
     68        GenealogyGraph.Ranks[vertex.Rank].AddLast(vertex);
     69
     70        newVertex.AddForwardArc(vertex);
     71        vertex.AddReverseArc(vertex);
     72      } else {
     73        // mutation should never happen without crossover
    6274      }
    6375      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.