Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/_static/page_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var titles = [


var newpages = [
{v: '4.1', pages: ['pgr_boyerMyrvold']},

{v: '4.0', pages: ['pgr_bandwidth', 'pgr_kingOrdering', 'pgr_sloanOrdering']},

{v: '3.8', pages: ['pgr_contractionDeadEnd', 'pgr_contractionLinear', 'pgr_separateCrossing',
Expand Down
1 change: 1 addition & 0 deletions doc/planar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License: GPL-2 See https://github.com/pgRouting/pgrouting/blob/main/LICENSE

set(LOCAL_FILES
pgr_boyerMyrvold.rst
pgr_isPlanar.rst
)

Expand Down
135 changes: 135 additions & 0 deletions doc/planar/pgr_boyerMyrvold.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
:file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2020-2026 pgRouting developers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the file is originally from 2026 so

:copyright: Copyright (c) 2026-2026 pgRouting developers

:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0

.. index::
single: Planar Family ; pgr_boyerMyrvold
single: boyerMyrvold

|
``pgr_boyerMyrvold`` - Experimental
===============================================================================

``pgr_boyerMyrvold`` — Returns the planar embedding of a graph, if the graph is
planar.

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

.. rubric:: Availability

* Version 4.1.0

* New experimental function.


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

A planar embedding of a graph is a mapping of the graph onto a plane such that
no two edges cross. Given a graph, the Boyer-Myrvold planarity testing algorithm
can produce a planar embedding if the graph is planar, or identify a Kuratowski
subgraph (a subdivision of :math:`K_5` or :math:`K_{3,3}`) if it is not.

The main characteristics are:

* This implementation uses the Boyer-Myrvold Planarity Testing.
* Returns the edges of the planar embedding when the graph is planar.
* If the graph is not planar, it returns an empty set.
* Applicable only for **undirected** graphs.
* The algorithm does not consider traversal costs in the calculations.
* Running time: :math:`O(|V|)`

|Boost| Boost Graph Inside

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

.. rubric:: Summary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one function so no summary word is needed


.. admonition:: \ \
:class: signatures

| pgr_boyerMyrvold(`Edges SQL`)
| RETURNS SETOF |result-edge|
:Example: Get the planar embedding of the graph

.. literalinclude:: boyerMyrvold.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 ``(seq, source, target, cost)``

============== =========== ==========================================
Column Type Description
============== =========== ==========================================
``seq`` ``BIGINT`` Sequential value starting from :math:`1`.
``source`` ``BIGINT`` Identifier of the source vertex.
``target`` ``BIGINT`` Identifier of the target vertex.
``cost`` ``FLOAT`` Cost of the edge.
============== =========== ==========================================

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

.. contents::
:local:

Making a non planar graph
...............................................................................

Adding extra edges to create a :math:`K_5` subgraph.

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

The graph is no longer planar, so the result is empty:

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

Using with pgr_connectedComponents
...............................................................................

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

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

* :doc:`pgr_isPlanar`
* :doc:`sampledata`
* `Boost: Boyer Myrvold
<https://www.boost.org/libs/graph/doc/boyer_myrvold.html>`__

.. rubric:: Indices and tables

* :ref:`genindex`
* :ref:`search`
2 changes: 2 additions & 0 deletions doc/src/experimental.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ Experimental Functions

.. rubric:: Planar Family

- :doc:`pgr_boyerMyrvold`
- :doc:`pgr_isPlanar`

.. toctree::
:hidden:

pgr_boyerMyrvold
pgr_isPlanar

.. rubric:: Miscellaneous Algorithms
Expand Down
102 changes: 68 additions & 34 deletions docqueries/planar/boyerMyrvold.result
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,100 @@ SET
/* :file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2018-2026 pgRouting developers
:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */
-- q1
/* -- q1 */
SELECT * FROM pgr_boyerMyrvold(
'SELECT id, source, target, cost, reverse_cost
FROM edge_table'
FROM edges'
);
seq | source | target | cost
-----+--------+--------+------
1 | 1 | 2 | 1
2 | 3 | 2 | 1
3 | 4 | 3 | 1
4 | 2 | 5 | 1
5 | 3 | 6 | 1
6 | 7 | 8 | 1
7 | 8 | 5 | 1
8 | 5 | 6 | 1
9 | 6 | 9 | 1
10 | 5 | 10 | 1
11 | 6 | 11 | 1
12 | 10 | 11 | 1
13 | 11 | 12 | 1
14 | 10 | 13 | 1
15 | 9 | 12 | 1
16 | 4 | 9 | 1
17 | 14 | 15 | 1
18 | 16 | 17 | 1
1 | 1 | 3 | 1
2 | 3 | 7 | 1
3 | 6 | 7 | 1
4 | 10 | 11 | 1
5 | 7 | 11 | 1
6 | 8 | 12 | 1
7 | 11 | 12 | 1
8 | 7 | 8 | 1
9 | 2 | 4 | 1
10 | 8 | 9 | 1
11 | 13 | 14 | 1
12 | 12 | 17 | 1
13 | 16 | 17 | 1
14 | 15 | 16 | 1
15 | 11 | 16 | 1
16 | 15 | 10 | 1
17 | 5 | 6 | 1
18 | 10 | 6 | 1
(18 rows)

-- q2
INSERT INTO edge_table (source, target, cost, reverse_cost) VALUES
/* -- q2 */
INSERT INTO edges (source, target, cost, reverse_cost) VALUES
(1,3,1,-1),(1,4,1,-1),(1,5,1,-1),(2,4,1,-1),(2,5,1,-1),(3,5,1,-1),(4,5,1,-1);
INSERT 0 7
-- q3
/* -- q3 */
SELECT * FROM pgr_boyerMyrvold(
'SELECT id, source, target, cost, reverse_cost
FROM edge_table'
FROM edges'
);
seq | source | target | cost
-----+--------+--------+------
(0 rows)
1 | 1 | 3 | 1
2 | 1 | 4 | 1
3 | 1 | 5 | 1
4 | 2 | 4 | 1
5 | 2 | 5 | 1
6 | 3 | 5 | 1
7 | 4 | 5 | 1
8 | 1 | 3 | 1
9 | 3 | 7 | 1
10 | 6 | 7 | 1
11 | 10 | 11 | 1
12 | 7 | 11 | 1
13 | 8 | 12 | 1
14 | 11 | 12 | 1
15 | 7 | 8 | 1
16 | 2 | 4 | 1
17 | 8 | 9 | 1
18 | 13 | 14 | 1
19 | 12 | 17 | 1
20 | 16 | 17 | 1
21 | 15 | 16 | 1
22 | 11 | 16 | 1
23 | 15 | 10 | 1
24 | 5 | 6 | 1
25 | 10 | 6 | 1
(25 rows)

-- q4
/* -- q4 */
SELECT * FROM pgr_boyerMyrvold(
$$
SELECT id, source, target, cost, reverse_cost FROM edge_table
SELECT id, source, target, cost, reverse_cost FROM edges
where source = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ')
'SELECT id, source, target, cost, reverse_cost FROM edges ')
WHERE component = 14)
)
OR
target = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edge_table ')
'SELECT id, source, target, cost, reverse_cost FROM edges ')
WHERE component = 14)
)
$$
);
seq | source | target | cost
-----+--------+--------+------
1 | 14 | 15 | 1
(1 row)
ERROR: No edges found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, the inner query is not returning edges

SELECT node FROM pgr_connectedComponents(
                            'SELECT id, source, target, cost, reverse_cost FROM edges ')
                        WHERE component = 14;
 node 
------
(0 rows)

but this one works:

SELECT node FROM pgr_connectedComponents(
                            'SELECT id, source, target, cost, reverse_cost FROM edges ')
                        WHERE component = 13;
 node 
------
   13
   14
(2 rows)

HINT:
SELECT id, source, target, cost, reverse_cost FROM edges
where source = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edges ')
WHERE component = 14)
)
OR
target = any (ARRAY(SELECT node FROM pgr_connectedComponents(
'SELECT id, source, target, cost, reverse_cost FROM edges ')
WHERE component = 14)
)

-- q5
CONTEXT: SQL function "pgr_boyermyrvold" statement 1
/* -- q5 */
ROLLBACK;
ROLLBACK
1 change: 1 addition & 0 deletions docqueries/planar/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
%main::tests = (
'any' => {
'files' => [qw(
boyerMyrvold.pg
isPlanar.pg
)]
},
Expand Down
2 changes: 1 addition & 1 deletion include/drivers/planar/boyerMyrvold_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct IID_t_rt IID_t_rt;
#ifdef __cplusplus
extern "C" {
#endif
void pgr_do_pgr_boyerMyrvold(
void pgr_do_boyerMyrvold(
const char*,
IID_t_rt**, size_t*,
char**, char**, char**);
Expand Down
1 change: 0 additions & 1 deletion include/planar/boyerMyrvold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>
#include <boost/graph/is_kuratowski_subgraph.hpp>
#include <boost/ref.hpp>

#include "cpp_common/messages.hpp"
Expand Down
Loading