pgRouting / pgrouting

Repository contains pgRouting library. Development branch is "develop", stable branch is "master"
https://pgrouting.org
GNU General Public License v2.0
1.15k stars 366 forks source link

Discussion on coding turn restrictions using Boost #610

Open woodbri opened 8 years ago

woodbri commented 8 years ago

The current pgr_trsp function does not use Boost in its underlying implementation, in part because Boost Graph does not support it natively. There has been some discussion about re-implementing the pgr_trsp like functionality using Boost Graph. I'm opening this issue to collect ideas and references regarding this.

There are also two terms that I have come across in this research "turn-penalties" and "turn-restrictions". An infinite penalty can be considered a restriction. From an implementation point of view having penalties is probably preferable because applying a penalty allows you more flexibility like applying a cost to making a turn or applying a greater cost to make a turn across traffic, or at traffic lights ot stop signs, etc.

In my mind "turn-restrictions" could be viewed as dynamic modification to the graph, based on the first link above this might be problematic, while changing the costs to a particular node based on the path to get there might be less problematic.

Please add additional useful comments and research.

dkastl commented 8 years ago

I like the term "turn-penalties". Describing "restrictions" as a special case for "penalties" reminds me a bit how one-way restrictions are handled. While in the beginning we said, that you just need to make the cost "very high" to apply one-way restrictions, it still means, that the route might violate the rule, if there is no other way.

I prefer to use -1 however rather than using high costs, so I would also like to handle turn-restrictions/penalties in a similar way.

cvvergara commented 8 years ago

Family of functions:

using acronyms

TRSP

pgr_TRSP(one to one, one to many, many to one, many to many) pgr_TRSPCost(one to one, one to many, many to one, many to many) pgr_TRSPCostMatrix pgr_TRSPDD(single start point, multiple start point) pgr_TRSPKSP() pgr_TRSPVIA()

TRSPWithPoints

pgr_TRSPWithPoints(one to one, one to many, many to one, many to many) pgr_TRSPWithPointsCost(one to one, one to many, many to one, many to many) pgr_TRSPWithPointsCostMatrix() pgr_TRSPWithPointsDD(single start point, multiple start point) pgr_TRSPWithPointsKSP() pgr_TRSPWithPointsVIA()

Not using acronyms (this is my preference)

turnRestricted

pgr_turnRestricted(one to one, one to many, many to one, many to many) pgr_turnRestrictedCost(one to one, one to many, many to one, many to many) pgr_turnRestrictedCostMatrix pgr_turnRestrictedDD(single start point, multiple start point) pgr_turnRestrictedKSP() pgr_turnRestrictedVIA()

turnRestrictedWithPoints

pgr_turnRestrictedWithPoints(one to one, one to many, many to one, many to many) pgr_turnRestrictedWithPointsCost(one to one, one to many, many to one, many to many) pgr_turnRestrictedWithPointsCostMatrix() pgr_turnRestrictedWithPointsDD(single start point, multiple start point) pgr_turnRestrictedWithPointsKSP() pgr_turnRestrictedWithPointsVIA()

woodbri commented 8 years ago

On 7/8/2016 9:38 PM, Daniel Kastl wrote:

I like the term "turn-penalties". Describing "restrictions" as a special case for "penalties" reminds me a bit how one-way restrictions are handled. While in the beginning we said, that you just need to make the cost "very high" to apply one-way restrictions, it still means, that the route might violate the rule, if there is no other way.

I prefer to use |-1| however rather than using high costs, so I would also like to handle turn-restrictions/penalties in a similar way.

The issue here has more to do with how the code is implemented. We use -1 to remove the edge but with turn restrictions it is potentially much more complicated because the same edges need to be there for some paths through the intersection and not for restricted paths.

So until we understand how we want to build the graph and process it and what constraints that puts on the code it is hard to determine what is possible. Anyway, I hear what you are asking for and tend to agree that that should be the plan if we can make it work that way.


This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

cvvergara commented 8 years ago

-1 on the internal sql query cost & reverse_cost the corresponding (source, target), (target, source) edge is not inserted. (for one way) Internally: if the algorithm needs to remove it, it can be done. if the algorithm needs to recover it, it can be done. if the algorithm needs to change the value, it can be done.

dkastl commented 8 years ago

Don't take my comment as how you should implement it ;-) I'm speaking from the user perspective and I find it better to assign -1 to apply a restriction than a very high cost. That's all. How this is applied internally is a different problem.

cvvergara commented 8 years ago

"no u-turn" "no right turn" "no left turn"

cvvergara commented 8 years ago

currently there is this way of representing "saving restrictions" in sample data

CREATE TABLE restrictions (
    rid BIGINT NOT NULL,
    to_cost FLOAT,
    target_id BIGINT,
    from_edge BIGINT,
    via_path TEXT
);

COPY restrictions (rid, to_cost, target_id, from_edge, via_path) FROM stdin WITH NULL '__NULL__' DELIMITER ',';
1,100,7,4,__NULL__
1,100,11,8,__NULL__
1,100,10,7,__NULL__
2,4,8,3,5
3,100,9,16,__NULL__
\.

and when passed as a parameter to pgr_TRSP

'SELECT to_cost, target_id,
        from_edge || coalesce('','' || via_path, '''') AS via_path
        FROM restrictions'

What would be the wish list for storing the restrictions so its easy to understand/use? (I am asking for a wish list, so we can have options for analysis of pro & con)

dkastl commented 8 years ago

I would say:

Thoughts?

cvvergara commented 8 years ago

(rid, to_cost, target_id, from_edge, via_path) (1, 0,7,4,NULL) (1,100,7,4,NULL) (1,-1,7,4,NULL)

(1, 0,7,4, {1,2,3}) <--- (1,100,7,4, {1,2,3}) (1,-1,7,4, {1,2,3})

this 7,4, {1,2,3} without looking at the documentation can you explain what it means?

woodbri commented 8 years ago

The definition of a restriction is:

For simple restrictions, via_path is NULL as the whole restriction can be defined using target_id and from_edge. For more complex restrictions, you need to define a path of multiple edges that represent the restriction.

woodbri commented 8 years ago

We have the following pages in the wiki related to turn restrictions:

Also the sample data was originally designed for test various simple and complex restrictions.

woodbri commented 8 years ago

Basically, our restriction model is identical to the OSM model: http://wiki.openstreetmap.org/wiki/Relation:restriction

woodbri commented 8 years ago

Here are some references to various papers discussing turn restriction implementation:

cvvergara commented 8 years ago

Here is the link of the current user's documentation: http://docs.pgrouting.org/2.2/en/src/trsp/doc/pgr_trsp.html

cvvergara commented 8 years ago

@sankepallyrohithreddy (rid, to_cost, target_id, from_edge, via_path) (1, 0,7,4, {1,2,3}) <--- This: 7,4, {1,2,3} With the detailed information given above, what do you think it means?

woodbri commented 8 years ago

I will leave the explaination to @sankepallyrohithreddy but will note that for this restriction:

(1, 0,7,4, {1,2,3}) <---

that regardless of the meaning, that the "effect" will be nothing because even if the restriction is triggered, the 0 cost would be the same as if it were not triggered.

rohithsankepally commented 8 years ago

Upon reading through, what I understand is

please correct me if I am wrong.

woodbri commented 8 years ago

@sankepallyrohithreddy so what is the path that is being restricted? ie: what is the sequence of edge ids in the path that is the restriction?

cvvergara commented 8 years ago

I'll rephrase the question. for the current implementation what is the meaning of all of this: (rid, to_cost, target_id, from_edge, via_path) (1, 100,7,4, {1,2,3})

cvvergara commented 8 years ago

@sankepallyrohithreddy can you draw, how the restricted path looks?

rohithsankepally commented 8 years ago

I think I misunderstood the definiton of via_edges. I think it is a sequence of edges which connects the from_edge and the target_edge. I would like to explain the following restriction (rid, to_cost, target_id, from_edge, via_path) (2, 4, 8, 3, {5} ) which is one of the restrictions mentioned in the documentation.

from_edge: v4-----e3------>v3 target_id: v6------e8------>v5, v5------e8------>v6 via_path: v3------e5----->v6

So now when we want to reach from v4 to v5 through the via_path the to_cost applied would be 4.

please correct me if I am wrong.

cvvergara commented 8 years ago

(rid, to_cost, target_id, from_edge, via_path) (2, 4, 8, 3, {5} ) id of the restriction is: 2 cost is: 4 target_id is: 8 <<-- documentation is not clear if its a node or an edge This table has to be used with: 'SELECT to_cost, target_id, from_edge || coalesce('',''||via_path,'''') AS via_path FROM restrictions'); so 3, 5 and 5 are edges ids

so the restriction is you want to go to 8 via 3 and 5. I would understand that e3->e5->8 where 8 is not clear if its a vertex or and edge

cvvergara commented 8 years ago

(rid, to_cost, target_id, from_edge, via_path) (1, 100,7,4, {1,2,3}) I understand that e4->e1->e2->e3->7

woodbri commented 8 years ago

Here is an interesting ticket from OSRM regarding restrictions and CH. https://github.com/Project-OSRM/osrm-backend/issues/2681