예제 #1
0
 private static VFlibcs.Graph TransToVFGraph(Node node)
 {
     nodeDictionary.Clear();
     _usedEdge.Clear();
     VFlibcs.Graph result = new VFlibcs.Graph();
     nodeDictionary.Add(node, result.InsertNode(node));
     InsertGraph(result, node);
     return(result);
 }
예제 #2
0
 // DFS Insert node.
 private static void InsertGraph(VFlibcs.Graph graph, Node node)
 {
     foreach (Node child in node.Children)
     {
         if (child == null)
         {
             continue;
         }
         // If the node have not set then set it.
         if (!nodeDictionary.ContainsKey(child))
         {
             nodeDictionary.Add(child, graph.InsertNode(child));
         }
         string stringEdge = nodeDictionary[node] + "+" + nodeDictionary[child];
         if (_usedEdge.Exists(x => x == stringEdge))
         {
             continue;
         }
         // Set edge.
         graph.InsertEdge(nodeDictionary[node], nodeDictionary[child]);
         _usedEdge.Add(stringEdge);
         InsertGraph(graph, child);
     }
     foreach (var parent in node.Parents)
     {
         if (parent == null)
         {
             continue;
         }
         // If the node have not set then set it.
         if (!nodeDictionary.ContainsKey(parent))
         {
             nodeDictionary.Add(parent, graph.InsertNode(parent));
         }
         string stringEdge = nodeDictionary[parent] + "+" + nodeDictionary[node];
         if (_usedEdge.Exists(x => x == stringEdge))
         {
             continue;
         }
         // Set edge.
         graph.InsertEdge(nodeDictionary[parent], nodeDictionary[node]);
         _usedEdge.Add(stringEdge);
         InsertGraph(graph, parent);
     }
 }
예제 #3
0
 // Step 1: Find matchs.
 private static Rule FindMatchs(VFlibcs.Graph graphVF)
 {
     foreach (var rule in RandomOrderByWeight())
     {
         if (rule.QuantityLimitMax == 0)
         {
             continue;
         }
         // VfState: Calculate the result of subgraph isomorphic.
         VFlibcs.VfState vfs = new VFlibcs.VfState(graphVF, _ruleVFgraphTable[rule], false, true);
         if (vfs.FMatch())
         {
             // Reduce the quantity limit.
             if (rule.QuantityLimitMin > 0)
             {
                 rule.QuantityLimitMin -= 1;
             }
             if (rule.QuantityLimitMax > 0)
             {
                 rule.QuantityLimitMax -= 1;
             }
             _relatedNodes.Clear();
             for (int i = 0; i < vfs.Mapping2To1.Length; i++)
             {
                 // Set Index.
                 Node node = graphVF.GetNodeAttr(vfs.Mapping2To1[i]) as Node;
                 // Record this one is used in this iterating.
                 node.Explored = true;
                 _exploredNodeStack.Push(node);
                 if (node.IsEdge)
                 {
                     continue;
                 }
                 node.Index = (_ruleVFgraphTable[rule].GetNodeAttr(i) as Node).Index;
                 _relatedNodes.Add(node);
             }
             return(rule);
         }
     }
     return(null);
 }