| 728 | } |
| 729 | |
| 730 | GrB_Matrix QueryGraph_MatrixRepresentation |
| 731 | ( |
| 732 | const QueryGraph *qg |
| 733 | ) { |
| 734 | ASSERT(qg != NULL); |
| 735 | |
| 736 | // make a clone of the given graph as we're about to modify it |
| 737 | QueryGraph *qg_clone = QueryGraph_Clone(qg); |
| 738 | |
| 739 | // give an ID for each node, abuse of `labelID` |
| 740 | uint node_count = QueryGraph_NodeCount(qg_clone); |
| 741 | for(uint i = 0; i < node_count; i++) { |
| 742 | QGNode *n = qg_clone->nodes[i]; |
| 743 | if(QGNode_LabelCount(n) == 0) QGNode_AddLabel(n, "", i); |
| 744 | else n->labelsID[0] = i; |
| 745 | } |
| 746 | |
| 747 | GrB_Matrix m; // matrix representation of QueryGraph |
| 748 | GrB_Info res = GrB_Matrix_new(&m, GrB_BOOL, node_count, node_count); |
| 749 | UNUSED(res); |
| 750 | ASSERT(res == GrB_SUCCESS); |
| 751 | |
| 752 | // build matrix representation of query graph |
| 753 | for(uint i = 0; i < node_count; i++) { |
| 754 | const QGNode *n = qg_clone->nodes[i]; |
| 755 | GrB_Index src = QGNode_GetLabelID(n, 0); |
| 756 | uint outgoing_degree = QGNode_OutgoingDegree(n); |
| 757 | |
| 758 | for(uint j = 0; j < outgoing_degree; j++) { |
| 759 | const QGEdge *e = n->outgoing_edges[j]; |
| 760 | GrB_Index dest = QGNode_GetLabelID(e->dest, 0); |
| 761 | |
| 762 | // populate `m` |
| 763 | res = GrB_Matrix_setElement_BOOL(m, true, src, dest); |
| 764 | ASSERT(res == GrB_SUCCESS); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | QueryGraph_Free(qg_clone); |
| 769 | return m; |
| 770 | } |
| 771 | |
| 772 | void QueryGraph_Print |
| 773 | ( |
no test coverage detected