Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/14 17:15:33 (10 years ago)
Author:
bburlacu
Message:

#1772: Simplified genealogy graph and fragment graph creation:

  • the genealogy graph now has a 1-1 mapping between content and vertices (as opposed to 1-n as it was previously, to account for elites); this required changes to the directed graph implementation
  • the fragment graph only contains bifurcation points (where the subtree contains the fragment so tracing must be done both ways (in the root parent AND in the other parent). in the other cases, tracing is restarted from the parent genealogy graph node.
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  
    191191        instrumentedManipulator.AfterExecutionOperators.Clear();
    192192        instrumentedManipulator.BeforeExecutionOperators.Clear();
    193         if (EnableManipulatorTracking.Value && Manipulator != null) {
     193
     194        if (EnableManipulatorTracking.Value) {
    194195          if (BeforeManipulatorOperator != null) {
    195196            BeforeManipulatorOperator.ChildParameter.ActualName = ManipulatorChildParameterName;
     
    222223        if (elite != null) {
    223224          var vertex = new GenealogyGraphNode<T> {
    224             Content = elite,
     225            Content = (T)elite.Clone(),
    225226            Rank = Generations.Value,
    226227            IsElite = true
    227228          };
    228           var previousVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite].Last();
     229          var previousVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite];
    229230          GenealogyGraph.AddVertex(vertex);
    230231          previousVertex.AddForwardArc(vertex);
    231232          vertex.AddReverseArc(previousVertex);
    232233          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
    233236          if (previousVertex.InArcs.Any()) {
    234237            vertex.InArcs.Last().Data = previousVertex.InArcs.Last().Data; // save the fragment in case there is one
     
    238241      // update qualities
    239242      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;
    244245      }
    245246
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs

    r10677 r10755  
    3838    }
    3939    [Storable]
    40     private readonly Dictionary<object, List<IVertex>> contentMap;
     40    private readonly Dictionary<object, IVertex> contentMap;
    4141    public DirectedGraph() {
    4242      nodes = new List<IVertex>();
    43       contentMap = new Dictionary<object, List<IVertex>>();
     43      contentMap = new Dictionary<object, IVertex>();
    4444    }
    4545    [StorableConstructor]
     
    5050      : base(original, cloner) {
    5151      nodes = new List<IVertex>(original.Nodes);
    52       contentMap = new Dictionary<object, List<IVertex>>(original.contentMap);
     52      contentMap = new Dictionary<object, IVertex>(original.contentMap);
    5353    }
    5454    public override IDeepCloneable Clone(Cloner cloner) {
     
    6262      return contentMap.ContainsKey(content);
    6363    }
    64     public List<IVertex> this[object key] {
     64    public IVertex this[object key] {
    6565      get {
    66         List<IVertex> result;
     66        IVertex result;
    6767        contentMap.TryGetValue(key, out result);
    6868        return result;
     
    8080    }
    8181    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;
    8286      Nodes.Add(vertex);
    83       if (!contentMap.ContainsKey(vertex.Content))
    84         contentMap[vertex.Content] = new List<IVertex>();
    85       contentMap[vertex.Content].Add(vertex);
    8687    }
    8788
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs

    r10300 r10755  
    3232    void RemoveVertex(IVertex vertex);
    3333    List<IVertex> Nodes { get; }
    34     List<IVertex> this[object content] { get; }
     34    IVertex this[object content] { get; }
    3535    bool Contains(object content);
    3636  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Fragment.cs

    r10650 r10755  
    88  public class Fragment : Item, IFragment {
    99    [Storable]
    10     public int Index { get; set; }
     10    public int Index1 { get; set; }
    1111
    1212    [Storable]
    13     public int OldIndex { get; set; }
     13    public int Index2 { get; set; }
    1414
    1515    [Storable]
     
    2323      : base(original, cloner) {
    2424      Root = original.Root;
    25       Index = original.Index;
    26       OldIndex = original.OldIndex;
     25      Index1 = original.Index1;
     26      Index2 = original.Index2;
    2727    }
    2828    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r10677 r10755  
    7171    }
    7272
    73     public new List<IGenealogyGraphNode> this[object content] {
     73    public new IGenealogyGraphNode this[object content] {
    7474      get {
    7575        var result = base[content];
    76         return result != null ? result.Cast<IGenealogyGraphNode>().ToList() : null;
     76        return result == null ? null : (IGenealogyGraphNode)result;
    7777      }
    7878    }
     
    112112    public override void AddVertex(IVertex vertex) {
    113113      var node = (IGenealogyGraphNode<T>)vertex;
    114       if (!Ranks.ContainsKey(node.Rank))
     114      if (!Ranks.ContainsKey(node.Rank)) {
    115115        Ranks[node.Rank] = new LinkedList<IGenealogyGraphNode>();
     116      }
    116117      Ranks[node.Rank].AddLast(node);
    117118      base.AddVertex(vertex);
     
    134135      if (updated != null) updated(sender, args);
    135136    }
    136     public new List<IGenealogyGraphNode<T>> this[object content] {
     137    public new IGenealogyGraphNode<T> this[object content] {
    137138      get {
    138139        var result = base[content];
    139         return result != null ? result.Cast<IGenealogyGraphNode<T>>().ToList() : null;
     140        return result == null ? null : (IGenealogyGraphNode<T>)result;
    140141      }
    141142    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Interfaces/IFragment.cs

    r10650 r10755  
    2525  public interface IFragment : IItem {
    2626    object Root { get; set; }
    27     int Index { get; set; }
    28     int OldIndex { get; set; }
     27    int Index1 { get; set; }
     28    int Index2 { get; set; }
    2929  }
    3030
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r10677 r10755  
    4949    public override IOperation Apply() {
    5050      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
    5153        var child = ChildParameter.ActualValue;
    5254        var clone = (T)child.Clone();
    53         var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child].Last();
     55        var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child];
    5456        var vClone = new GenealogyGraphNode<T> { Content = clone, Rank = vChild.Rank - 0.5 };
    5557        GenealogyGraph.AddVertex(vClone);
    5658        // 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        }
    5865        vChild.InArcs = new List<IGenealogyGraphArc>();
    5966        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;
    6369          }
    6470          vClone.AddReverseArc(p);
     
    6672        vChild.AddReverseArc(vClone);
    6773        vClone.AddForwardArc(vChild);
     74        vClone.InArcs.Last().Data = fragment;
    6875      } else { // this needs to be checked
    6976        var vChild = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value };
Note: See TracChangeset for help on using the changeset viewer.