Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 16x 5x 1x 4x 1x 3x 2x 1x 1x | import { isSimpleGraph } from '../essence';
import Graph from '../Graph';
import { containAllSameNodes, containSameEdges } from './contain';
/**
* @description Check if one graph is the complement of another graph.
* @description.zh-CN 检查一个图是否是另一个图的补图。
*/
export const isGraphComplement = <NodeIDType = any, EdgeType = any>(
originGraph: Graph<NodeIDType, any, EdgeType, any>,
targetGraph: Graph<NodeIDType, any, EdgeType, any>,
) => {
if (!isSimpleGraph(originGraph) || !isSimpleGraph(targetGraph)) {
return false;
}
if (!containAllSameNodes(originGraph, targetGraph)) {
return false;
}
if (containSameEdges(originGraph, targetGraph)) {
return false;
}
const nodeCount = originGraph.nodeCount();
return originGraph.edgeCount() + targetGraph.edgeCount() === (nodeCount * (nodeCount - 1)) / 2;
};
|