/* MODIFY AS NEEDED */ static void process( char* edges_sql, int64_t start_vid, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, MY_RETURN_VALUE_TYPE **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); MY_EDGE_TYPE *edges = NULL; size_t total_edges = 0; MY_EDGE_FUNCTION(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); char *err_msg = NULL; char *log_msg = NULL; // Code standard: // Pass the arrays and the sizes on the same line clock_t start_t = clock(); do_pgr_MY_FUNCTION_NAME( edges, total_edges, start_vid, end_vidsArr, size_end_vidsArr, directed, result_tuples, result_count, &log_msg, &err_msg); time_msg(" processing pgr_funnyDijkstra", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("LOG: %s\n", log_msg); if (log_msg) free(log_msg); if (err_msg) { if (*result_tuples) free(*result_tuples); if (end_vidsArr) free(end_vidsArr); elog(ERROR, "%s", err_msg); free(err_msg); } pfree(edges); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, int64_t start_vid, int64_t end_vid, bool directed, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); pgr_edge_t *edges = NULL; if (start_vid == end_vid) { (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } size_t total_tuples = 0; pgr_get_edges(edges_sql, &edges, &total_tuples); if (total_tuples == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_tuples); PGR_DBG("Starting processing"); clock_t start_t = clock(); char *err_msg = NULL; do_pgr_one_to_one_dijkstra( edges, total_tuples, start_vid, end_vid, directed, only_cost, result_tuples, result_count, &err_msg); time_msg(" processing Dijkstra one to one", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); free(err_msg); pfree(edges); pgr_SPI_finish(); }
static void process(char* edges_sql, bool *result_bool) { pgr_SPI_connect(); PGR_DBG("Load data"); Pgr_edge_xy_t *edges = NULL; size_t total_edges = 0; pgr_get_edges_xy(edges_sql, &edges, &total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); (*result_bool) = true; pfree(edges); pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_edges); size_t i; for (i = 0; i < total_edges; ++i) { PGR_DBG("id = %li \t source = %li \t target = %ld cost = %lf reverse_cost = %lf", edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost); PGR_DBG(" (x1,y1) = (%.32lf ,%.32lf) (x2,y2) = (%.32lf,.%.32lf)", edges[i].x1, edges[i].y1, edges[i].x2, edges[i].y2); } PGR_DBG("Starting processing"); char *err_msg = NULL; char *log_msg = NULL; (*result_bool) = do_pgr_testXYedges( edges, total_edges, &log_msg, &err_msg); pfree(edges); PGR_DBG("Returned log message = %s\n", log_msg); if (log_msg) { elog(DEBUG1, "%s", log_msg); free(log_msg); } PGR_DBG("Returned error message = %s\n", err_msg); if (err_msg) { pgr_SPI_finish(); elog(ERROR, "%s", err_msg); free(err_msg); } pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char *edges_sql, int64_t *source_vertices, size_t size_source_verticesArr, int64_t sink_vertex, bool directed, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); pgr_basic_edge_t *edges = NULL; size_t total_tuples = 0; pgr_get_basic_edges(edges_sql, &edges, &total_tuples); if (total_tuples == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_tuples); PGR_DBG("Starting processing"); clock_t start_t = clock(); char *err_msg = NULL; do_pgr_edge_disjoint_paths_many_to_one( edges, total_tuples, source_vertices, size_source_verticesArr, sink_vertex, directed, result_tuples, result_count, &err_msg); time_msg("processing edge disjoint paths", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); free(err_msg); pfree(edges); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char *edges_sql, bool directed, pgr_basic_edge_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); pgr_basic_edge_t *edges = NULL; size_t total_tuples = 0; pgr_get_basic_edges(edges_sql, &edges, &total_tuples); if (total_tuples == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_tuples); PGR_DBG("Starting processing"); clock_t start_t = clock(); char *err_msg = NULL; do_pgr_maximum_cardinality_matching( edges, directed, total_tuples, result_tuples, result_count, &err_msg); time_msg("processing max flow", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); free(err_msg); pfree(edges); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* distances_sql, int64_t start_vid, int64_t end_vid, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); Matrix_cell_t *distances = NULL; size_t total_distances = 0; pgr_get_distances(distances_sql, &distances, &total_distances); if (total_distances == 0) { PGR_DBG("No distances found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_distances); PGR_DBG("Starting processing"); char *err_msg = NULL; do_pgr_tsp( distances, total_distances, start_vid, end_vid, result_tuples, result_count, &err_msg); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); free(err_msg); pfree(distances); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, bool directed, Matrix_cell_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); pgr_edge_t *edges = NULL; size_t total_tuples = 0; pgr_get_data_4_columns(edges_sql, &edges, &total_tuples); if (total_tuples == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Total %ld tuples in query:", total_tuples); PGR_DBG("Starting processing"); char *err_msg = (char *)""; clock_t start_t = clock(); do_pgr_johnson( edges, total_tuples, directed, result_tuples, result_count, &err_msg); time_msg(" processing Johnson", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); free(err_msg); pfree(edges); pgr_SPI_finish(); }
static void process( char* edges_sql, char* points_sql, ArrayType *starts, ArrayType *ends, bool directed, char *driving_side, bool details, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { driving_side[0] = estimate_drivingSide(driving_side[0]); pgr_SPI_connect(); size_t size_start_pidsArr = 0; int64_t* start_pidsArr = pgr_get_bigIntArray(&size_start_pidsArr, starts); size_t size_end_pidsArr = 0; int64_t* end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends); Point_on_edge_t *points = NULL; size_t total_points = 0; pgr_get_points(points_sql, &points, &total_points); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); pgr_edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; pgr_get_edges( edges_of_points_query, &edges_of_points, &total_edges_of_points); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_edges(edges_no_points_query, &edges, &total_edges); free(edges_of_points_query); free(edges_no_points_query); if ((total_edges + total_edges_of_points) == 0) { pgr_SPI_finish(); return; } clock_t start_t = clock(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; do_pgr_many_to_many_withPoints( edges, total_edges, points, total_points, edges_of_points, total_edges_of_points, start_pidsArr, size_start_pidsArr, end_pidsArr, size_end_pidsArr, driving_side[0], details, directed, only_cost, true, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); if (only_cost) { time_msg("processing pgr_withPointsCost(one to one)", start_t, clock()); } else { time_msg("processing pgr_withPoints(one to one)", start_t, clock()); } if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_count) = 0; (*result_tuples) = NULL; } pgr_global_report(log_msg, notice_msg, err_msg); #if 0 if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); if (edges) pfree(edges); if (points) pfree(points); if (edges_of_points) pfree(edges_of_points); if (start_pidsArr) pfree(start_pidsArr); if (end_pidsArr) pfree(end_pidsArr); #endif pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, char* points_sql, int64_t start_pid, int64_t *end_pidsArr, size_t size_end_pidsArr, bool directed, char *driving_side, bool details, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { driving_side[0] = (char) tolower(driving_side[0]); PGR_DBG("driving side:%c", driving_side[0]); if (!((driving_side[0] == 'r') || (driving_side[0] == 'l'))) { driving_side[0] = 'b'; } PGR_DBG("estimated driving side:%c", driving_side[0]); pgr_SPI_connect(); PGR_DBG("load the points"); Point_on_edge_t *points = NULL; size_t total_points = 0; pgr_get_points(points_sql, &points, &total_points); #if 0 #ifndef NDEBUG size_t i = 0; for (i = 0; i < total_points; i ++) { PGR_DBG("%ld\t%ld\t%f\t%c", points[i].pid, points[i].edge_id, points[i].fraction, points[i].side); } #endif #endif /* * TODO move this code to c++ */ PGR_DBG(" -- change the query"); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); PGR_DBG("edges_of_points_query:\n%s", edges_of_points_query); PGR_DBG("edges_no_points_query:\n%s", edges_no_points_query); PGR_DBG("load the edges that match the points"); pgr_edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points); PGR_DBG("Total %ld edges in query:", total_edges_of_points); #if 0 #ifndef NDEBUG for (i = 0; i < total_edges_of_points; i ++) { PGR_DBG("%ld\t%ld\t%ld\t%f\t%f", edges_of_points[i].id, edges_of_points[i].source, edges_of_points[i].target, edges_of_points[i].cost, edges_of_points[i].reverse_cost); } #endif #endif PGR_DBG("load the edges that don't match the points"); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_edges(edges_no_points_query, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); #if 0 #ifndef NDEBUG for (i = 0; i < total_edges; i ++) { PGR_DBG("%ld\t%ld\t%ld\t%f\t%f", edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost); } #endif PGR_DBG("freeing allocated memory not used anymore"); #endif free(edges_of_points_query); free(edges_no_points_query); if ((total_edges + total_edges_of_points) == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); char *err_msg = NULL; char *log_msg = NULL; clock_t start_t = clock(); do_pgr_one_to_many_withPoints( edges, total_edges, points, total_points, edges_of_points, total_edges_of_points, start_pid, end_pidsArr, size_end_pidsArr, driving_side[0], details, directed, only_cost, result_tuples, result_count, &log_msg, &err_msg); time_msg(" processing withPoints one to many", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("LOG: %s\n", log_msg); if (log_msg) free(log_msg); if (err_msg) { if (*result_tuples) free(*result_tuples); if (end_pidsArr) free(end_pidsArr); elog(ERROR, "%s", err_msg); free(err_msg); } pfree(edges); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, char* points_sql, int64_t start_pid, int64_t end_pid, bool directed, char *driving_side, bool details, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { driving_side[0] = tolower(driving_side[0]); PGR_DBG("driving side:%c",driving_side[0]); if (! ((driving_side[0] == 'r') || (driving_side[0] == 'l'))) { driving_side[0] = 'b'; } PGR_DBG("estimated driving side:%c",driving_side[0]); pgr_SPI_connect(); PGR_DBG("load the points"); Point_on_edge_t *points = NULL; size_t total_points = 0; pgr_get_points(points_sql, &points, &total_points); #ifdef DEBUG size_t i = 0; for (i = 0; i < total_points; i ++) { PGR_DBG("%ld\t%ld\t%f\t%c",points[i].pid, points[i].edge_id, points[i].fraction, points[i].side); } #endif PGR_DBG(" -- change the query"); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); PGR_DBG("edges_of_points_query:\n%s", edges_of_points_query); PGR_DBG("edges_no_points_query:\n%s", edges_no_points_query); PGR_DBG("load the edges that match the points"); pgr_edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; pgr_get_data_5_columns(edges_of_points_query, &edges_of_points, &total_edges_of_points); PGR_DBG("Total %ld edges in query:", total_edges_of_points); #ifdef DEBUG for (i = 0; i < total_edges_of_points; i ++) { PGR_DBG("%ld\t%ld\t%ld\t%f\t%f", edges_of_points[i].id, edges_of_points[i].source, edges_of_points[i].target, edges_of_points[i].cost, edges_of_points[i].reverse_cost); } #endif PGR_DBG("load the edges that dont match the points"); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_data_5_columns(edges_no_points_query, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); #ifdef DEBUG for (i = 0; i < total_edges; i ++) { PGR_DBG("%ld\t%ld\t%ld\t%f\t%f", edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost); } #endif PGR_DBG("freeing allocated memory not used anymore"); free(edges_of_points_query); free(edges_no_points_query); if ( (total_edges + total_edges_of_points) == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); char *err_msg = NULL; clock_t start_t = clock(); int errcode = do_pgr_withPoints( edges, total_edges, points, total_points, edges_of_points, total_edges_of_points, start_pid, end_pid, directed, driving_side[0], details, only_cost, result_tuples, result_count, &err_msg); time_msg(" processing withPoints one to one", start_t, clock()); PGR_DBG("Returning %ld tuples\n", *result_count); PGR_DBG("Returned message = %s\n", err_msg); if (!err_msg) free(err_msg); pfree(edges); pgr_SPI_finish(); if (errcode) { pgr_send_error(errcode); } }
static void compute( char* edges_sql, int64_t start_vertex, int64_t end_vertex, int k, bool directed, bool heap_paths, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); PGR_DBG("Load data"); pgr_edge_t *edges = NULL; size_t total_edges = 0; if (start_vertex == end_vertex) { pgr_SPI_finish(); return; } pgr_get_edges(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); pgr_SPI_finish(); return; } PGR_DBG("Calling do_pgr_ksp\n"); PGR_DBG("heap_paths = %i\n", heap_paths); clock_t start_t = clock(); char *log_msg = NULL; char *notice_msg = NULL; char *err_msg = NULL; do_pgr_ksp( edges, total_edges, start_vertex, end_vertex, k, directed, heap_paths, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); time_msg(" processing KSP", start_t, clock()); if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } pgr_global_report(log_msg, notice_msg, err_msg); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); pgr_global_report(log_msg, notice_msg, err_msg); pfree(edges); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, char* points_sql, int64_t start_pid, int64_t end_pid, int k, bool directed, bool heap_paths, char *driving_side, bool details, General_path_element_t **result_tuples, size_t *result_count) { driving_side[0] = (char) tolower(driving_side[0]); PGR_DBG("driving side:%c",driving_side[0]); if (! ((driving_side[0] == 'r') || (driving_side[0] == 'l'))) { driving_side[0] = 'b'; } pgr_SPI_connect(); Point_on_edge_t *points = NULL; size_t total_points = 0; pgr_get_points(points_sql, &points, &total_points); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); pgr_edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; pgr_get_edges(edges_of_points_query, &edges_of_points, &total_edges_of_points); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_edges(edges_no_points_query, &edges, &total_edges); PGR_DBG("freeing allocated memory not used anymore"); free(edges_of_points_query); free(edges_no_points_query); if ((total_edges + total_edges_of_points) == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); clock_t start_t = clock(); char *log_msg = NULL; char *notice_msg = NULL; char *err_msg = NULL; do_pgr_withPointsKsp( edges, total_edges, points, total_points, edges_of_points, total_edges_of_points, start_pid, end_pid, k, directed, heap_paths, driving_side[0], details, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); time_msg(" processing withPointsKSP", start_t, clock()); PGR_DBG("Returned message = %s\n", err_msg); if (err_msg) { if (*result_tuples) free(*result_tuples); } pgr_global_report(log_msg, notice_msg, err_msg); pfree(edges); pfree(edges_of_points); pfree(points); pgr_SPI_finish(); }
static void process( char* edges_sql, char* points_sql, int64_t start_pid, ArrayType *ends, bool directed, char *driving_side, bool details, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { driving_side[0] = estimate_drivingSide(driving_side[0]); PGR_DBG("estimated driving side:%c", driving_side[0]); pgr_SPI_connect(); size_t size_end_pidsArr = 0; int64_t* end_pidsArr = pgr_get_bigIntArray(&size_end_pidsArr, ends); PGR_DBG("load the points"); size_t total_points = 0; Point_on_edge_t *points = NULL; pgr_get_points(points_sql, &points, &total_points); PGR_DBG(" -- change the query"); char *edges_of_points_query = NULL; char *edges_no_points_query = NULL; get_new_queries( edges_sql, points_sql, &edges_of_points_query, &edges_no_points_query); PGR_DBG("edges_of_points_query:\n%s", edges_of_points_query); PGR_DBG("edges_no_points_query:\n%s", edges_no_points_query); PGR_DBG("load the edges that match the points"); pgr_edge_t *edges_of_points = NULL; size_t total_edges_of_points = 0; pgr_get_edges( edges_of_points_query, &edges_of_points, &total_edges_of_points); PGR_DBG("Total %ld edges in query:", total_edges_of_points); PGR_DBG("load the edges that don't match the points"); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_edges(edges_no_points_query, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); free(edges_of_points_query); free(edges_no_points_query); if ((total_edges + total_edges_of_points) == 0) { PGR_DBG("No edges found"); pgr_SPI_finish(); return; } PGR_DBG("Starting timer"); clock_t start_t = clock(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; do_pgr_many_to_many_withPoints( edges, total_edges, points, total_points, edges_of_points, total_edges_of_points, &start_pid, 1, end_pidsArr, size_end_pidsArr, driving_side[0], details, directed, only_cost, true, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); if (only_cost) { time_msg("processing pgr_withPointsCost(one to many)", start_t, clock()); } else { time_msg("processing pgr_withPoints(one to many)", start_t, clock()); } if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_count) = 0; (*result_tuples) = NULL; } pgr_global_report(log_msg, notice_msg, err_msg); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); if (edges) pfree(edges); if (points) pfree(points); if (edges_of_points) pfree(edges_of_points); if (end_pidsArr) pfree(end_pidsArr); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* distances_sql, int64_t start_vid, int64_t end_vid, double time_limit, int64_t tries_per_temperature, int64_t max_changes_per_temperature, int64_t max_consecutive_non_changes, double initial_temperature, double final_temperature, double cooling_factor, bool randomize, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); /* * errors in parameters */ if (initial_temperature < final_temperature) { elog(ERROR, "Condition not met: initial_temperature" " > final_temperature"); } if (final_temperature <= 0) { elog(ERROR, "Condition not met: final_temperature > 0"); } if (cooling_factor <=0 || cooling_factor >=1) { elog(ERROR, "Condition not met: 0 < cooling_factor < 1"); } if (tries_per_temperature < 0) { elog(ERROR, "Condition not met: tries_per_temperature >= 0"); } if (max_changes_per_temperature < 1) { elog(ERROR, "Condition not met: max_changes_per_temperature > 0"); } if (max_consecutive_non_changes < 1) { elog(ERROR, "Condition not met: max_consecutive_non_changes > 0"); } if (time_limit < 0) { elog(ERROR, "Condition not met: max_processing_time >= 0"); } Matrix_cell_t *distances = NULL; size_t total_distances = 0; pgr_get_matrixRows(distances_sql, &distances, &total_distances); if (total_distances == 0) { PGR_DBG("No distances found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting timer"); clock_t start_t = clock(); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; do_pgr_tsp( distances, total_distances, start_vid, end_vid, initial_temperature, final_temperature, cooling_factor, tries_per_temperature, max_changes_per_temperature, max_consecutive_non_changes, randomize, time_limit, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); time_msg("eucledianTSP", start_t, clock()); if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } pgr_global_report(log_msg, notice_msg, err_msg); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); if (distances) pfree(distances); pgr_SPI_finish(); }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, ArrayType *starts, ArrayType *ends, bool directed, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { pgr_SPI_connect(); int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; start_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_start_vidsArr, starts); int64_t* end_vidsArr = NULL; size_t size_end_vidsArr = 0; end_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_vidsArr, ends); pgr_edge_t *edges = NULL; size_t total_edges = 0; pgr_get_edges(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); clock_t start_t = clock(); char *log_msg = NULL; char *notice_msg = NULL; char *err_msg = NULL; do_pgr_bdDijkstra( edges, total_edges, start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr, directed, only_cost, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); time_msg(" processing pgr_bdDijkstra", start_t, clock()); PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) free(*result_tuples); } pgr_global_report(log_msg, notice_msg, err_msg); pfree(edges); pgr_SPI_finish(); }
static void process(char* edges_sql, int64_t start_vid, int64_t end_vid, bool directed, int heuristic, double factor, double epsilon, bool only_cost, General_path_element_t **result_tuples, size_t *result_count) { check_parameters(heuristic, factor, epsilon); pgr_SPI_connect(); PGR_DBG("Load data"); Pgr_edge_xy_t *edges = NULL; size_t total_edges = 0; pgr_get_edges_xy(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); (*result_count) = 0; (*result_tuples) = NULL; pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); char* log_msg = NULL; char* notice_msg = NULL; char* err_msg = NULL; clock_t start_t = clock(); do_pgr_astarManyToMany( edges, total_edges, &start_vid, 1, &end_vid, 1, directed, heuristic, factor, epsilon, only_cost, true, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); if (only_cost) { time_msg("processing pgr_astarCost(one to one)", start_t, clock()); } else { time_msg("processing pgr_astar(one to one)", start_t, clock()); } if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_count) = 0; (*result_tuples) = NULL; } pgr_global_report(log_msg, notice_msg, err_msg); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); if (edges) pfree(edges); pgr_SPI_finish(); }
static int compute_trsp( char* edges_sql, int dovertex, int start_id, double start_pos, int end_id, double end_pos, bool directed, bool has_reverse_cost, char *restrict_sql, path_element_t **path, size_t *path_count) { pgr_SPI_connect(); PGR_DBG("Load edges"); pgr_edge_t *edges = NULL; size_t total_tuples = 0; pgr_get_data_5_columns(edges_sql, &edges, &total_tuples); PGR_DBG("Total %ld edges", total_tuples); PGR_DBG("Load restrictions"); restrict_t *restricts = NULL; size_t total_restrict_tuples = 0; if (restrict_sql == NULL) { PGR_DBG("Sql for restrictions is null."); } else { pgr_get_restriction_data(restrict_sql, &restricts, &total_restrict_tuples); } #ifdef DEBUG int t1; for (t1=0; t1<total_restrict_tuples; t1++) { PGR_DBG("restricts: %.2f, %ld, %ld, %ld, %ld, %ld, %ld", restricts[t1].to_cost, restricts[t1].target_id, restricts[t1].via[0], restricts[t1].via[1], restricts[t1].via[2], restricts[t1].via[3], restricts[t1].via[4]); } #endif PGR_DBG("Total %ld restriction", total_restrict_tuples); int v_max_id=0; int v_min_id=INT_MAX; /* track if start and end are both in edge tuples */ int s_count = 0; int t_count = 0; char *err_msg; int ret = -1; register int z; PGR_DBG("start turn_restrict_shortest_path\n"); if (start_id == end_id) { PGR_DBG("Starting vertex and Ending Vertex are equal"); *path = NULL; return 0; } //defining min and max vertex id PGR_DBG("Total %i edge tuples", total_tuples); for(z=0; z<total_tuples; z++) { if(edges[z].source<v_min_id) v_min_id=(int)edges[z].source; if(edges[z].source>v_max_id) v_max_id=(int)edges[z].source; if(edges[z].target<v_min_id) v_min_id=(int)edges[z].target; if(edges[z].target>v_max_id) v_max_id=(int)edges[z].target; //PGR_DBG("%i <-> %i", v_min_id, v_max_id); } //:::::::::::::::::::::::::::::::::::: //:: reducing vertex id (renumbering) //:::::::::::::::::::::::::::::::::::: for(z=0; z<total_tuples; z++) { //check if edges[] contains source and target if (dovertex) { if(edges[z].source == start_id || edges[z].target == start_id) ++s_count; if(edges[z].source == end_id || edges[z].target == end_id) ++t_count; } else { if(edges[z].id == start_id) ++s_count; if(edges[z].id == end_id) ++t_count; } edges[z].source-=v_min_id; edges[z].target-=v_min_id; edges[z].cost = edges[z].cost; //PGR_DBG("edgeID: %i SRc:%i - %i, cost: %f", edges[z].id,edges[z].source, edges[z].target,edges[z].cost); } PGR_DBG("Min vertex id: %i , Max vid: %i",v_min_id,v_max_id); PGR_DBG("Total %ld edge tuples", total_tuples); if(s_count == 0) { elog(ERROR, "Start id was not found."); return -1; } if(t_count == 0) { elog(ERROR, "Target id was not found."); return -1; } if (dovertex) { start_id -= v_min_id; end_id -= v_min_id; } if (dovertex) { PGR_DBG("Calling trsp_node_wrapper\n"); ret = trsp_node_wrapper(edges, total_tuples, restricts, total_restrict_tuples, start_id, end_id, directed, has_reverse_cost, path, path_count, &err_msg); } else { PGR_DBG("Calling trsp_edge_wrapper\n"); ret = trsp_edge_wrapper(edges, total_tuples, restricts, total_restrict_tuples, start_id, start_pos, end_id, end_pos, directed, has_reverse_cost, path, path_count, &err_msg); } PGR_DBG("Message received from inside:"); PGR_DBG("%s",err_msg); //PGR_DBG("SIZE %i\n",*path_count); //:::::::::::::::::::::::::::::::: //:: restoring original vertex id //:::::::::::::::::::::::::::::::: for(z=0;z<*path_count;z++) { //PGR_DBG("vetex %i\n",(*path)[z].vertex_id); if (z || (*path)[z].vertex_id != -1) (*path)[z].vertex_id+=v_min_id; } PGR_DBG("ret = %i\n", ret); PGR_DBG("*path_count = %i\n", *path_count); if (ret < 0) { //elog(ERROR, "Error computing path: %s", err_msg); ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED), errmsg("Error computing path: %s", err_msg))); } pgr_SPI_finish(); return 0; }
/* MODIFY AS NEEDED */ static void process( char* edges_sql, int64_t start_vid, int64_t end_vid, #if 0 /* * handling arrays example */ ArrayType *starts, ArrayType *ends, #endif bool directed, bool only_cost, MY_RETURN_VALUE_TYPE **result_tuples, size_t *result_count) { /* * https://www.postgresql.org/docs/current/static/spi-spi-connect.html */ pgr_SPI_connect(); #if 0 /* * handling arrays example */ PGR_DBG("Initializing arrays"); int64_t* start_vidsArr = NULL; size_t size_start_vidsArr = 0; start_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_start_vidsArr, starts); PGR_DBG("start_vidsArr size %ld ", size_start_vidsArr); int64_t* end_vidsArr = NULL; size_t size_end_vidsArr = 0; end_vidsArr = (int64_t*) pgr_get_bigIntArray(&size_end_vidsArr, ends); PGR_DBG("end_vidsArr size %ld ", size_end_vidsArr); #endif (*result_tuples) = NULL; (*result_count) = 0; PGR_DBG("Load data"); MY_EDGE_TYPE *edges = NULL; size_t total_edges = 0; if (start_vid == end_vid) { /* * https://www.postgresql.org/docs/current/static/spi-spi-finish.html */ pgr_SPI_finish(); return; } MY_EDGE_FUNCTION(edges_sql, &edges, &total_edges); PGR_DBG("Total %ld edges in query:", total_edges); if (total_edges == 0) { PGR_DBG("No edges found"); pgr_SPI_finish(); return; } PGR_DBG("Starting processing"); clock_t start_t = clock(); char *log_msg = NULL; char *notice_msg = NULL; char *err_msg = NULL; do_pgr_MY_FUNCTION_NAME( edges, total_edges, start_vid, end_vid, #if 0 /* * handling arrays example */ start_vidsArr, size_start_vidsArr, end_vidsArr, size_end_vidsArr, #endif directed, only_cost, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); time_msg(" processing pgr_MY_FUNCTION_NAME", start_t, clock()); PGR_DBG("Returning %ld tuples", *result_count); if (err_msg) { if (*result_tuples) pfree(*result_tuples); } pgr_global_report(log_msg, notice_msg, err_msg); if (edges) pfree(edges); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); #if 0 /* * handling arrays example */ if (end_vidsArr) pfree(end_vidsArr); if (start_vidsArr) pfree(start_vidsArr); #endif pgr_SPI_finish(); }
static void process( char *edges_sql, ArrayType *starts, ArrayType *ends, char *algorithm, bool only_flow, pgr_flow_t **result_tuples, size_t *result_count) { if (!(strcmp(algorithm, "push_relabel") == 0 || strcmp(algorithm, "edmonds_karp") == 0 || strcmp(algorithm, "boykov_kolmogorov") == 0)) { elog(ERROR, "Unknown algorithm"); } pgr_SPI_connect(); size_t size_source_verticesArr = 0; int64_t* source_vertices = pgr_get_bigIntArray(&size_source_verticesArr, starts); size_t size_sink_verticesArr = 0; int64_t* sink_vertices = pgr_get_bigIntArray(&size_sink_verticesArr, ends); pgr_edge_t *edges = NULL; size_t total_edges = 0; /* NOTE: * For flow, cost and reverse_cost are really capacity and reverse_capacity */ pgr_get_flow_edges(edges_sql, &edges, &total_edges); if (total_edges == 0) { if (source_vertices) pfree(source_vertices); if (sink_vertices) pfree(sink_vertices); pgr_SPI_finish(); return; } PGR_DBG("Starting timer"); clock_t start_t = clock(); char* log_msg = NULL; char* notice_msg = NULL; char *err_msg = NULL; do_pgr_max_flow( edges, total_edges, source_vertices, size_source_verticesArr, sink_vertices, size_sink_verticesArr, algorithm, only_flow, result_tuples, result_count, &log_msg, ¬ice_msg, &err_msg); if (only_flow) { time_msg("pgr_maxFlow(many to many)", start_t, clock()); } else if (strcmp(algorithm, "push_relabel") == 0) { time_msg("pgr_maxFlowPushRelabel(many to many)", start_t, clock()); } else if (strcmp(algorithm, "edmonds_karp") == 0) { time_msg("pgr_maxFlowEdmondsKarp(many to many)", start_t, clock()); } else { time_msg("pgr_maxFlowBoykovKolmogorov(many to many)", start_t, clock()); } if (edges) pfree(edges); if (source_vertices) pfree(source_vertices); if (sink_vertices) pfree(sink_vertices); if (err_msg && (*result_tuples)) { pfree(*result_tuples); (*result_tuples) = NULL; (*result_count) = 0; } pgr_global_report(log_msg, notice_msg, err_msg); if (log_msg) pfree(log_msg); if (notice_msg) pfree(notice_msg); if (err_msg) pfree(err_msg); pgr_SPI_finish(); }