Changeset 9293 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 03/07/13 14:53:43 (12 years ago)
- Location:
- branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r9241 r9293 50 50 <DebugType>pdbonly</DebugType> 51 51 <Optimize>true</Optimize> 52 <OutputPath>..\..\..\..\ Trunk\sources\bin\</OutputPath>52 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 53 53 <DefineConstants>TRACE</DefineConstants> 54 54 <ErrorReport>prompt</ErrorReport> … … 66 66 </PropertyGroup> 67 67 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 68 <OutputPath> $(SolutionDir)\bin\</OutputPath>68 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 69 69 <DefineConstants>TRACE</DefineConstants> 70 70 <Optimize>true</Optimize> … … 84 84 </PropertyGroup> 85 85 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 86 <OutputPath> $(SolutionDir)\bin\</OutputPath>86 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 87 87 <DefineConstants>TRACE</DefineConstants> 88 88 <Optimize>true</Optimize> … … 200 200 <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" /> 201 201 <Compile Include="SymbolicDataAnalysisExpressionTreeMatching.cs" /> 202 <Compile Include="SymbolicDataAnalysisExpressionTreeSimilarity.cs" /> 202 203 <Compile Include="SymbolicDataAnalysisModel.cs"> 203 204 <SubType>Code</SubType> -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeMatching.cs
r9249 r9293 161 161 162 162 public static class SymbolicExpressionTreeMatching { 163 public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {164 return t1.Root.IsSimilarTo(t2.Root, comparer);165 }166 public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {167 return Match(t1, t2, comparer) == Math.Min(t1.GetLength(), t2.GetLength());168 }169 163 public static bool ContainsFragment(this ISymbolicExpressionTreeNode root, IFragment fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 170 164 return FindMatches(root, fragment.Root, comparer).Any(); … … 179 173 // below, we use ">=" for Match(n, fragment, comp) >= fragmentLength because in case of relaxed conditions, 180 174 // we can have multiple matches of the same node 175 181 176 return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, fragment, comp) == fragmentLength); 182 177 } … … 206 201 } 207 202 } 203 204 public class MaximalCommonSubsequenceCalculator { 205 private ISymbolicExpressionTreeNode[] x; 206 private ISymbolicExpressionTreeNode[] y; 207 private List<ISymbolicExpressionTreeNode> maxCommonSubseq; 208 private double[,] matrix; 209 210 public SymbolicExpressionTreeNodeSimilarityComparer comparer; 211 212 public List<ISymbolicExpressionTreeNode> Calculate(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) { 213 if (comparer == null) throw new Exception("Comparer cannot be null."); 214 215 x = n1.IterateNodesPrefix().ToArray(); 216 y = n2.IterateNodesPrefix().ToArray(); 217 218 if (maxCommonSubseq == null) maxCommonSubseq = new List<ISymbolicExpressionTreeNode>(); 219 else maxCommonSubseq.Clear(); 220 221 int n = x.Length; 222 int m = y.Length; 223 224 matrix = new double[n + 1, m + 1]; 225 226 for (int i = 0; i <= n; ++i) { 227 for (int j = 0; j <= m; ++j) { 228 if (i == 0 || j == 0) { 229 matrix[i, j] = 0; 230 } else if (comparer.Equals(x[i - 1], y[j - 1])) { 231 matrix[i, j] = matrix[i - 1, j - 1] + 1; 232 } else { 233 matrix[i, j] = Math.Max(matrix[i - 1, j], matrix[i, j - 1]); 234 } 235 } 236 } 237 recon(n, m); 238 return new List<ISymbolicExpressionTreeNode>(maxCommonSubseq); 239 } 240 241 private void recon(int i, int j) { 242 if (i == 0 || j == 0) return; 243 if (comparer.Equals(x[i - 1], y[j - 1])) { 244 recon(i - 1, j - 1); 245 maxCommonSubseq.Add(x[i - 1]); 246 } else if (matrix[i - 1, j] > matrix[i, j - 1]) { 247 recon(i - 1, j); 248 } else recon(i, j - 1); 249 } 250 }
Note: See TracChangeset
for help on using the changeset viewer.