本文整理汇总了C#中ISymbolicExpressionTreeNode.IterateNodesPostfix方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbolicExpressionTreeNode.IterateNodesPostfix方法的具体用法?C# ISymbolicExpressionTreeNode.IterateNodesPostfix怎么用?C# ISymbolicExpressionTreeNode.IterateNodesPostfix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbolicExpressionTreeNode
的用法示例。
在下文中一共展示了ISymbolicExpressionTreeNode.IterateNodesPostfix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: copySubtree
private void copySubtree() {
if (tempNode != null) {
foreach (var subtree in tempNode.IterateNodesPostfix()) {
var visualNode = GetVisualSymbolicExpressionTreeNode(subtree);
visualNode.LineColor = Color.Black;
visualNode.TextColor = Color.Black;
if (subtree.Parent != null) {
var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(subtree.Parent, subtree);
visualLine.LineColor = Color.Black;
}
}
}
tempNode = currSelected.Content;
foreach (var node in tempNode.IterateNodesPostfix()) {
var visualNode = GetVisualSymbolicExpressionTreeNode(node);
visualNode.LineColor = Color.LightGray;
visualNode.TextColor = Color.LightGray;
foreach (var subtree in node.Subtrees) {
var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree);
visualLine.LineColor = Color.LightGray;
}
}
currSelected = null;
RepaintNodes(); // no need to redo the layout and repaint everything since this operation does not change the tree
}
示例2: Compact
/// <summary>
/// Creates a compact representation of the two trees as a directed acyclic graph
/// </summary>
/// <param name="n1">The root of the first tree</param>
/// <param name="n2">The root of the second tree</param>
/// <returns>The compacted DAG representing the two trees</returns>
private Dictionary<ISymbolicExpressionTreeNode, GraphNode> Compact(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
var nodeMap = new Dictionary<ISymbolicExpressionTreeNode, GraphNode>(); // K
var labelMap = new Dictionary<string, GraphNode>(); // L
var childrenCount = new Dictionary<ISymbolicExpressionTreeNode, int>(); // Children
var nodes = n1.IterateNodesPostfix().Concat(n2.IterateNodesPostfix()); // the disjoint union F
var list = new List<GraphNode>();
var queue = new Queue<ISymbolicExpressionTreeNode>();
foreach (var n in nodes) {
if (n.SubtreeCount == 0) {
var label = GetLabel(n);
if (!labelMap.ContainsKey(label)) {
var z = new GraphNode { SymbolicExpressionTreeNode = n, Label = label };
labelMap[z.Label] = z;
}
nodeMap[n] = labelMap[label];
queue.Enqueue(n);
} else {
childrenCount[n] = n.SubtreeCount;
}
}
while (queue.Any()) {
var n = queue.Dequeue();
if (n.SubtreeCount > 0) {
bool found = false;
var label = n.Symbol.Name;
var depth = n.GetDepth();
bool sort = n.SubtreeCount > 1 && commutativeSymbols.Contains(label);
var nSubtrees = n.Subtrees.Select(x => nodeMap[x]).ToList();
if (sort) nSubtrees.Sort((a, b) => string.CompareOrdinal(a.Label, b.Label));
for (int i = list.Count - 1; i >= 0; --i) {
var w = list[i];
if (!(n.SubtreeCount == w.SubtreeCount && label == w.Label && depth == w.Depth))
continue;
// sort V and W when the symbol is commutative because we are dealing with unordered trees
var m = w.SymbolicExpressionTreeNode;
var mSubtrees = m.Subtrees.Select(x => nodeMap[x]).ToList();
if (sort) mSubtrees.Sort((a, b) => string.CompareOrdinal(a.Label, b.Label));
found = nSubtrees.SequenceEqual(mSubtrees);
if (found) {
nodeMap[n] = w;
break;
}
}
if (!found) {
var w = new GraphNode { SymbolicExpressionTreeNode = n, Label = label, Depth = depth };
list.Add(w);
nodeMap[n] = w;
}
}
if (n == n1 || n == n2)
continue;
var p = n.Parent;
if (p == null)
continue;
childrenCount[p]--;
if (childrenCount[p] == 0)
queue.Enqueue(p);
}
return nodeMap;
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:78,代码来源:SymbolicExpressionTreeBottomUpSimilarityCalculator.cs