Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 19:35:34 (10 years ago)
Author:
bburlacu
Message:

#1772:

  • Removed unused code
  • Adapted genealogy graph according to the trunk changes to the directed graph
  • Adapted trace calculator and before/after operators
  • Introduced a CloneableCollection to help save node lists
Location:
branches/HeuristicLab.EvolutionTracking
Files:
2 added
5 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r11852 r11925  
    3737    private Dictionary<string, IGenealogyGraphNode> idMap;
    3838
    39     private readonly Comparison<IArc> compareArcs = (a, b) => {
     39    private readonly Comparison<IArc<IDeepCloneable>> compareArcs = (a, b) => {
    4040      if (a.Data == b.Data)
    4141        return 0;
     
    5656      RebuildDictionaries();
    5757
    58       foreach (var arcs in Vertices.Select(v => (List<IArc>)((IVertex)v).InArcs)) { arcs.Sort(compareArcs); }
     58      foreach (var arcs in Vertices.Select(v => v.InArcs.ToList())) { arcs.Sort(compareArcs); }
    5959    }
    6060    public override IDeepCloneable Clone(Cloner cloner) {
     
    6969    private void AfterDeserialization() {
    7070      RebuildDictionaries();
    71       foreach (var arcs in Vertices.Select(v => (List<IArc>)((Vertex)v).InArcs)) { arcs.Sort(compareArcs); }
     71      foreach (var arcs in Vertices.Select(v => v.InArcs.ToList())) { arcs.Sort(compareArcs); }
    7272    }
    7373    public GenealogyGraph() {
     
    169169      return ColorGradient.Colors[colorIndex];
    170170    }
    171 
    172     public override void AddVertices(IEnumerable<IVertex> vertexList) {
    173       base.AddVertices(vertexList);
    174       RebuildDictionaries();
    175     }
    176171  }
    177172
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs

    r11502 r11925  
    2727  [StorableClass]
    2828  [Item("GenealogyGraphArc", "A graph arc connecting two GenealogyGraphNodes and holding some data.")]
    29   public class GenealogyGraphArc : Arc, IGenealogyGraphArc {
     29  public class GenealogyGraphArc : Arc<IDeepCloneable>, IGenealogyGraphArc {
    3030    [StorableConstructor]
    3131    protected GenealogyGraphArc(bool deserializing) : base(deserializing) { }
     
    5555    [StorableConstructor]
    5656    protected GenealogyGraphArc(bool deserializing) : base(deserializing) { }
     57
    5758    protected GenealogyGraphArc(GenealogyGraphArc original, Cloner cloner)
    5859      : base(original, cloner) {
     
    6263      return new GenealogyGraphArc<T>(this, cloner);
    6364    }
     65
    6466    public new T Data {
    6567      get { return (T)base.Data; }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs

    r11858 r11925  
    3030  [StorableClass]
    3131  [Item("GenealogGraphNode", "A class representing a node in the GenealogyGraph")]
    32   public class GenealogyGraphNode : Vertex, IGenealogyGraphNode {
     32  public class GenealogyGraphNode : Vertex<IDeepCloneable>, IGenealogyGraphNode {
    3333    [StorableConstructor]
    3434    protected GenealogyGraphNode(bool deserializing) : base(deserializing) { }
     
    4646    }
    4747
     48    public GenealogyGraphNode() {
     49      Id = Guid.NewGuid().ToString();
     50    }
     51
    4852    public GenealogyGraphNode(IDeepCloneable data)
    49       : base(data) {
    50       Id = Guid.NewGuid().ToString();
     53      : this() {
     54      Data = data;
    5155    }
    5256
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphArc.cs

    r11253 r11925  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324
    2425namespace HeuristicLab.EvolutionTracking {
    25   public interface IGenealogyGraphArc : IArc {
     26  public interface IGenealogyGraphArc : IArc<IDeepCloneable> {
    2627    new IGenealogyGraphNode Source { get; }
    2728    new IGenealogyGraphNode Target { get; }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs

    r11253 r11925  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526
    2627namespace HeuristicLab.EvolutionTracking {
    27   public interface IGenealogyGraphNode : IVertex, IComparable<IGenealogyGraphNode> {
     28  public interface IGenealogyGraphNode : IVertex<IDeepCloneable>, IComparable<IGenealogyGraphNode> {
    2829    double Rank { get; set; }
    2930    double Quality { get; set; }
     
    3940  }
    4041
    41   public interface IGenealogyGraphNode<T> : IGenealogyGraphNode, IVertex<T> where T : class {
     42  public interface IGenealogyGraphNode<T> : IGenealogyGraphNode where T : class {
    4243    new IEnumerable<IGenealogyGraphNode<T>> Parents { get; }
    4344    new IEnumerable<IGenealogyGraphNode<T>> Children { get; }
    44 
    4545    new IEnumerable<IGenealogyGraphNode<T>> Ancestors { get; }
    4646    new IEnumerable<IGenealogyGraphNode<T>> Descendants { get; }
     47
     48    new T Data { get; set; }
    4749  }
    4850}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/HeuristicLab.EvolutionTracking-3.4.csproj

    r11639 r11925  
    110110  <ItemGroup>
    111111    <Compile Include="Analyzers\GenealogyAnalyzer.cs" />
     112    <Compile Include="Collections\CloneableCollection.cs" />
    112113    <Compile Include="Fragment.cs" />
    113114    <Compile Include="Interfaces\IFragment.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r11864 r11925  
    278278      <DependentUpon>VariableView.cs</DependentUpon>
    279279    </Compile>
    280     <Compile Include="Tracking\FragmentGraphView.cs">
    281       <SubType>UserControl</SubType>
    282     </Compile>
    283     <Compile Include="Tracking\FragmentGraphView.Designer.cs">
    284       <DependentUpon>FragmentGraphView.cs</DependentUpon>
    285     </Compile>
    286280    <Compile Include="Tracking\SymbolicDataAnalysisGenealogyGraphView.cs">
    287281      <SubType>UserControl</SubType>
     
    289283    <Compile Include="Tracking\SymbolicDataAnalysisGenealogyGraphView.Designer.cs">
    290284      <DependentUpon>SymbolicDataAnalysisGenealogyGraphView.cs</DependentUpon>
    291     </Compile>
    292     <Compile Include="Tracking\SymbolicDataAnalysisExpressionLineageExplorerView.cs">
    293       <SubType>UserControl</SubType>
    294     </Compile>
    295     <Compile Include="Tracking\SymbolicDataAnalysisExpressionLineageExplorerView.Designer.cs">
    296       <DependentUpon>SymbolicDataAnalysisExpressionLineageExplorerView.cs</DependentUpon>
    297     </Compile>
    298     <Compile Include="Tracking\SymbolicExpressionChartControl.cs">
    299       <SubType>UserControl</SubType>
    300     </Compile>
    301     <Compile Include="Tracking\SymbolicExpressionChartControl.Designer.cs">
    302       <DependentUpon>SymbolicExpressionChartControl.cs</DependentUpon>
    303285    </Compile>
    304286    <Compile Include="TreeEditDialogs\SymbolicExpressionTreeConstantNodeEditDialog.cs">
     
    384366      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    385367      <SubType>Designer</SubType>
    386     </EmbeddedResource>
    387     <EmbeddedResource Include="Tracking\SymbolicDataAnalysisGenealogyGraphView.resx">
    388       <DependentUpon>SymbolicDataAnalysisGenealogyGraphView.cs</DependentUpon>
    389368    </EmbeddedResource>
    390369  </ItemGroup>
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs

    r11881 r11925  
    8585        // that will include just the individual and its ancestors
    8686        var graph = new GenealogyGraph<ISymbolicExpressionTree>();
    87         var ancestors = new[] { graphNode }.Concat(graphNode.Ancestors);
    88         var cloned = ancestors.ToDictionary(x => x, x => cloner.Clone(x));
    89         graph.AddVertices(cloned.Values);
    90         foreach (var arc in cloned.Keys.SelectMany(x => x.InArcs)) {
    91           graph.AddArc(cloner.Clone(arc));
    92         }
     87        var ancestors = new[] { graphNode }.Concat(graphNode.Ancestors).ToList();
     88        graph.AddVertices(ancestors.Select(cloner.Clone));
     89        graph.AddArcs(ancestors.SelectMany(x => x.InArcs).Select(cloner.Clone));
    9390        MainFormManager.MainForm.ShowContent(graph);
    9491      }
     
    185182    private void navigateRightButton_Click(object sender, EventArgs e) {
    186183      var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode;
    187       var inArcs = (List<IArc>)((IVertex)graphNode).InArcs;
     184      var inArcs = graphNode.InArcs.ToList();
    188185      if (inArcs.Count > 0) {
    189186        var data = inArcs.Last().Data;
     
    205202          for (int i = 1; i < inArcs.Count; ++i) {
    206203            td = (TraceData)inArcs[i].Data;
    207             var f2 = ((ISymbolicExpressionTree)inArcs[i].Source.Data).NodeAt(td.SubtreeIndex);
     204            var f2 = ((IGenealogyGraphNode<ISymbolicExpressionTree>)inArcs[i].Source).Data.NodeAt(td.SubtreeIndex);
    208205            // if the subtrees are the same we have found a match
    209206            // note: this is not necessarily 100% correct if in the trace graph we have identical fragments on different arcs
     
    218215    }
    219216  }
    220 
    221217  public class SymbolicDataAnalysisGenealogyGraphViewDesignable : GenealogyGraphView<ISymbolicExpressionTree> { }
     218
     219  internal static class Util {
     220    internal static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) {
     221      return NodeAt(tree.Root, position);
     222    }
     223    internal static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTreeNode root, int position) {
     224      return root.IterateNodesPrefix().ElementAt(position);
     225    }
     226  }
    222227}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11858 r11925  
    321321    <Compile Include="Tracking\TraceCalculator.cs" />
    322322    <Compile Include="TransformationToSymbolicTreeMapper.cs" />
    323     <Compile Include="Tracking\FragmentGraph\FragmentGraph.cs" />
    324323    <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs" />
    325324    <Compile Include="Tracking\SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs

    r11852 r11925  
    4949
    5050      for (int i = 0; i < parents.Count; ++i) {
    51         arcs[i].Data = parents[i].IterateNodesPrefix().ToList();
     51        arcs[i].Data = parents[i].IterateNodesPrefix().ToCloneableCollection();
    5252      }
    5353
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r11881 r11925  
    9595        Debug.Assert(si < g.Data.Length);
    9696        var inArcs = (List<IArc>)((IVertex)g).InArcs;
    97         var fragment = (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data;
     97        var fragment = (IFragment<ISymbolicExpressionTreeNode>)((IGenealogyGraphArc)inArcs.Last()).Data;
    9898        if (fragment == null) {
    9999          // TODO: think about what the correct behavior should be here (seems good so far)
     
    225225  }
    226226  // this class is here to help clarify the semantics
    227   public class TraceData : Tuple<int, int, int, int> {
     227  public class TraceData : Tuple<int, int, int, int>, IDeepCloneable {
    228228    public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex)
    229229      : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) {
     
    234234    public int LastSubtreeIndex { get { return Item3; } }
    235235    public int LastFragmentIndex { get { return Item4; } }
     236    public object Clone() {
     237      return new TraceData(SubtreeIndex, FragmentIndex, LastSubtreeIndex, LastFragmentIndex);
     238    }
     239
     240    public IDeepCloneable Clone(Cloner cloner) {
     241      return cloner.Clone(this);
     242    }
    236243  }
    237244
Note: See TracChangeset for help on using the changeset viewer.