Skip to content

Commit 35fe145

Browse files
committed
added flow mtx checking script
1 parent 5074aa3 commit 35fe145

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

experimental/test/LG_check_flow.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#include "LG_internal.h"
3+
#include <LG_Xtest.h>
4+
5+
#undef LG_FREE_ALL
6+
#undef LG_FREE_WORK
7+
8+
#define LG_FREE_WORK \
9+
{ \
10+
GrB_free(&flow_r); \
11+
GrB_free(&flow_c); \
12+
GrB_free(&result_vec); \
13+
}
14+
15+
16+
#define LG_FREE_ALL \
17+
{ \
18+
LG_FREE_WORK; \
19+
}
20+
21+
22+
int LG_check_flow(const GrB_Matrix *flow_mtx, char* msg) {
23+
GrB_Vector flow_r=NULL, flow_c=NULL, result_vec=NULL ;
24+
GrB_Index n ;
25+
double net_flow = -1;
26+
LG_TRY(GrB_Matrix_nrows(&n, *flow_mtx));
27+
LG_TRY(GrB_Vector_new(&flow_r, GrB_FP64, n));
28+
LG_TRY(GrB_Vector_new(&flow_c, GrB_FP64, n));
29+
LG_TRY(GrB_Vector_new(&result_vec, GrB_FP64, n));
30+
LG_TRY(GrB_reduce(flow_c, NULL, NULL, GrB_PLUS_MONOID_FP64, *flow_mtx, NULL));
31+
LG_TRY(GrB_reduce(flow_r, NULL, NULL, GrB_PLUS_MONOID_FP64, *flow_mtx, GrB_DESC_T1));
32+
LG_TRY(GrB_eWiseAdd(result_vec, NULL, NULL, GrB_MINUS_FP64, flow_r, flow_c, NULL));
33+
LG_TRY(GrB_reduce(&net_flow, NULL, GrB_PLUS_MONOID_FP64, result_vec, NULL));
34+
LG_ASSERT_MSG(net_flow == 0, GrB_INVALID_VALUE, "Flow conservation is not followed");
35+
return GrB_SUCCESS;
36+
}

experimental/test/include/LG_Xtest.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ int LG_check_argminmax
116116
int dim, // dim=1: cols of A, dim=2: rows of A
117117
bool is_min,
118118
char *msg
119+
)
120+
121+
int LG_check_flow
122+
(
123+
const GrB_Matrix *flow_mtx,
124+
char* msg
119125
) ;
120126

121127
#endif

experimental/test/test_MaxFlow.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
12
#include <acutest.h>
23
#include <LAGraphX.h>
34
#include <LAGraph_test.h>
45
#include <stdio.h>
5-
6-
#include "LG_Xtest.h"
6+
#include <LG_Xtest.h>
77
#include "LG_internal.h"
88

99

@@ -63,4 +63,45 @@ void test_MaxFlow(void) {
6363
LAGraph_Finalize(msg);
6464
}
6565

66-
TEST_LIST = {{"MaxFlow", test_MaxFlow}, {NULL, NULL}};
66+
void test_MaxFlowMtx(void) {
67+
LAGraph_Init(msg);
68+
//OK(LG_SET_BURBLE(1));
69+
OK(LG_SET_BURBLE(0));
70+
OK(GxB_Global_Option_set(GxB_JIT_C_CONTROL, 4));
71+
for(uint8_t test = 0; test < NTESTS; test++){
72+
GrB_Matrix A=NULL;
73+
TEST_CASE(tests[test].filename);
74+
snprintf(filename, LEN, LG_DATA_DIR "%s", tests[test].filename);
75+
FILE* f = fopen(filename, "r");
76+
TEST_CHECK(f != NULL);
77+
OK(LAGraph_MMRead(&A, f, msg));
78+
79+
//create flow mtx
80+
GrB_Matrix flow_mtx=NULL;
81+
GrB_Index n;
82+
OK(GrB_Matrix_nrows(&n, A));
83+
OK(GrB_Matrix_new(&flow_mtx, GrB_FP64, n, n));
84+
85+
OK(fclose(f));
86+
OK(LAGraph_New(&G, &A, LAGraph_ADJACENCY_DIRECTED, msg));
87+
OK(LAGraph_Cached_AT(G, msg));
88+
OK(LAGraph_Cached_EMin(G, msg));
89+
90+
//begin test
91+
double flow = 0;
92+
OK(LAGr_MaxFlow(&flow, &flow_mtx, G, tests[test].S, tests[test].T, msg));
93+
int status = LG_check_flow(&flow_mtx, msg);
94+
printf("%d", status);
95+
printf("%s\n", msg);
96+
TEST_CHECK(flow == tests[test].F);
97+
printf("flow is: %lf\n", flow);
98+
99+
//free work
100+
GrB_free(&flow_mtx);
101+
OK(LAGraph_Delete(&G, msg));
102+
}
103+
LAGraph_Finalize(msg);
104+
}
105+
106+
107+
TEST_LIST = {{"MaxFlow", test_MaxFlow}, {"MaxFlowMtx", test_MaxFlowMtx}, {NULL, NULL}};

include/LAGraphX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,7 @@ int LAGraph_coloring_MIS
14921492
char *msg
14931493
) ;
14941494

1495+
LAGRAPHX_PUBLIC
14951496
int LAGr_MaxFlow(
14961497
//outputs
14971498
double* f,

0 commit comments

Comments
 (0)