当前位置: 首页>>代码示例>>C#>>正文


C# ISymbolicExpressionTreeNode.IterateNodesPrefix方法代码示例

本文整理汇总了C#中ISymbolicExpressionTreeNode.IterateNodesPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbolicExpressionTreeNode.IterateNodesPrefix方法的具体用法?C# ISymbolicExpressionTreeNode.IterateNodesPrefix怎么用?C# ISymbolicExpressionTreeNode.IterateNodesPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISymbolicExpressionTreeNode的用法示例。


在下文中一共展示了ISymbolicExpressionTreeNode.IterateNodesPrefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Difference

 public static ISymbolicExpressionTreeNode Difference(this ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode other) {
   var a = node.IterateNodesPrefix().ToList();
   var b = other.IterateNodesPrefix().ToList();
   var list = new List<ISymbolicExpressionTreeNode>();
   for (int i = 0, j = 0; i < a.Count && j < b.Count; ++i, ++j) {
     var s1 = a[i].ToString();
     var s2 = b[j].ToString();
     if (s1 == s2) continue;
     list.Add(a[i]);
     // skip subtrees since the parents are already different
     i += a[i].SubtreeCount;
     j += b[j].SubtreeCount;
   }
   ISymbolicExpressionTreeNode result = list.Count > 0 ? LowestCommonAncestor(node, list) : null;
   return result;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:16,代码来源:SymbolicExpressionTreeMatching.cs

示例2: Compile

 private static IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper, IEnumerable<Func<Instruction, Instruction>> postInstructionCompiledHooks) {
   foreach (var node in branch.IterateNodesPrefix()) {
     Instruction instr = new Instruction();
     int subtreesCount = node.SubtreeCount;
     if (subtreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)");
     instr.nArguments = (byte)subtreesCount;
     instr.opCode = opCodeMapper(node);
     if (node.Symbol is Argument) {
       var argNode = (ArgumentTreeNode)node;
       instr.data = (ushort)argNode.Symbol.ArgumentIndex;
     }
     instr.dynamicNode = node;
     foreach (var hook in postInstructionCompiledHooks) {
       instr = hook(instr);
     }
     yield return instr;
   }
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:18,代码来源:SymbolicExpressionTreeCompiler.cs

示例3: ComputeBottomUpMapping

    public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
      var comparer = new SymbolicExpressionTreeNodeComparer(); // use a node comparer because it's faster than calling node.ToString() (strings are expensive) and comparing strings
      var compactedGraph = Compact(n1, n2);

      var forwardMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t1 => nodes of t2
      var reverseMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t2 => nodes of t1

      // visit nodes in order of decreasing height to ensure correct mapping
      var nodes1 = n1.IterateNodesPrefix().OrderByDescending(x => x.GetDepth()).ToList();
      var nodes2 = n2.IterateNodesPrefix().ToList();
      for (int i = 0; i < nodes1.Count; ++i) {
        var v = nodes1[i];
        if (forwardMap.ContainsKey(v))
          continue;
        var kv = compactedGraph[v];
        ISymbolicExpressionTreeNode w = null;
        for (int j = 0; j < nodes2.Count; ++j) {
          var t = nodes2[j];
          if (reverseMap.ContainsKey(t) || compactedGraph[t] != kv)
            continue;
          w = t;
          break;
        }
        if (w == null) continue;

        // at this point we know that v and w are isomorphic, however, the mapping cannot be done directly
        // (as in the paper) because the trees are unordered (subtree order might differ). the solution is 
        // to sort subtrees from under commutative labels (this will work because the subtrees are isomorphic!)
        // while iterating over the two subtrees
        var vv = IterateBreadthOrdered(v, comparer).ToList();
        var ww = IterateBreadthOrdered(w, comparer).ToList();
        int len = Math.Min(vv.Count, ww.Count);
        for (int j = 0; j < len; ++j) {
          var s = vv[j];
          var t = ww[j];
          Debug.Assert(!reverseMap.ContainsKey(t));

          forwardMap[s] = t;
          reverseMap[t] = s;
        }
      }

      return forwardMap;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:44,代码来源:SymbolicExpressionTreeBottomUpSimilarityCalculator.cs


注:本文中的ISymbolicExpressionTreeNode.IterateNodesPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。