1616``pgr_degree `` -- Proposed
1717===============================================================================
1818
19- ``pgr_degree `` — For each vertex in an undirected graph, return the count of edges incident to the vertex.
19+ ``pgr_degree `` — For each vertex in an undirected graph, return the count of
20+ edges incident to the vertex.
2021
2122
2223.. include :: proposed.rst
2829.. rubric :: Version 3.8.0
2930
3031* Error messages adjustment.
32+ * New signature with only Edges SQL.
3133
3234.. rubric :: Version 3.4.0
3335
3739Description
3840-------------------------------------------------------------------------------
3941
40- Calculates the degree of the vertices of an ** undirected ** graph
42+ Calculates the degree of the vertices of an undirected graph
4143
44+ The degree (or valency) of a vertex of a graph is the number of edges that are
45+ incident to the vertex.
4246
43- |Boost | Boost Graph Inside
47+ - Works for **undirected ** graphs.
48+ - A loop contributes 2 to a vertex's degree.
49+ - A vertex with degree 0 is called an isolated vertex.
50+
51+ - Isolated vertex is not part of the result
52+
53+ - Vertex not participating on the subgraph is considered and isolated vertex.
54+ - There can be a ``dryrun `` execution and the code used to get the answer will
55+ be shown in a PostgreSQL ``NOTICE ``.
56+
57+ - The code can be used as base code for the particular application
58+ requirements.
59+
60+ - No ordering is performed.
4461
4562Signatures
4663-------------------------------------------------------------------------------
4764
4865.. admonition :: \ \
4966 :class: signatures
5067
68+ | pgr_degree(`Edges SQL`_ , [``dryrun``])
5169 | pgr_degree(`Edges SQL`_ , `Vertex SQL`_, [``dryrun``])
5270
5371 | RETURNS SETOF |result-degree|
5472 | OR EMPTY SET
5573
56- :Example: Extracting the vertex information
74+ .. index ::
75+ single: degree - Proposed ; Edges and Vertices - Proposed on v3.4
76+
77+ Edges
78+ ...............................................................................
79+
80+ .. admonition :: \ \
81+ :class: signatures
5782
58- pgr_degree can utilize output from `pgr_extractVertices ` or can have `pgr_extractVertices ` embedded in the call.
59- For decent size networks, it is best to prep your vertices table before hand and use that vertices table
60- for pgr_degree calls.
83+ | pgr_degree(`Edges SQL`_ , [``dryrun``])
84+
85+ | RETURNS SETOF |result-degree|
86+ | OR EMPTY SET
87+
88+ :example: Get the degree of the vertices defined on the edges table
6189
6290.. literalinclude :: degree.queries
6391 :start-after: -- q1
6492 :end-before: -- q2
6593
94+ Edges and Vertices
95+ ...............................................................................
96+
97+ .. admonition :: \ \
98+ :class: signatures
99+
100+ | pgr_degree(`Edges SQL`_ , `Vertex SQL`_, [``dryrun``])
101+
102+ | RETURNS SETOF |result-degree|
103+ | OR EMPTY SET
104+
105+ :Example: Extracting the vertex information
106+
107+ ``pgr_degree `` can use :doc: `pgr_extractVertices ` embedded in the call.
108+
109+ For decent size networks, it is best to prepare your vertices table before hand
110+ and use it on ``pgr_degree `` calls. (See `Using a vertex table `_)
111+
112+ Calculate the degree of the nodes:
113+
114+ .. literalinclude :: degree.queries
115+ :start-after: -- q2
116+ :end-before: -- q3
117+
118+ .. index ::
119+ single: degree- Proposed ; Edges - Proposed on v3.4
120+
66121
67122Parameters
68123-------------------------------------------------------------------------------
@@ -77,8 +132,6 @@ Parameter Type Description
77132Optional parameters
78133-------------------------------------------------------------------------------
79134
80- .. TODO move to pgRouting concepts
81-
82135=========== ============= ========== =======================================
83136Parameter Type Default Description
84137=========== ============= ========== =======================================
@@ -95,18 +148,44 @@ Inner Queries
95148Edges SQL
96149...............................................................................
97150
98- .. TODO move to pgRouting concepts
151+ .. rubric :: For the `Edges and Vertices`_ signature:
152+
153+ .. list-table ::
154+ :width: 81
155+ :widths: auto
156+ :header-rows: 1
157+
158+ * - Column
159+ - Type
160+ - Description
161+ * - ``id ``
162+ - ``BIGINT ``
163+ - Identifier of the edge.
164+
165+ For the `Edges `_ signature:
166+
167+ .. list-table ::
168+ :width: 81
169+ :widths: auto
170+ :header-rows: 1
99171
100- ================= =================== ===================================
101- Column Type Description
102- ================= =================== ===================================
103- ``id `` ``BIGINT `` Identifier of the edge.
104- ================= =================== ===================================
172+ * - Column
173+ - Type
174+ - Description
175+ * - ``id ``
176+ - ``BIGINT ``
177+ - Identifier of the edge.
178+ * - ``source ``
179+ - ``BIGINT ``
180+ - Identifier of the first end point vertex of the edge.
181+ * - ``target ``
182+ - ``BIGINT ``
183+ - Identifier of the second end point vertex of the edge.
105184
106185Vertex SQL
107186...............................................................................
108187
109- .. TODO move to pgRouting concepts
188+ .. rubric :: For the `Edges and Vertices`_ signature:
110189
111190.. list-table ::
112191 :width: 81
@@ -136,8 +215,6 @@ Vertex SQL
136215Result columns
137216-------------------------------------------------------------------------------
138217
139- .. TODO move to pgRouting concepts
140-
141218.. list-table ::
142219 :width: 81
143220 :widths: auto
@@ -159,12 +236,101 @@ Additional Examples
159236.. contents ::
160237 :local:
161238
239+ Degree of a loop
240+ ...............................................................................
241+
242+ A loop contributes 2 to a vertex's degree.
243+
244+ .. graphviz ::
245+
246+ graph G {
247+ 2 [shape=circle;style=filled;color=green;fontsize=8;width=0.3;fixedsize=true];
248+ 2 -- 2 [label="1",fontsize=8];
249+ }
250+
251+ .. rubric :: Using the `Edges`_ signature.
252+
253+ .. literalinclude :: degree.queries
254+ :start-after: -- q3
255+ :end-before: -- q4
256+
257+ .. rubric :: Using the `Edges and Vertices`_ signature.
258+
259+ .. literalinclude :: degree.queries
260+ :start-after: -- q4
261+ :end-before: -- q5
262+
162263Degree of a sub graph
163264...............................................................................
164265
266+ For the following is a subgraph of the :doc: `sampledata `:
267+
268+ - :math: `E = \{(1 , 5 \leftrightarrow 6 ), (1 , 6 \leftrightarrow 10 )\}`
269+ - :math: `V = \{ 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 \}`
270+
271+
272+ .. graphviz ::
273+
274+ graph G {
275+ 5,6,10 [shape=circle;style=filled;color=lightgreen;fontsize=8;width=0.3;fixedsize=true];
276+ 1,2,3,4,7,8,9,11,12,13,14,15,16,17 [shape=circle;style=filled;color=cyan;fontsize=8;width=0.3;fixedsize=true];
277+
278+ 5 -- 6 [label="1",fontsize=8];
279+ 10 -- 6 [label="2",fontsize=8];
280+
281+ 1 [pos="0,2!"];
282+ 2 [pos="0.5,3.5!"];
283+ 3 [pos="1,2!"];
284+ 4 [pos="2,3.5!"];
285+ 5 [pos="2,0!"];
286+ 6 [pos="2,1!"];
287+ 7 [pos="2,2!"];
288+ 8 [pos="2,3!"];
289+ 9 [pos="2,4!"];
290+ 10 [pos="3,1!"];
291+ 11 [pos="3,2!"];
292+ 12 [pos="3,3!"];
293+ 13 [pos="3.5,2.3!"];
294+ 14 [pos="3.5,4!"];
295+ 15 [pos="4,1!"];
296+ 16 [pos="4,2!"];
297+ 17 [pos="4,3!"];
298+ }
299+
300+ The vertices not participating on the edge are considered isolated
301+
302+ - their degree is 0 in the subgraph and
303+ - their degree is not shown in the output.
304+
305+ .. rubric :: Using the `Edges`_ signature.
306+
307+ .. literalinclude :: degree.queries
308+ :start-after: -- q5
309+ :end-before: -- q6
310+
311+ .. rubric :: Using the `Edges and Vertices`_ signature.
312+
313+ .. literalinclude :: degree.queries
314+ :start-after: -- q6
315+ :end-before: -- q7
316+
317+ Using a vertex table
318+ ...............................................................................
319+
320+ For decent size networks, it is best to prepare your vertices table before hand
321+ and use it on ``pgr_degree `` calls.
322+
323+ Extract the vertex information and save into a table:
324+
165325.. literalinclude :: degree.queries
166- :start-after: -- q2
167- :end-before: -- q3
326+ :start-after: -- q8
327+ :end-before: -- q9
328+
329+ Calculate the degree of the nodes:
330+
331+ .. literalinclude :: degree.queries
332+ :start-after: -- q9
333+ :end-before: -- q10
168334
169335Dry run execution
170336...............................................................................
@@ -176,20 +342,33 @@ The results can be used as base code to make a refinement based on the backend
176342development needs.
177343
178344.. literalinclude :: degree.queries
179- :start-after: -- q3
180- :end-before: -- q4
345+ :start-after: -- q10
346+ :end-before: -- q11
181347
182- Degree from an existing table
348+ Finding dead ends
183349...............................................................................
184- If you have a vertices table already built using ``pgr_extractVertices ``
185- and want the degree of the whole graph rather than a subset, you can forgo using pgr_degree
186- and work with the ``in_edges `` and ``out_edges `` columns directly.
187350
351+ If there is a vertices table already built using ``pgr_extractVertices ``
352+ and want the degree of the whole graph rather than a subset, it can be forgo using
353+ ``pgr_degree `` and work with the ``in_edges `` and ``out_edges `` columns
354+ directly.
355+
356+ The degree of a dead end is 1.
188357
189358.. include :: pgRouting-concepts.rst
190359 :start-after: degree_from_table_start
191360 :end-before: degree_from_table_end
192361
362+ Finding linear vertices
363+ ...............................................................................
364+
365+ The degree of a linear vertex is 2.
366+
367+ If there is a vertices table already built using the ``pgr_extractVertices ``
368+
369+ .. include :: pgRouting-concepts.rst
370+ :start-after: linear_degree_from_table_start
371+ :end-before: linear_degree_from_table_end
193372
194373See Also
195374-------------------------------------------------------------------------------
0 commit comments