/* 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* 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(); }