Skip to content

Commit bf6d562

Browse files
committed
(bdastar) using the process and driver
1 parent 0b2fab4 commit bf6d562

File tree

6 files changed

+36
-74
lines changed

6 files changed

+36
-74
lines changed

sql/bdAstar/bdAstarCostMatrix.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CREATE FUNCTION pgr_bdAstarCostMatrix(
4646
RETURNS SETOF RECORD AS
4747
$BODY$
4848
SELECT a.start_vid, a.end_vid, a.agg_cost
49-
FROM _pgr_bdAstar(_pgr_get_statement($1), $2::BIGINT[], $2::BIGINT[], $3, $4, $5::FLOAT, $6::FLOAT, true) a;
49+
FROM _pgr_bdAstar(_pgr_get_statement($1), $2::BIGINT[], '{}'::BIGINT[], $3, $4, $5::FLOAT, $6::FLOAT, true) a;
5050
$BODY$
5151
LANGUAGE SQL VOLATILE STRICT
5252
COST ${COST_HIGH} ROWS ${ROWS_HIGH};

src/astar/astar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ PGDLLEXPORT Datum _pgr_astar(PG_FUNCTION_ARGS) {
4848
MemoryContext oldcontext;
4949
funcctx = SRF_FIRSTCALL_INIT();
5050
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
51+
5152
if (PG_NARGS() == 9) {
5253
/*
5354
* many to many

src/astar/astar_driver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4141
#include "cpp_common/to_postgres.hpp"
4242

4343
#include "astar/astar.hpp"
44+
#include "bdAstar/bdAstar.hpp"
4445

4546
namespace pgrouting {
4647
namespace drivers {
@@ -97,6 +98,7 @@ void do_astar(
9798
using pgrouting::xyDirectedGraph;
9899

99100
using pgrouting::algorithms::astar;
101+
using pgrouting::algorithms::bdastar;
100102

101103
hint = combinations_sql;
102104
auto combinations = get_combinations(combinations_sql, starts, ends, normal, is_matrix);
@@ -126,6 +128,9 @@ void do_astar(
126128
if (directed) {
127129
digraph.insert_edges(edges);
128130
switch (which) {
131+
case BDASTAR:
132+
paths = bdastar(digraph, combinations, heuristic, factor, epsilon, only_cost);
133+
break;
129134
case ASTAR:
130135
paths = astar(digraph, combinations, heuristic, factor, epsilon, only_cost);
131136
break;
@@ -136,6 +141,9 @@ void do_astar(
136141
} else {
137142
undigraph.insert_edges(edges);
138143
switch (which) {
144+
case BDASTAR:
145+
paths = bdastar(undigraph, combinations, heuristic, factor, epsilon, only_cost);
146+
break;
139147
case ASTAR:
140148
paths = astar(undigraph, combinations, heuristic, factor, epsilon, only_cost);
141149
break;

src/bdAstar/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is part of the pgRouting project.
22
# Copyright (c) 2016-2026 pgRouting developers
33
# License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE
4+
45
ADD_LIBRARY(bdAstar OBJECT
56
bdAstar.c
6-
bdAstar_driver.cpp
7-
)
7+
)

src/bdAstar/bdAstar.c

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -31,73 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3131
#include "c_common/postgres_connection.h"
3232

3333
#include "c_types/path_rt.h"
34-
#include "c_common/debug_macro.h"
35-
#include "c_common/e_report.h"
36-
#include "c_common/time_msg.h"
37-
#include "c_common/check_parameters.h"
38-
#include "drivers/bdAstar/bdAstar_driver.h"
34+
#include "process/astar_process.h"
3935

4036
PGDLLEXPORT Datum _pgr_bdastar(PG_FUNCTION_ARGS);
4137
PG_FUNCTION_INFO_V1(_pgr_bdastar);
4238

4339

44-
static
45-
void
46-
process(char* edges_sql,
47-
char* combinations_sql,
48-
ArrayType *starts,
49-
ArrayType *ends,
50-
bool directed,
51-
int heuristic,
52-
double factor,
53-
double epsilon,
54-
bool only_cost,
55-
Path_rt **result_tuples,
56-
size_t *result_count) {
57-
check_parameters(heuristic, factor, epsilon);
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_bdAstar(
66-
edges_sql,
67-
combinations_sql,
68-
starts, ends,
69-
70-
directed,
71-
heuristic,
72-
factor,
73-
epsilon,
74-
only_cost,
75-
result_tuples, result_count,
76-
&log_msg,
77-
&notice_msg,
78-
&err_msg);
79-
80-
if (only_cost) {
81-
time_msg("pgr_bdAstarCost", start_t, clock());
82-
} else {
83-
time_msg("pgr_bdAstar", start_t, clock());
84-
}
85-
86-
if (err_msg && (*result_tuples)) {
87-
pfree(*result_tuples);
88-
(*result_tuples) = NULL;
89-
(*result_count) = 0;
90-
}
91-
92-
pgr_global_report(&log_msg, &notice_msg, &err_msg);
93-
94-
pgr_SPI_finish();
95-
}
96-
9740
PGDLLEXPORT Datum
9841
_pgr_bdastar(PG_FUNCTION_ARGS) {
9942
FuncCallContext *funcctx;
100-
TupleDesc tuple_desc;
43+
TupleDesc tuple_desc;
10144

10245
Path_rt *result_tuples = NULL;
10346
size_t result_count = 0;
@@ -107,50 +50,59 @@ _pgr_bdastar(PG_FUNCTION_ARGS) {
10750
funcctx = SRF_FIRSTCALL_INIT();
10851
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
10952

110-
11153
if (PG_NARGS() == 8) {
11254
/*
11355
* many to many
11456
*/
115-
process(
57+
pgr_process_astar(
11658
text_to_cstring(PG_GETARG_TEXT_P(0)),
11759
NULL,
11860
PG_GETARG_ARRAYTYPE_P(1),
11961
PG_GETARG_ARRAYTYPE_P(2),
62+
12063
PG_GETARG_BOOL(3),
64+
PG_GETARG_BOOL(7),
65+
true,
66+
12167
PG_GETARG_INT32(4),
12268
PG_GETARG_FLOAT8(5),
12369
PG_GETARG_FLOAT8(6),
124-
PG_GETARG_BOOL(7),
70+
71+
BDASTAR,
12572
&result_tuples,
12673
&result_count);
12774
} else if (PG_NARGS() == 7) {
12875
/*
129-
* combinations
76+
* Combinations
13077
*/
131-
process(
78+
pgr_process_astar(
13279
text_to_cstring(PG_GETARG_TEXT_P(0)),
13380
text_to_cstring(PG_GETARG_TEXT_P(1)),
134-
NULL,
135-
NULL,
81+
82+
NULL, NULL,
83+
13684
PG_GETARG_BOOL(2),
85+
PG_GETARG_BOOL(6),
86+
true,
87+
13788
PG_GETARG_INT32(3),
13889
PG_GETARG_FLOAT8(4),
13990
PG_GETARG_FLOAT8(5),
140-
PG_GETARG_BOOL(6),
91+
92+
BDASTAR,
14193
&result_tuples,
14294
&result_count);
14395
}
14496

145-
14697
funcctx->max_calls = result_count;
14798
funcctx->user_fctx = result_tuples;
14899
if (get_call_result_type(fcinfo, NULL, &tuple_desc)
149-
!= TYPEFUNC_COMPOSITE)
100+
!= TYPEFUNC_COMPOSITE) {
150101
ereport(ERROR,
151102
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
152103
errmsg("function returning record called in context "
153104
"that cannot accept type record")));
105+
}
154106

155107
funcctx->tuple_desc = tuple_desc;
156108
MemoryContextSwitchTo(oldcontext);
@@ -167,7 +119,6 @@ _pgr_bdastar(PG_FUNCTION_ARGS) {
167119
bool* nulls;
168120
size_t call_cntr = funcctx->call_cntr;
169121

170-
171122
size_t numb = 8;
172123
values = palloc(numb * sizeof(Datum));
173124
nulls = palloc(numb * sizeof(bool));

src/cpp_common/utilities.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ get_name(Which which, bool is_only_cost, bool is_near, bool is_matrix) {
6969
switch (which) {
7070
case DIJKSTRA :
7171
base = "pgr_dijkstra";
72-
suffix = std::string(is_near? "Near" : "") + (is_only_cost? "Cost" : "") + (is_only_cost && is_matrix? "Matrix" : "");
72+
suffix = std::string(is_near? "Near" : "")
73+
+ (is_only_cost? "Cost" : "")
74+
+ (is_only_cost && is_matrix? "Matrix" : "");
7375
break;
7476
case BDDIJKSTRA :
7577
base = "pgr_bdDijkstra";

0 commit comments

Comments
 (0)