Turn Restrictions
Previous  Top  Next

Calculations can be performed calculations in two modes: With or without support for turn restrictions. Before a network is loaded, you will have to decide which mode to use by setting property TurnMode. The internal working of the two modes are quite different, which means performance and RAM requirements are also different:

·Turn restriction mode is app. 2 times as slow as normal mode.  
·Allowing U-turns slow the calculations down further (app. 30%).  
·Turn restriction mode takes up more RAM - see Function NWload for details.  

When adding restrictions to the network you can choose between either a 100% restriction (a negative value) or a delay expressed in the same unit as costs. If cost is measured in minutes, using "1" would add a delay of 1 minute for a specific turn. This could be e.g. a left-turn. Don't use turn-delays combined with shortest path routes - it just wouldn't make sense to add a 1 km to the route, since the reported distances would be wrong.

When querying a route the delay is added just after the turn has been performed: A delay of 2 minutes at node B has no impact on the cost of going from node A to node B, whereas if you move on to the next node, the 2 minutes are reflected in the next node on the route.

Adding turn restrictions

Restrictions can be added, updated and deleted using the same function (TurnRestriction). It is also possible to add restrictions to a normal 4-road intersection in one step by using function TurnStandard. Then no turns are allowed except driving straight through.

It is possible to import/export turn restrictions for easier retrieval at a later time. Use function TurnImport2_TXT and TurnExport2_TXT for this. Similar functions exist for binary formats. All currently defined turn restrictions can be removed with procedure TurnReset.

With the release of RW Net 2.33 a new set of functions has been added to allow mandatory turns and use of external ID's in defining the turn restrictions. Support for complex turn restrictions has also been prepared.

Querying a route

In normal mode, each intersection/node can only be visited once on a route. In turn restriction mode each link can only be travelled once in each direction, but the intersections can be visited several times. This has some implications when mixing the two modes in the same application:

If you call Route with the same node1 and node2, you will get an error code in normal mode, while turn restriction mode will return a valid path, which may be just one link travelled in both directions (if you allow U-turns) or something a little more complicated otherwise depending on your network.

In normal mode you would use a loop like this to query the cost along a route (pascal-code):

route(node1,node2);
length:= RouteFind(node2);
for i:= length downto 1 do
begin
  writeln('Node: ',RouteGetNode(i),' ',GetNodeCost(RouteGetNode(i)),' km');
end;
Writeln('Total cost: ',GetNodeCost(node2));

Since a node can be part of a route more than once in turn restriction mode, you can not use the loop above, but has to use a loop like this instead. The advantage is that this loop will also work in normal mode and produce the same results as above:

Route(node1,node2);
length:= RouteFind(node2);
for i:= length downto 1 do
begin
  write('Node: ',RouteGetNode(i));
  if i=length then writeln(' 0 km') else
    writeln(' ',GetLinkCost(RouteGetLink(i)),' km');
end;
Writeln('Total cost: ',GetNodeCost(node2));