本文整理汇总了C#中GraphToDSCompiler.Node.GetParents方法的典型用法代码示例。如果您正苦于以下问题:C# Node.GetParents方法的具体用法?C# Node.GetParents怎么用?C# Node.GetParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphToDSCompiler.Node
的用法示例。
在下文中一共展示了Node.GetParents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceNode
public bool ReplaceNode(Node replacement,Node toBeReplaced)
{
if (nodeMap.ContainsKey(replacement.Guid))
{
foreach (Node dad in toBeReplaced.GetParents())
{
//rem.RemoveEdgeTo(child);
dad.ReplaceChild(toBeReplaced,replacement);
}
nodeList.Remove(toBeReplaced);
nodeMap[replacement.Guid]=replacement;
nodeList.Add(replacement);
return true;
}
return false;
}
示例2: RemoveNode
/// <summary>
/// Removes the node passed as parameter from the graph(represented using NodeMap)
/// </summary>
/// <param name="rem"></param>
/// <returns></returns>
public bool RemoveNode(Node rem)
{
if (nodeMap.ContainsKey(rem.Guid))
{
IEnumerable iter = rem.GetChildren();
foreach (Node child in iter)
{
child.RemoveParent(rem);
}
iter = rem.GetParents();
foreach (Node dad in iter)
{
dad.RemoveChild(rem);
}
nodeMap.Remove(rem.Guid);
nodeList.Remove(rem);
return true;
}
return false;
}
示例3: RemoveAllEdges
/// <summary>
/// Remove all edges from or to the node passed as parameter.
/// </summary>
/// <param name="rem"></param>
/// <returns></returns>
public bool RemoveAllEdges(Node rem)
{
if (nodeMap.ContainsKey(rem.Guid))
{
IEnumerable iter = rem.GetChildren();
foreach (Node child in iter)
{
rem.RemoveChild(child);
child.RemoveParent(rem);
}
iter = rem.GetParents();
foreach (Node dad in iter)
{
rem.RemoveChild(dad);
dad.RemoveChild(rem);
}
return true;
}
return false;
}
示例4: DFS
private List<Node> DFS(Node node, AST graph, List<Node> input)
{
List<Node> result = new List<Node>();
//foreach (Node neighborNode in node.GetParents())
for (int i=0; i<node.GetParents().Count; i++)
{
Node neighborNode = node.GetParents()[i];
KeyValuePair<int, Node> item = neighborNode.children.FirstOrDefault(x => x.Value == node);
{
neighborNode.children.Remove(item.Key);
//item.Value.GetParents().Remove(neighborNode);
item.Value.GetParents().RemoveAll(x => x == neighborNode);
result.AddRange(DFS(neighborNode, graph, input));
item.Value.GetParents().Add(neighborNode);
neighborNode.children.Add(item.Key, item.Value);
}
}
//foreach (KeyValuePair<int, Node> neighborNode in node.children)
for (int i=0; i<node.children.Count; i++)
{
KeyValuePair<int, Node> neighborNode = node.children.ElementAt(i);
neighborNode.Value.GetParents().Remove(neighborNode.Value);
List<Node> parentNodeList = new List<Node>(neighborNode.Value.GetParents());
foreach (Node parentNode in parentNodeList)
{
parentNode.RemoveChild(neighborNode.Value);
}
result.AddRange(DFS(neighborNode.Value, graph, input));
foreach (Node parentNode in parentNodeList)
{
parentNode.children.Add(neighborNode.Key, neighborNode.Value);
}
neighborNode.Value.GetParents().Add(neighborNode.Value);
}
result.Add(node);
return result;
}
示例5: BFS
private List<Node> BFS(Node node, AST graph, List<Node> input)
{
List<uint> UIDlist = this.nodesToGuid(input);
List<Node> result = new List<Node>();
Queue<Node> mainQ = new Queue<Node>();
mainQ.Enqueue(node);
result.Add(node);
foreach (Node parentNode in node.GetParents())
{
if (UIDlist.Contains(parentNode.Guid))
{
mainQ.Enqueue(parentNode);
if (!result.Contains(parentNode))
{
result.Add(parentNode);
}
input.Remove(parentNode);
}
}
foreach (KeyValuePair<int, Node> childPair in node.children)
{
if (UIDlist.Contains(childPair.Value.Guid))
{
mainQ.Enqueue(childPair.Value);
if (!result.Contains(childPair.Value))
{
result.Add(childPair.Value);
}
input.Remove(childPair.Value);
}
}
while (mainQ.Count != 0)
{
Node topNode = mainQ.Dequeue();
foreach (Node parentNode in topNode.GetParents())
{
if (!result.Contains(parentNode) && UIDlist.Contains(parentNode.Guid))
{
mainQ.Enqueue(parentNode);
if (UIDlist.Contains(parentNode.Guid))
{
result.Add(parentNode);
input.Remove(parentNode);
}
}
}
foreach (KeyValuePair<int, Node> sonNodePair in topNode.children)
{
if (!result.Contains(sonNodePair.Value) && UIDlist.Contains(sonNodePair.Value.Guid))
{
mainQ.Enqueue(sonNodePair.Value);
if (UIDlist.Contains(sonNodePair.Value.Guid))
{
result.Add(sonNodePair.Value);
input.Remove(sonNodePair.Value);
}
}
}
}
return result;
}
示例6: DFS_Parent
private List<Node> DFS_Parent(Node node, AST graph, List<Node> input)
{
List<Node> result = new List<Node>();
if (input.Count == 0)
return result;
//if (input.Contains(node))
if (nodesToGuid(input).Contains(node.Guid))
result.Add(node);
foreach (Node parentNode in node.GetParents())
result.AddRange(DFS_Parent(parentNode, graph, input));
return result;
}