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


C# IGraph.GetCompatibleNodes方法代码示例

本文整理汇总了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;
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:12,代码来源:GraphHelperParallel.cs

示例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;
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:69,代码来源:GraphValidator.cs

示例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);
            }
        }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:62,代码来源:GraphDumper.cs


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