Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group-connectivity-pub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radek Hušek
group-connectivity-pub
Commits
a6754c27
Commit
a6754c27
authored
9 years ago
by
Radek Hušek
Browse files
Options
Downloads
Patches
Plain Diff
init
parents
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
group-connectivity.h
+114
-0
114 additions, 0 deletions
group-connectivity.h
group-connectivity.pyx
+34
-0
34 additions, 0 deletions
group-connectivity.pyx
with
148 additions
and
0 deletions
group-connectivity.h
0 → 100644
+
114
−
0
View file @
a6754c27
#ifndef __GROUP_CONNECTIVITY_H__
#define __GROUP_CONNECTIVITY_H__
namespace
Ring
{
#define MakeRing(Name, Size, Plus, Negate, Multiply, One) \
template < typename T_ > struct Name { \
typedef T_ T; \
enum { size = Size }; \
static T plus(T a, T b) { return Plus; } \
static T negate(T a) { return Negate; } \
static const T zero = 0; \
}
MakeRing
(
Z4
,
4
,
(
a
+
b
)
%
4
,
(
4
-
a
)
%
4
,
(
a
*
b
)
%
4
,
1
);
MakeRing
(
Z2_2
,
4
,
a
^
b
,
a
,
a
&
b
,
3
);
}
#include
<vector>
struct
AbstractTester
{
bool
isConnected
;
std
::
vector
<
size_t
>
classes
;
typedef
unsigned
EdgeId
;
typedef
int
DirectedEdgeId
;
virtual
void
init
(
std
::
vector
<
EdgeId
>
spanningTree
,
std
::
vector
<
std
::
vector
<
DirectedEdgeId
>
>
elementaryCycles
);
virtual
bool
run
();
virtual
~
AbstractTester
()
{}
}
template
<
typename
Ring_
>
struct
Tester
:
public
AbstractTester
{
typedef
Ring_
Ring
;
typedef
typename
Ring
::
T
T
;
typedef
std
::
vector
<
T
>
Mapping
;
// combine(alpha, a, beta, b) calculates a = alpha * a + beta * b
Mapping
&
combine
(
T
alpha
,
Mapping
&
a
,
T
beta
,
const
Mapping
&
b
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
a
[
i
]
=
Ring
::
plus
(
Ring
::
multiply
(
alpha
,
a
[
i
]),
Ring
::
multiply
(
beta
,
b
[
i
]));
return
a
;
}
size_t
numForb
;
std
::
vector
<
EdgeId
>
classEdges
;
std
::
vector
<
std
::
pair
<
EdgeId
,
Mapping
>
>
nonClassEdges
;
virtual
void
init
(
std
::
vector
<
EdgeId
>
spanningTree
,
std
::
vector
<
std
::
vector
<
DirectedEdgeId
>
>
elementaryCycles
)
{
}
Mapping
&
unpack
(
size_t
index
,
Mapping
&
ret
)
{
size_t
m
=
Ring
::
size
-
1
;
for
(
size_t
i
=
0
;
i
<
G
.
edges
();
i
++
)
{
ret
[
i
]
=
(
index
%
m
)
+
1
;
index
/=
m
;
}
return
ret
;
}
Mapping
&
cannonize
(
Mapping
&
map
)
{
for
(
const
auto
&
i
:
nonClassEdges
)
{
if
(
map
[
i
.
first
]
!=
Ring
::
zero
)
combine
(
Ring
::
one
,
map
,
map
[
i
.
first
],
i
.
second
);
}
return
map
;
}
size_t
pack
(
const
Mapping
&
map
)
{
size_t
index
=
0
;
for
(
auto
i
:
classEdges
)
{
index
*=
Ring
::
size
;
index
+=
map
[
i
];
}
return
index
;
}
virtual
bool
run
()
{
Mapping
forb
(
G
.
edges
(),
0
);
for
(
size_t
i
=
0
;
i
<
numForb
;
i
++
)
classes
[
pack
(
cannonize
(
unpack
(
i
,
forb
)))]
++
;
for
(
auto
&
c
:
classes
)
if
(
!
c
)
return
(
isConnected
=
false
);
return
(
isConnected
=
true
);
}
virtual
~
Tester
()
{}
}
#endif
This diff is collapsed.
Click to expand it.
group-connectivity.pyx
0 → 100644
+
34
−
0
View file @
a6754c27
from
libcpp.vector
cimport
vector
cdef
extern
from
"
group-connectivity.h
"
namespace
"
Ring
"
:
cdef
cppclass
Z4
[
T
]:
pass
cdef
cppclass
Z2_2
[
T
]:
pass
cdef
extern
from
"
group-connectivity.h
"
:
cdef
cppclass
AbstractTester
:
bool
isConnected
vector
[
size_t
]
classes
void
init
(
vector
[
unsigned
],
vector
[
vector
[
int
]])
bool
run
()
cdef
cppclass
Tester
[
T
]:
pass
def
groupConnectivityTest
(
G
,
group
=
"
Z4
"
):
st
=
G
.
min_spanning_tree
()
cdef
AbstractTester
*
tester
=
NULL
if
group
==
"
Z4
"
:
tester
=
new
Tester
[
Z4
[
unsigned
]]
elif
group
==
"
Z2_2
"
:
tester
=
new
Tester
[
Z2_2
[
unsigned
]]
assert
(
tester
!=
NULL
)
tester
.
init
()
ret
=
tester
.
run
()
classes
=
tester
.
classes
del
tester
return
(
ret
,
classes
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment