File: pgr_lineGraphFull.rst

package info (click to toggle)
pgrouting 4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,332 kB
  • sloc: cpp: 21,315; sql: 10,419; ansic: 9,795; perl: 1,142; sh: 919; javascript: 314; xml: 182; makefile: 29
file content (400 lines) | stat: -rw-r--r-- 11,193 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
:file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2016-2026 pgRouting developers
:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0

.. index::
   single: Transformation Family ; pgr_lineGraphFull
   single: lineGraphFull - Experimental on v2.6

|

``pgr_lineGraphFull`` - Experimental
===============================================================================

``pgr_lineGraphFull`` — Transforms a given graph into a new graph where all of
the vertices from the original graph are converted to line graphs.

.. include:: experimental.rst
   :start-after: warning-begin
   :end-before: end-warning

.. rubric:: Availability

* Version 2.6.0

  * New experimental function.


Description
-------------------------------------------------------------------------------

``pgr_lineGraphFull``, converts original directed graph to a directed line graph
by converting each vertex to a complete graph and keeping all the original
edges.
The new connecting edges have a cost 0 and go between the adjacent original
edges, respecting the directionality.

A possible application of the resulting graph is **"routing with two edge
restrictions"**:

- Setting a cost of using the vertex when routing between edges on the
  connecting edge
- Forbid the routing between two edges by removing the connecting edge

This is possible because each of the intersections (vertices) in the original
graph are now complete graphs that have a new edge for each possible turn across
that intersection.

The main characteristics are:

- This function is for **directed** graphs.
- Results are undefined when a negative vertex id is used in the input graph.
- Results are undefined when a duplicated edge id is used in the input graph.
- Running time: TBD

|Boost| Boost Graph Inside

Signatures
-------------------------------------------------------------------------------

.. rubric:: Summary

.. admonition:: \ \
   :class: signatures

   | pgr_lineGraphFull(`Edges SQL`_)

   | Returns set of |result-linegf|
   | OR EMPTY SET

:Example: Full line graph of subgraph of edges :math:`\{4, 7, 8, 10\}`

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q1
   :end-before: -- q2

Parameters
-------------------------------------------------------------------------------

.. include:: pgRouting-concepts.rst
   :start-after: only_edge_param_start
   :end-before: only_edge_param_end

Inner Queries
-------------------------------------------------------------------------------

Edges SQL
...............................................................................

.. include:: pgRouting-concepts.rst
    :start-after: basic_edges_sql_start
    :end-before: basic_edges_sql_end

Result columns
-------------------------------------------------------------------------------

Returns set of |result-linegf|

.. list-table::
   :width: 81
   :widths: auto
   :header-rows: 1

   * - Column
     - Type
     - Description
   * - ``seq``
     - ``INTEGER``
     - Sequential value starting from **1**.

       - Gives a local identifier for the edge
   * - ``source``
     - ``BIGINT``
     - Identifier of the source vertex of the current edge.

       * When `negative`: the source is the reverse edge in the original graph.
   * - ``target``
     - ``BIGINT``
     - Identifier of the target vertex of the current edge.

       * When `negative`: the target is the reverse edge in the original graph.
   * - ``cost``
     - ``FLOAT``
     - Weight of the edge (``source``, ``target``).

       * When `negative`: edge (``source``, ``target``) does not exist,
         therefore it’s not part of the graph.
   * - ``reverse_cost``
     - ``FLOAT``
     - Weight of the edge (``target``, ``source``).

       * When `negative`: edge (``target``, ``source``) does not exist,
         therefore it’s not part of the graph.

Additional Examples
-------------------------------------------------------------------------------


.. contents::
   :local:

* The examples of this section are based on the :doc:`sampledata` network.
* The examples include the subgraph including edges 4, 7, 8, and 10 with
  ``reverse_cost``.

The data
...............................................................................

This example displays how this graph transformation works to create additional
edges for each possible turn in a graph.

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q0
   :end-before: -- q1

| |first|

.. TODO fix image

.. |first| image:: images/original.png
   :align: middle

The transformation
...............................................................................

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q1
   :end-before: -- q2

.. TODO fix image

| |second|

.. |second| image:: images/transformation.png
   :align: middle

In the transformed graph, all of the edges from the original graph are still
present (yellow), but we now have additional edges for every turn that could be
made across vertex 7 (orange).

Creating table that identifies transformed vertices
...............................................................................

The vertices in the transformed graph are each created by splitting up the
vertices in the original graph.
Unless a vertex in the original graph is a leaf
vertex, it will generate more than one vertex in the transformed graph.
One of the newly created vertices in the transformed graph will be given the
same vertex identifier as the vertex that it was created from in the original
graph, but the rest of the newly created vertices will have negative vertex ids.

Following is an example of how to generate a table that maps the ids of the
newly created vertices with the original vertex that they were created from

Store edge results
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The first step is to store the results of the ``pgr_lineGraphFull`` call into a
table

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q2
   :end-before: -- q3

Create the mapping table
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

From the original graph's vertex information

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q3
   :end-before: -- q4

Add the new vertices

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q4
   :end-before: -- q5

Filling the mapping table
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The positive vertex identifiers are the original identifiers

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q5
   :end-before: -- q6

Inspecting the vertices map

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q6
   :end-before: -- q7

The self loops happen when there is no cost traveling to the ``target`` and the
source has an original value.

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q7
   :end-before: -- q8

Updating values from self loops

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q8
   :end-before: -- q9

Inspecting the vertices table

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q9
   :end-before: -- q10

Updating from inner self loops

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q10
   :end-before: -- q11

Inspecting the vertices map

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q11
   :end-before: -- q12

Adding a soft restriction
...............................................................................

A soft restriction going from vertex 6 to vertex 3 using edges 4 -> 7 is wanted.

Identifying the restriction
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Running a :doc:`pgr_dijkstraNear` the edge with cost 0, edge 8, is where the
cost will be increased

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q12
   :end-before: -- q13

The edge to be altered is ``WHERE cost = 0 AND seq != 1 AND edge != -1`` from
the previous query:

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q13
   :end-before: -- q14

Adding a value to the restriction
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Updating the cost to the edge:

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q14
   :end-before: -- q15

:Example: Routing from :math:`6` to :math:`3`

Now the route does not use edge 8 and does a U turn on a leaf vertex.

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q15
   :end-before: -- q16

Simplifying leaf vertices
...............................................................................

In this example, there is no additional cost for traversing a leaf vertex.

Using the vertex map give the leaf verices their original value.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

On the source column

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q16
   :end-before: -- q17

On the target column

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q17
   :end-before: -- q18

Removing self loops on leaf nodes
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The self loops of the leaf nodes are

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q18
   :end-before: -- q19

Which can be removed

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q19
   :end-before: -- q20

:Example: Routing from :math:`6` to :math:`3`

Routing can be done now using the original vertices id using :doc:`pgr_dijkstra`

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q20
   :end-before: -- q21

Complete routing graph
...............................................................................

Add edges from the original graph
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Add all the edges that are not involved in the line graph process to the new
table

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q21
   :end-before: -- q22

Some administrative tasks to get new identifiers for the edges

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q22
   :end-before: -- q23

Add the newly calculated edges
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q23
   :end-before: -- q24

Using the routing graph
...............................................................................

When using this method for routing with soft restrictions there will be uturns

:Example: Routing from :math:`6` to :math:`3`

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q24
   :end-before: -- q25

:Example: Routing from :math:`5` to :math:`1`

.. literalinclude:: lineGraphFull.queries
   :start-after: -- q25
   :end-before: -- q26

See Also
-------------------------------------------------------------------------------

* https://en.wikipedia.org/wiki/Line_graph
* https://en.wikipedia.org/wiki/Complete_graph

.. rubric:: Indices and tables

* :ref:`genindex`
* :ref:`search`