diff --git a/packages/graph/package.json b/packages/graph/package.json index fa4f4d8..54775f4 100644 --- a/packages/graph/package.json +++ b/packages/graph/package.json @@ -1,6 +1,6 @@ { "name": "@antv/algorithm", - "version": "0.1.11", + "version": "0.1.13", "description": "graph algorithm", "keywords": [ "graph", diff --git a/packages/graph/src/gSpan/gSpan.ts b/packages/graph/src/gSpan/gSpan.ts index b67e258..6e68cd8 100644 --- a/packages/graph/src/gSpan/gSpan.ts +++ b/packages/graph/src/gSpan/gSpan.ts @@ -112,11 +112,9 @@ class DFScode { const toNodeId = dfsEdge.toNode; const { nodeLabel1, edgeLabel, nodeLabel2 } = dfsEdge.nodeEdgeNodeLabel; - if (nodeLabel1 !== VACANT_NODE_LABEL) - graph.addNode(fromNodeId, nodeLabel1); + if (nodeLabel1 !== VACANT_NODE_LABEL) graph.addNode(fromNodeId, nodeLabel1); if (nodeLabel2 !== VACANT_NODE_LABEL) graph.addNode(toNodeId, nodeLabel2); - - graph.addEdge(undefined, fromNodeId, toNodeId, edgeLabel); + if (nodeLabel1 !== VACANT_NODE_LABEL && nodeLabel2 !== nodeLabel1) graph.addEdge(undefined, fromNodeId, toNodeId, edgeLabel); }); return graph; } @@ -429,6 +427,7 @@ class GSpan { // 比较 root 中每一项的 nodeEdgeNodeLabel 大小,按照 nodeLabel1、edgeLabe、nodeLabel2 的顺序比较 let minLabel = this.findMinLabel(root); // line 419 + if (!minLabel) return; dfsCodeMin.dfsEdgeList.push( new DFSedge( 0, diff --git a/packages/graph/src/gaddi.ts b/packages/graph/src/gaddi.ts index 9d147cf..586c8fb 100644 --- a/packages/graph/src/gaddi.ts +++ b/packages/graph/src/gaddi.ts @@ -204,6 +204,7 @@ const getMatchedCount = (graph, structure, nodeLabelProp, edgeLabelProp) => { nodeMap[node.id] = node; }); let count = 0; + if (!structure?.edges?.length || structure?.nodes?.length < 2) return 0; graph.edges.forEach(e => { const sourceLabel = nodeMap[e.source][nodeLabelProp]; const targetLabel = nodeMap[e.target][nodeLabelProp]; @@ -540,7 +541,6 @@ const GADDI = ( // ); // 1.2. 生成上面节点对的相应相交邻居诱导子图。格式为 {'beginNodeIdx-endNodeIdx': {nodes: [], edges: []}} let intGMap = getIntersectNeighborInducedGraph(nodePairsMap, kNeighborUnits, graphData); - // 1.3. 使用 gSpan 算法(frequent graph mining)计算 ISIntG 的前 10 个频率最高的子结构(3-4条边) const top = 10, minSupport = 1, @@ -797,7 +797,6 @@ const GADDI = ( } } - // prune3: 若该邻居点到 candidate 的 NDS 距离比和它有相同 label 的节点到 beginPNode 的最小 NDS 距离小,移除这个点 const ndsToCandidate = ndsDist[key] ? ndsDist[key]