本文整理汇总了C#中IGraph.GetCompatibleNodes方法的典型用法代码示例。如果您正苦于以下问题:C# IGraph.GetCompatibleNodes方法的具体用法?C# IGraph.GetCompatibleNodes怎么用?C# IGraph.GetCompatibleNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraph
的用法示例。
在下文中一共展示了IGraph.GetCompatibleNodes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Nodes
/// <summary>
/// Returns the nodes in the graph of the type given, as set
/// </summary>
public static Dictionary<INode, SetValueType> Nodes(IGraph graph, NodeType nodeType, int threadId)
{
Dictionary<INode, SetValueType> nodesSet = new Dictionary<INode, SetValueType>();
foreach(INode node in graph.GetCompatibleNodes(nodeType))
{
nodesSet[node] = null;
}
return nodesSet;
}
示例2: Validate
/// <summary>
/// Checks whether a graph meets its connection assertions.
/// </summary>
/// <param name="graph">The graph to validate.</param>
/// <param name="mode">The validation mode to apply.</param>
/// <param name="errors">If the graph is not valid, this refers to a List of ConnectionAssertionError objects, otherwise it is null.</param>
/// <returns>True, if the graph is valid.</returns>
public static bool Validate(IGraph graph, ValidationMode mode, out List<ConnectionAssertionError> errors)
{
bool result = true;
Dictionary<IEdge, bool> checkedOutEdges = new Dictionary<IEdge, bool>(2 * graph.NumEdges);
Dictionary<IEdge, bool> checkedInEdges = new Dictionary<IEdge, bool>(2 * graph.NumEdges);
errors = new List<ConnectionAssertionError>();
int numConnectionAssertions = 0;
foreach(ValidateInfo valInfo in graph.Model.ValidateInfo)
{
// Check outgoing count on nodes of source type
foreach(INode node in graph.GetCompatibleNodes(valInfo.SourceType))
{
result &= ValidateSource(node, valInfo, errors, checkedOutEdges, checkedInEdges);
}
// Check incoming count on nodes of target type
foreach(INode node in graph.GetCompatibleNodes(valInfo.TargetType))
{
result &= ValidateTarget(node, valInfo, errors, checkedOutEdges, checkedInEdges);
}
++numConnectionAssertions;
}
if(mode == ValidationMode.StrictOnlySpecified)
{
Dictionary<EdgeType, bool> strictnessCheckedEdgeTypes = new Dictionary<EdgeType, bool>(2 * numConnectionAssertions);
foreach(ValidateInfo valInfo in graph.Model.ValidateInfo)
{
if(strictnessCheckedEdgeTypes.ContainsKey(valInfo.EdgeType))
continue;
foreach(IEdge edge in graph.GetExactEdges(valInfo.EdgeType))
{
// Some edges with connection assertions specified are not covered; strict only specified validation prohibits that!
if(!checkedOutEdges.ContainsKey(edge) || !checkedInEdges.ContainsKey(edge))
{
errors.Add(new ConnectionAssertionError(CAEType.EdgeNotSpecified, edge, 0, null));
result = false;
}
}
strictnessCheckedEdgeTypes.Add(valInfo.EdgeType, true);
}
}
if(mode == ValidationMode.Strict
&& (graph.NumEdges != checkedOutEdges.Count || graph.NumEdges != checkedInEdges.Count))
{
// Some edges are not covered; strict validation prohibits that!
foreach(IEdge edge in graph.Edges)
{
if(!checkedOutEdges.ContainsKey(edge) || !checkedInEdges.ContainsKey(edge))
{
errors.Add(new ConnectionAssertionError(CAEType.EdgeNotSpecified, edge, 0, null));
result = false;
}
}
}
if(result) errors = null;
return result;
}
示例3: DumpGroups
private static void DumpGroups(IGraph graph, Set<INode> nodes, DumpContext dc)
{
// Compute the nesting hierarchy (groups)
Dictionary<INode, DumpGroupNode> groupNodes = new Dictionary<INode, DumpGroupNode>();
Dictionary<INode, INode> containedIn = new Dictionary<INode, INode>();
Set<INode> groupedNodes = new Set<INode>();
// (by iterating the group node types in order of dump declaration and removing the iterated nodes from the available nodes,
// the conflict resolution priorities of debug enable are taken care of)
foreach(GroupNodeType groupNodeType in dc.DumpInfo.GroupNodeTypes)
{
foreach(INode node in graph.GetCompatibleNodes(groupNodeType.NodeType))
{
if(nodes.Contains(node))
{
if(!groupNodes.ContainsKey(node)) groupNodes.Add(node, new DumpGroupNode()); // todo: is the if needed?
nodes.Remove(node);
}
if(dc.DumpInfo.IsExcludedNodeType(node.Type)) continue;
foreach(IEdge edge in node.Incoming)
{
GroupMode grpMode = groupNodeType.GetEdgeGroupMode(edge.Type, edge.Source.Type);
if((grpMode & GroupMode.GroupIncomingNodes) == 0) continue;
if(!dc.Nodes.Contains(edge.Source)) continue;
groupNodes[node].groupedNodes.Add(edge.Source);
if(!containedIn.ContainsKey(edge.Source)) containedIn.Add(edge.Source, node); // crashes without if in case of multiple containment due to dump misspecification by user
groupedNodes.Add(edge.Source);
if((grpMode & GroupMode.Hidden) != 0) dc.ExcludedEdges.Add(edge);
}
foreach(IEdge edge in node.Outgoing)
{
GroupMode grpMode = groupNodeType.GetEdgeGroupMode(edge.Type, edge.Target.Type);
if((grpMode & GroupMode.GroupOutgoingNodes) == 0) continue;
if(!dc.Nodes.Contains(edge.Target)) continue;
groupNodes[node].groupedNodes.Add(edge.Target);
if(!containedIn.ContainsKey(edge.Target)) containedIn.Add(edge.Target, node); // crashes without if in case of multiple containment due to dump misspecification by user
groupedNodes.Add(edge.Target);
if((grpMode & GroupMode.Hidden) != 0) dc.ExcludedEdges.Add(edge);
}
}
}
// Dump the groups (begin at the roots of the group trees)
foreach(KeyValuePair<INode, DumpGroupNode> groupNode in groupNodes)
{
if(!containedIn.ContainsKey(groupNode.Key))
{
DumpGroupTree(groupNode.Key, groupNodes, dc);
DumpEdgesFromNode(groupNode.Key, dc);
}
}
// Dump the rest, which has not been grouped
nodes.Remove(groupedNodes);
foreach(INode node in nodes)
{
DumpNodeAndEdges(node, dc);
}
}