Hi everyone, I hope someone here can help me with my problem. I’m trying to set up a routing algorithm that can calculate routes on a custom forest road network. It should also be able to reflect turn restrictions.
My problem is that I can’t properly handle U-turns. Using the path array, I can specify a sequence of edges that must not be used. If I were to model a U-turn, this would result in the same ID in both the from and to fields [edge_id, edge_id]. However, this doesn’t indicate which node this restriction applies to.
Example
If I enter the constraint [1,1], it's not clear whether it applies to a U-turn at node A or B.
A <---1---> B <---2---> C
To Reproduce
Here is a short code snippet you can use to test the behavior.
DROP TABLE IF EXISTS test_edges;
CREATE TEMP TABLE test_edges (
id BIGINT PRIMARY KEY,
source BIGINT,
target BIGINT,
cost DOUBLE PRECISION,
reverse_cost DOUBLE PRECISION
);
INSERT INTO test_edges VALUES
(1, 1, 2, 10.0, 10.0), -- e1: 1 <-> 2
(2, 2, 3, 10.0, 10.0), -- e2: 2 <-> 3
(3, 3, 4, 10.0, 10.0), -- e3: 3 <-> 4
(4, 4, 1, 50.0, 50.0); -- e4:
DROP TABLE IF EXISTS test_restrictions;
CREATE TEMP TABLE test_restrictions (
path BIGINT[],
cost DOUBLE PRECISION
);
INSERT INTO test_restrictions VALUES
(ARRAY[1,1],99999.0);
SELECT *
FROM pgr_trsp_withpoints(
'SELECT id, source, target, cost, reverse_cost FROM test_edges',
'SELECT path, cost FROM test_restrictions',
'SELECT pid, edge_id, fraction, side
FROM (VALUES (1::BIGINT, 1::BIGINT, 0.5::DOUBLE PRECISION, ''r''::CHAR),
(2::BIGINT, 4::BIGINT, 0.9::DOUBLE PRECISION, ''b''::CHAR))
AS p(pid, edge_id, fraction, side)',
ARRAY[-1]::BIGINT[],
ARRAY[-2]::BIGINT[],
directed := true,
details => true
);
Expectation
I can't imagine being the first person to encounter this problem, so I hope there's a solution. I would have expected it to be possible to specify a via node to improve the assignment (similar to specifying OSM restrictions).
Platform/versions
Unfortunately, I'm stuck with pgrouting 3.5, since that's the latest version available for postgresql for azure.
Hi everyone, I hope someone here can help me with my problem. I’m trying to set up a routing algorithm that can calculate routes on a custom forest road network. It should also be able to reflect turn restrictions.
My problem is that I can’t properly handle U-turns. Using the path array, I can specify a sequence of edges that must not be used. If I were to model a U-turn, this would result in the same ID in both the from and to fields [edge_id, edge_id]. However, this doesn’t indicate which node this restriction applies to.
Example
If I enter the constraint [1,1], it's not clear whether it applies to a U-turn at node A or B.
A <---1---> B <---2---> C
To Reproduce
Here is a short code snippet you can use to test the behavior.
Expectation
I can't imagine being the first person to encounter this problem, so I hope there's a solution. I would have expected it to be possible to specify a via node to improve the assignment (similar to specifying OSM restrictions).
Platform/versions
Unfortunately, I'm stuck with pgrouting 3.5, since that's the latest version available for postgresql for azure.