Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tiago Peixoto
graph-tool
Commits
444651a7
Commit
444651a7
authored
Nov 13, 2012
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix make_maximal_planar()
parent
2a05bb3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
80 deletions
+23
-80
src/graph/topology/graph_maximal_planar.cc
src/graph/topology/graph_maximal_planar.cc
+7
-42
src/graph/topology/graph_topology.cc
src/graph/topology/graph_topology.cc
+1
-1
src/graph_tool/topology/__init__.py
src/graph_tool/topology/__init__.py
+15
-37
No files found.
src/graph/topology/graph_maximal_planar.cc
View file @
444651a7
...
...
@@ -27,44 +27,20 @@ using namespace std;
using
namespace
boost
;
using
namespace
graph_tool
;
template
<
class
EdgeMap
>
struct
mark_planar_edge
{
mark_planar_edge
(
EdgeMap
map
,
bool
force
)
:
_map
(
map
),
_force
(
force
)
{}
EdgeMap
_map
;
bool
_force
;
template
<
typename
Graph
,
typename
Vertex
>
void
visit_vertex_pair
(
Vertex
u
,
Vertex
v
,
Graph
&
g
)
{
if
(
!
is_adjacent
(
u
,
v
,
g
))
add_edge
(
u
,
v
,
g
);
}
template
<
typename
Graph
,
typename
Vertex
,
class
EdgePredicate
,
class
VertexPredicate
>
void
visit_vertex_pair
(
Vertex
u
,
Vertex
v
,
UndirectedAdaptor
<
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>
>&
g
)
{
if
(
_force
&&
!
is_adjacent
(
u
,
v
,
g
))
{
add_edge
(
u
,
v
,
g
);
return
;
}
typedef
typename
graph_traits
<
Graph
>::
edge_descriptor
edge_t
;
std
::
pair
<
edge_t
,
bool
>
e
=
edge
(
u
,
v
,
UndirectedAdaptor
<
Graph
>
(
g
.
OriginalGraph
().
m_g
));
if
(
e
.
second
)
_map
[
e
.
first
]
=
true
;
}
};
struct
do_maximal_planar
{
template
<
class
Graph
,
class
VertexIndex
,
class
EdgeIndex
,
class
EdgeMap
>
void
operator
()(
Graph
&
g
,
VertexIndex
vertex_index
,
EdgeIndex
edge_index
,
EdgeMap
emap
,
bool
augment
)
const
template
<
class
Graph
,
class
VertexIndex
,
class
EdgeIndex
>
void
operator
()(
Graph
&
g
,
VertexIndex
vertex_index
,
EdgeIndex
edge_index
)
const
{
unchecked_vector_property_map
...
...
@@ -78,7 +54,7 @@ struct do_maximal_planar
if
(
!
is_planar
)
throw
GraphException
(
"Graph is not planar!"
);
mark_planar_edge
<
EdgeMap
>
vis
(
emap
,
augment
)
;
mark_planar_edge
vis
;
make_biconnected_planar
(
g
,
embedding
,
edge_index
,
vis
);
boyer_myrvold_planarity_test
(
boyer_myrvold_params
::
graph
=
g
,
...
...
@@ -90,20 +66,9 @@ struct do_maximal_planar
};
void
maximal_planar
(
GraphInterface
&
gi
,
boost
::
any
edge_map
,
bool
augment
)
void
maximal_planar
(
GraphInterface
&
gi
)
{
if
(
augment
)
{
run_action
<
graph_tool
::
detail
::
never_directed
,
mpl
::
true_
>
()
(
gi
,
bind
<
void
>
(
do_maximal_planar
(),
_1
,
gi
.
GetVertexIndex
(),
gi
.
GetEdgeIndex
(),
false
,
true
))();
}
else
{
run_action
<
graph_tool
::
detail
::
never_directed
,
mpl
::
true_
>
()
(
gi
,
bind
<
void
>
(
do_maximal_planar
(),
_1
,
gi
.
GetVertexIndex
(),
gi
.
GetEdgeIndex
(),
_2
,
false
),
edge_scalar_properties
())
(
edge_map
);
}
run_action
<
graph_tool
::
detail
::
never_directed
,
mpl
::
true_
>
()
(
gi
,
bind
<
void
>
(
do_maximal_planar
(),
_1
,
gi
.
GetVertexIndex
(),
gi
.
GetEdgeIndex
()))();
}
src/graph/topology/graph_topology.cc
View file @
444651a7
...
...
@@ -32,7 +32,7 @@ bool topological_sort(GraphInterface& gi, vector<int32_t>& sort);
void
dominator_tree
(
GraphInterface
&
gi
,
size_t
entry
,
boost
::
any
pred_map
);
void
transitive_closure
(
GraphInterface
&
gi
,
GraphInterface
&
tcgi
);
bool
is_planar
(
GraphInterface
&
gi
,
boost
::
any
embed_map
,
boost
::
any
kur_map
);
void
maximal_planar
(
GraphInterface
&
gi
,
boost
::
any
edge_map
,
bool
augment
);
void
maximal_planar
(
GraphInterface
&
gi
);
void
subgraph_isomorphism
(
GraphInterface
&
gi1
,
GraphInterface
&
gi2
,
boost
::
any
vertex_label1
,
boost
::
any
vertex_label2
,
boost
::
any
edge_label1
,
boost
::
any
edge_label2
,
...
...
src/graph_tool/topology/__init__.py
View file @
444651a7
...
...
@@ -1328,16 +1328,8 @@ def make_maximal_planar(g, unfilter=False):
Parameters
----------
g : :class:`~graph_tool.Graph`
Graph to be used.
unfilter : bool (optional, default: False)
If true, and the `g` is filtered, the edges will be unfiltered instead
of added. Note that in this case the resulting graph may not be
maximally planar if the necessary edges are not existent in the
underlying unfiltered graph.
Returns
-------
`None`
Graph to be used. It must be a biconnected planar graph with at least 3
vertices.
Notes
-----
...
...
@@ -1346,49 +1338,35 @@ def make_maximal_planar(g, unfilter=False):
creating a non-planar graph. By Euler's formula, a maximal planar graph with
V > 2 vertices always has 3V - 6 edges and 2V - 4 faces.
The input graph to make_maximal_planar() must be a biconnected planar graph
with at least 3 vertices.
This algorithm runs in :math:`O(V + E)` time.
Examples
--------
>>> from numpy.random import seed, random
>>> seed(42)
>>> g = gt.triangulation(random((100,2)))[0]
>>> p, embed_order = gt.is_planar(g, embedding=True)
>>> print(p)
>>> g = gt.lattice([42, 42])
>>> gt.make_maximal_planar(g)
>>> gt.is_planar(g)
True
>>> print(list(embed_order[g.vertex(0)]))
[0, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>>> g = gt.random_graph(100, lambda: 4, directed=False)
>>> p, kur = gt.is_planar(g, kuratowski=True)
>>> print(p)
False
>>> g.set_edge_filter(kur, True)
>>> gt.graph_draw(g, output_size=(300, 300), output="kuratowski.pdf")
>>> print(g.num_vertices(), g.num_edges())
(1764, 5286)
>>> gt.graph_draw(g, output_size=(300, 300), output="maximal_planar.pdf")
<...>
.. figure::
kuratowski
.*
.. figure::
maximal_planar
.*
:align: center
Obstructing Kuratowski subgraph of a random
graph.
A maximally planar
graph.
References
----------
.. [boyer-myrvold] John M. Boyer and Wendy J. Myrvold, "On the Cutting Edge:
Simplified O(n) Planarity by Edge Addition" Journal of Graph Algorithms
and Applications, 8(2): 241-273, 2004. http://www.emis.ams.org/journals/JGAA/accepted/2004/BoyerMyrvold2004.8.3.pdf
.. [boost-planarity] http://www.boost.org/libs/graph/doc/boyer_myrvold.html
.. [boost-planarity] http://www.boost.org/libs/graph/doc/make_maximal_planar.html
"""
if
unfilter
and
g
.
get_edge_filter
()
is
not
None
:
emap
=
g
.
get_edge_filter
()[
0
]
else
:
unfilter
=
False
emap
=
None
g
=
GraphView
(
g
,
directed
=
False
)
libgraph_tool_topology
.
maximal_planar
(
g
.
_Graph__graph
,
_prop
(
"e"
,
g
,
emap
),
not
unfilter
)
libgraph_tool_topology
.
maximal_planar
(
g
.
_Graph__graph
)
def
is_DAG
(
g
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment