Changeset 10833 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 05/11/14 00:03:36 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMaxCommonSequenceCalculator.cs
r10650 r10833 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 4 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Matching { 5 public class MaxCommonSequenceCalculator<T, U>26 public class MaxCommonSequenceCalculator<T, TComp> 6 27 where T : class 7 where U: IEqualityComparer<T> {28 where TComp : IEqualityComparer<T> { 8 29 9 public U Comparer { get; set; } 30 private TComp comparer; 31 public TComp Comparer { 32 get { return comparer; } 33 set { comparer = value; } 34 } 35 10 36 private int[,] matrix; 11 37 private List<T> sequence; 12 38 39 public MaxCommonSequenceCalculator(TComp comparer) { 40 this.comparer = comparer; 41 } 42 13 43 /// <summary> 14 /// Calculate the maximal common subsequence between arrays a and b and return it 44 /// Calculate the maximal common subsequence between arrays a and b and return it. 45 /// THIS DOES NOT WORK FOR TREES 15 46 /// </summary> 16 47 /// <param name="a"></param> … … 27 58 for (int i = 0; i <= m; ++i) { 28 59 for (int j = 0; j <= n; ++j) { 29 if (i == 0 || j == 0) { 30 matrix[i, j] = 0; 31 } else if (Comparer.Equals(a[i - 1], b[j - 1])) { 60 if (comparer.Equals(a[i - 1], b[j - 1])) { 32 61 matrix[i, j] = matrix[i - 1, j - 1] + 1; 33 62 } else { … … 36 65 } 37 66 } 38 recon(a, b, n, m);67 Recon(a, b, n, m); // build the common subsequence 39 68 return sequence; 40 69 } 41 70 42 private void recon(T[] a, T[] b, int i, int j) { 43 while (true) { 44 if (i == 0 || j == 0) return; 45 if (Comparer.Equals(a[i - 1], b[j - 1])) { 46 recon(a, b, i - 1, j - 1); 71 private void Recon(T[] a, T[] b, int i, int j) { 72 while (i > 0 && j > 0) { 73 if (comparer.Equals(a[i - 1], b[j - 1])) { 74 Recon(a, b, i - 1, j - 1); 47 75 sequence.Add(a[i - 1]); 48 76 } else if (matrix[i - 1, j] > matrix[i, j - 1]) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r10827 r10833 46 46 break; 47 47 } 48 //49 // if (fragment == null) {50 // throw new Exception("SymbolicDataAnalysisExpressionAfterCrossoverOperator: Could not identify fragment");51 // }52 48 53 49 arcs[0].Data = null; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs
r10827 r10833 57 57 } 58 58 59 // if (fragment == null) {60 // throw new Exception("SymbolicDataAnalysisExpressionAfterManipulatorOperator: Could not identify fragment");61 // }62 63 59 vChild.InArcs.First().Data = fragment; 64 60 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10755 r10833 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using HeuristicLab.Core; … … 35 34 36 35 for (int i = 0; i < parents.Count; ++i) { 37 var nodes = parents[i].IterateNodesPrefix().ToList(); 38 arcs[i].Data = nodes; 36 arcs[i].Data = parents[i].IterateNodesPrefix().ToList(); 39 37 } 40 var parentVertices = childVertex.Parents.ToList(); 41 if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) { 42 throw new Exception("Inconsistency detected in GenealogyGraph."); 43 } 38 39 // var parentVertices = childVertex.Parents.ToList(); 40 // 41 // if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) { 42 // throw new Exception("Inconsistency detected in GenealogyGraph."); 43 // } 44 44 45 45 return result; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r10827 r10833 33 33 vChild.InArcs.First().Data = vChild.Content.IterateNodesPrefix().ToList(); 34 34 35 var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source; 36 var fragment = (IFragment<ISymbolicExpressionTreeNode>)vClone.InArcs.Last().Data; 37 if (fragment != null) { 38 // this step must be performed because the fragment root actually references the original child (not the clone). 39 // then, a mutation operation (acting on the original child), could disrupt it 40 fragment.Root = vClone.Content.IterateNodesPrefix().ElementAt(fragment.Index1); 41 } 42 35 43 return result; 36 44 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10827 r10833 30 30 var fragmentNode = new FragmentNode { 31 31 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = node.Content.NodeAt(index) }, 32 Rank = node.Rank 32 Rank = node.Rank, 33 Quality = node.Quality 33 34 }; 34 35 if (parent != null) { … … 98 99 var fragmentNode = new FragmentNode { 99 100 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 100 Rank = node.Rank 101 Rank = node.Rank, 102 Quality = node.Quality 101 103 }; 102 104 if (parent != null) {
Note: See TracChangeset
for help on using the changeset viewer.