Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Radek Hušek
group-connectivity-pub
Commits
0efdd348
Commit
0efdd348
authored
Dec 10, 2015
by
Radek Hušek
Committed by
Radek Hušek
Nov 09, 2017
Browse files
Implement Python part of 2-cut optimization
parent
4a9adc94
Changes
2
Hide whitespace changes
Inline
Side-by-side
group-connectivity.h
View file @
0efdd348
...
...
@@ -158,7 +158,7 @@ struct Tester : public AbstractTester {
#endif
Mapping
&
can
n
onize
(
Mapping
&
map
)
{
Mapping
&
canonize
(
Mapping
&
map
)
{
for
(
const
auto
&
i
:
nonClassEdges
)
{
#if OPTIMIZE_COMBINE
if
(
map
[
i
.
first
]
!=
Ring
::
zero
)
...
...
@@ -225,11 +225,11 @@ struct Tester : public AbstractTester {
do
{
Mapping
copy
(
forb
);
INC
(
classes
[
pack
(
can
n
onize
(
copy
))]);
INC
(
classes
[
pack
(
canonize
(
copy
))]);
}
while
(
nextForb
(
forb
));
# else
for
(
size_t
i
=
0
;
i
<
numForb
;
i
++
)
INC
(
classes
[
pack
(
can
n
onize
(
unpack
(
i
,
forb
)))]);
INC
(
classes
[
pack
(
canonize
(
unpack
(
i
,
forb
)))]);
# endif
for
(
const
auto
&
c
:
classes
)
if
(
!
c
)
return
(
isConnected
=
false
);
...
...
groupConnectivity.pyx
View file @
0efdd348
...
...
@@ -25,6 +25,7 @@ cdef extern from "group-connectivity.h":
cdef
cppclass
Tester
[
T
](
AbstractTester
):
pass
def
pathToEdges
(
G
,
path
):
ret
=
[]
u
=
path
[
0
]
...
...
@@ -35,7 +36,9 @@ def pathToEdges(G, path):
u
=
v
return
ret
def
testGroupConnectivity
(
G
,
group
=
"Z4"
,
getClasses
=
False
,
debug
=
False
):
def
testGroupConnectivity
(
G
,
group
=
"Z4"
,
getClasses
=
False
,
useTwoCuts
=
False
,
debug
=
False
):
cdef
AbstractTester
*
tester
=
NULL
if
group
==
"Z4"
:
tester
=
new
Tester
[
Z4
[
int
]]()
...
...
@@ -46,6 +49,9 @@ def testGroupConnectivity(G, group = "Z4", getClasses = False, debug = False):
assert
(
tester
!=
NULL
)
if
useTwoCuts
:
G
.
relabel
()
i
=
1
for
(
u
,
v
,
_
)
in
G
.
edge_iterator
():
G
.
set_edge_label
(
u
,
v
,
i
)
...
...
@@ -59,11 +65,37 @@ def testGroupConnectivity(G, group = "Z4", getClasses = False, debug = False):
spanningTreeEdges
=
[
l
for
(
_
,
_
,
l
)
in
spanningTree
.
edge_iterator
()
]
twoCuts
=
[]
if
useTwoCuts
:
availableEdges
=
set
(
spanningTreeEdges
)
for
v
in
[
v
for
v
in
G
.
vertices
()
if
G
.
degree
(
v
)
==
2
]:
e
,
f
=
G
.
edges_incident
(
v
)
el
=
e
[
2
]
fl
=
f
[
2
]
if
el
not
in
availableEdges
or
fl
not
in
availableEdges
:
continue
availableEdges
.
remove
(
el
)
availableEdges
.
remove
(
fl
)
w1
=
e
[
0
]
if
e
[
0
]
!=
v
else
e
[
1
]
w2
=
f
[
0
]
if
f
[
0
]
!=
v
else
f
[
1
]
if
w1
>
v
:
el
*=
-
1
if
w2
<
v
:
fl
*=
-
1
if
debug
:
print
"twoCut> "
,
v
,
w1
,
w2
,
el
,
fl
,
(
w1
>
v
),
(
w2
<
v
)
twoCuts
.
append
((
el
,
fl
))
if
debug
:
print
"Spanning Tree: "
,
spanningTreeEdges
print
"Elementary cycles: "
,
elemCycles
print
"Two cuts: "
,
twoCuts
tester
.
init
(
G
.
num_edges
(),
spanningTreeEdges
,
[]
,
elemCycles
)
tester
.
init
(
G
.
num_edges
(),
spanningTreeEdges
,
twoCuts
,
elemCycles
)
ret
=
tester
.
run
()
if
getClasses
:
...
...
@@ -74,6 +106,7 @@ def testGroupConnectivity(G, group = "Z4", getClasses = False, debug = False):
del
tester
return
ret
def
subdivisionIterator
(
G
,
edges
=
None
):
if
edges
is
None
:
edges
=
G
.
edges
()
...
...
Write
Preview
Supports
Markdown
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