@@ -31,124 +31,56 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3131
3232#include "c_common/postgres_connection.h"
3333
34- #include "c_common/debug_macro.h"
35- #include "c_common/e_report.h"
36- #include "c_common/time_msg.h"
37- #include "drivers/max_flow/max_flow_driver.h"
38-
3934#include "c_types/flow_t.h"
4035
41- PGDLLEXPORT Datum
42- _pgr_maxflow (PG_FUNCTION_ARGS );
43-
44- static
45- void
46- process (
47- char * edges_sql ,
48- char * combinations_sql ,
49- ArrayType * starts ,
50- ArrayType * ends ,
51- int algorithm ,
52- bool only_flow ,
53- Flow_t * * result_tuples ,
54- size_t * result_count ) {
55- if (algorithm < 1 || algorithm > 3 ) {
56- elog (ERROR , "Unknown algorithm" );
57- }
58-
59- pgr_SPI_connect ();
60- char * log_msg = NULL ;
61- char * notice_msg = NULL ;
62- char * err_msg = NULL ;
63-
64- clock_t start_t = clock ();
65- pgr_do_max_flow (
66- edges_sql ,
67- combinations_sql ,
68- starts , ends ,
69-
70- algorithm ,
71- only_flow ,
72-
73- result_tuples , result_count ,
74-
75- & log_msg ,
76- & notice_msg ,
77- & err_msg );
78-
79- if (only_flow ) {
80- time_msg ("pgr_maxFlow(many to many)" , start_t , clock ());
81- } else if (algorithm == 1 ) {
82- time_msg ("pgr_maxFlowPushRelabel(many to many)" , start_t , clock ());
83- } else if (algorithm == 3 ) {
84- time_msg ("pgr_maxFlowEdmondsKarp(many to many)" , start_t , clock ());
85- } else {
86- time_msg ("pgr_maxFlowBoykovKolmogorov(many to many)" , start_t , clock ());
87- }
88-
89- if (err_msg && (* result_tuples )) {
90- pfree (* result_tuples );
91- (* result_tuples ) = NULL ;
92- (* result_count ) = 0 ;
93- }
36+ #include "process/maxFlow_process.h"
9437
95- pgr_global_report (& log_msg , & notice_msg , & err_msg );
96-
97- pgr_SPI_finish ();
98- }
38+ PGDLLEXPORT Datum _pgr_maxflow (PG_FUNCTION_ARGS );
39+ PG_FUNCTION_INFO_V1 (_pgr_maxflow );
9940
10041
101- PG_FUNCTION_INFO_V1 (_pgr_maxflow );
102- PGDLLEXPORT Datum
103- _pgr_maxflow (PG_FUNCTION_ARGS ) {
104- FuncCallContext * funcctx ;
105- TupleDesc tuple_desc ;
42+ PGDLLEXPORT Datum _pgr_maxflow (PG_FUNCTION_ARGS ) {
43+ FuncCallContext * funcctx ;
44+ TupleDesc tuple_desc ;
10645
107- /**************************************************************************/
108- Flow_t * result_tuples = 0 ;
46+ Flow_t * result_tuples = NULL ;
10947 size_t result_count = 0 ;
110- /**************************************************************************/
11148
11249 if (SRF_IS_FIRSTCALL ()) {
113- MemoryContext oldcontext ;
50+ MemoryContext oldcontext ;
11451 funcctx = SRF_FIRSTCALL_INIT ();
11552 oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
11653
117-
118- /**********************************************************************/
119-
12054 if (PG_NARGS () == 5 ) {
12155 /*
12256 * many to many
12357 */
124- process (
58+ pgr_process_maxFlow (
12559 text_to_cstring (PG_GETARG_TEXT_P (0 )),
12660 NULL ,
61+
12762 PG_GETARG_ARRAYTYPE_P (1 ),
12863 PG_GETARG_ARRAYTYPE_P (2 ),
129- PG_GETARG_INT32 (3 ),
130- PG_GETARG_BOOL (4 ),
64+ PG_GETARG_BOOL (4 )? MAXFLOW : MAXFLOW + PG_GETARG_INT32 (3 ),
13165 & result_tuples ,
13266 & result_count );
13367
13468 } else if (PG_NARGS () == 4 ) {
13569 /*
13670 * combinations
13771 */
138- process (
72+ pgr_process_maxFlow (
13973 text_to_cstring (PG_GETARG_TEXT_P (0 )),
14074 text_to_cstring (PG_GETARG_TEXT_P (1 )),
75+
14176 NULL ,
14277 NULL ,
143- PG_GETARG_INT32 ( 2 ),
144- PG_GETARG_BOOL (3 ),
78+
79+ PG_GETARG_BOOL (3 )? MAXFLOW : MAXFLOW + PG_GETARG_INT32 ( 2 ) ,
14580 & result_tuples ,
14681 & result_count );
14782 }
14883
149- /* */
150- /**********************************************************************/
151-
15284 funcctx -> max_calls = result_count ;
15385 funcctx -> user_fctx = result_tuples ;
15486 if (get_call_result_type (fcinfo , NULL , & tuple_desc )
@@ -168,14 +100,13 @@ _pgr_maxflow(PG_FUNCTION_ARGS) {
168100 result_tuples = (Flow_t * ) funcctx -> user_fctx ;
169101
170102 if (funcctx -> call_cntr < funcctx -> max_calls ) {
171- HeapTuple tuple ;
172- Datum result ;
173- Datum * values ;
174- bool * nulls ;
103+ HeapTuple tuple ;
104+ Datum result ;
105+ Datum * values ;
106+ bool * nulls ;
107+
175108 size_t call_cntr = funcctx -> call_cntr ;
176109
177- /**********************************************************************/
178- /* MODIFY AS NEEDED */
179110 values = palloc (6 * sizeof (Datum ));
180111 nulls = palloc (6 * sizeof (bool ));
181112
@@ -190,7 +121,6 @@ _pgr_maxflow(PG_FUNCTION_ARGS) {
190121 values [3 ] = Int64GetDatum (result_tuples [call_cntr ].target );
191122 values [4 ] = Int64GetDatum (result_tuples [call_cntr ].flow );
192123 values [5 ] = Int64GetDatum (result_tuples [call_cntr ].residual_capacity );
193- /**********************************************************************/
194124
195125 tuple = heap_form_tuple (tuple_desc , values , nulls );
196126 result = HeapTupleGetDatum (tuple );
0 commit comments