Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdc-counting
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radek Hušek
cdc-counting
Commits
a1a24473
Commit
a1a24473
authored
3 years ago
by
Radek Hušek
Browse files
Options
Downloads
Patches
Plain Diff
drop test_cycle.py
parent
75fab70c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_cycle.py
+0
-143
0 additions, 143 deletions
test_cycle.py
with
0 additions
and
143 deletions
test_cycle.py
deleted
100644 → 0
+
0
−
143
View file @
75fab70c
from
graph_tools.base
import
*
from
graph_tools.parameters
import
CircuitDoubleCover
,
CycleDoubleCover
,
VertexCount
from
graph_tools.misc
import
sun
from
sage.all
import
MixedIntegerLinearProgram
from
itertools
import
permutations
verbose
=
False
def
solve_gadget
(
g
,
alt_gadgets
,
param
=
CycleDoubleCover
(
5
)):
N
=
g
.
size
()
P
=
MixedIntegerLinearProgram
(
maximization
=
False
)
V
=
P
.
new_variable
(
real
=
True
,
nonnegative
=
True
)
P_dual
=
MixedIntegerLinearProgram
(
maximization
=
True
)
V_dual
=
P_dual
.
new_variable
(
real
=
True
,
nonnegative
=
True
)
BOUNDARIES
=
list
(
param
.
enumerate_boundaries
(
N
))
def
fake_gadget
(
b
):
return
FakeGadget
(
N
,
[
Boundary
(
b
,
1
)
])
def
join
(
a
,
b
):
return
Gadget
.
join
([
a
,
b
],
[
((
1
,
i
),
(
2
,
i
))
for
i
in
range
(
1
,
N
+
1
)
],
[])
def
gadget_to_multiplicity_vector
(
gadget
):
return
[
join
(
fake_gadget
(
b
),
gadget
).
eval
(
param
)
for
b
in
BOUNDARIES
]
dual_objective
=
0
dual_constraints
=
[
0
]
*
len
(
BOUNDARIES
)
def
gadget_to_constraint
(
gadget
,
var
):
nonlocal
dual_objective
mv
=
gadget_to_multiplicity_vector
(
gadget
)
n
=
VertexCount
.
finalize
(
gadget
.
eval_gadget
(
VertexCount
))
P
.
add_constraint
(
sum
(
a
*
V
[
b
]
for
a
,
b
in
zip
(
mv
,
BOUNDARIES
)
)
>=
2
**
(
n
//
2
))
for
i
,
a
in
enumerate
(
mv
):
dual_constraints
[
i
]
+=
a
*
V_dual
[
var
]
dual_objective
+=
2
**
(
n
//
2
)
*
V_dual
[
var
]
for
i
,
ag
in
enumerate
(
alt_gadgets
):
gadget_to_constraint
(
ag
,
i
)
P_dual
.
set_objective
(
dual_objective
)
mv
=
gadget_to_multiplicity_vector
(
g
)
P
.
set_objective
(
sum
(
a
*
V
[
b
]
for
a
,
b
in
zip
(
mv
,
BOUNDARIES
)
))
for
b
,
const
in
zip
(
mv
,
dual_constraints
):
P_dual
.
add_constraint
(
const
<=
b
)
ret
=
(
P
.
solve
(),
P_dual
.
solve
(),
2
**
(
VertexCount
.
finalize
(
g
.
eval_gadget
(
VertexCount
))
//
2
)
)
if
verbose
:
#P_dual.show()
for
i
,
v
in
sorted
(
P_dual
.
get_values
(
V_dual
).
items
()):
print
(
'
w_%s = %s
'
%
(
i
,
v
))
return
ret
def
friend_boundary
(
g
,
param
):
N
=
g
.
size
();
BOUNDARIES
=
list
(
param
.
enumerate_boundaries
(
N
))
def
test_boundary
(
b
):
fg
=
FakeGadget
(
N
,
[
Boundary
(
b
,
1
)
])
joins
=
[
((
1
,
i
),
(
2
,
i
))
for
i
in
range
(
1
,
N
+
1
)
]
return
(
b
,
Gadget
.
join
([
fg
,
g
],
joins
,
[]).
eval
(
param
))
return
[
test_boundary
(
b
)
for
b
in
BOUNDARIES
]
def
rot
(
l
,
x
):
return
l
[
x
:]
+
l
[:
x
]
G4
=
[
Gadget
.
join
([
CUBIC_VERTEX
]
*
2
,
[((
1
,
1
),
(
2
,
1
))],
[
(
1
,
2
),
(
1
,
3
),
(
2
,
2
),
(
2
,
3
)
]),
Gadget
.
join
([
CUBIC_VERTEX
]
*
2
,
[((
1
,
1
),
(
2
,
1
))],
[
(
1
,
2
),
(
2
,
2
),
(
1
,
3
),
(
2
,
3
)
]),
Gadget
.
join
([
CUBIC_VERTEX
]
*
2
,
[((
1
,
1
),
(
2
,
1
))],
[
(
1
,
2
),
(
2
,
2
),
(
2
,
3
),
(
1
,
3
)
]),
]
G4f
=
[
Gadget
.
join
([
FREE_EDGE
]
*
2
,
[],
[
(
1
,
1
),
(
1
,
2
),
(
2
,
1
),
(
2
,
2
)
]),
Gadget
.
join
([
FREE_EDGE
]
*
2
,
[],
[
(
1
,
1
),
(
2
,
1
),
(
2
,
2
),
(
1
,
2
)
]),
Gadget
.
join
([
FREE_EDGE
]
*
2
,
[],
[
(
1
,
1
),
(
2
,
1
),
(
1
,
2
),
(
2
,
2
)
]),
]
G5fp
=
[
Gadget
.
join
([
CUBIC_VERTEX
,
FREE_EDGE
],
[],
rot
([
(
1
,
1
),
(
1
,
2
),
(
1
,
3
),
(
2
,
1
),
(
2
,
2
)
],
i
))
for
i
in
range
(
5
)
]
G5t
=
[
Gadget
.
join
([
CUBIC_VERTEX
]
*
3
,
[((
1
,
1
),
(
2
,
1
)),
((
2
,
2
),
(
3
,
2
))],
list
(
out
))
for
out
in
permutations
([
(
1
,
2
),
(
1
,
3
),
(
2
,
3
),
(
3
,
1
),
(
3
,
3
)
])
]
G5f
=
[
Gadget
.
join
([
CUBIC_VERTEX
,
FREE_EDGE
],
[],
list
(
out
))
for
out
in
permutations
([
(
1
,
1
),
(
1
,
2
),
(
1
,
3
),
(
2
,
1
),
(
2
,
2
)
])
]
G5s
=
[
Gadget
.
join
([
CUBIC_VERTEX
]
*
3
,
[((
1
,
1
),
(
2
,
1
)),
((
2
,
2
),
(
3
,
2
))],
rot
([
(
1
,
2
),
(
1
,
3
),
(
2
,
3
),
(
3
,
1
),
(
3
,
3
)
],
i
))
for
i
in
range
(
5
)
]
G6
=
[
Gadget
.
join
([
FREE_EDGE
]
*
3
,
[],
rot
([
(
1
,
1
),
(
1
,
2
),
(
2
,
1
),
(
2
,
2
),
(
3
,
1
),
(
3
,
2
)
],
i
))
for
i
in
range
(
6
)
]
if
__name__
==
"
__main__
"
:
import
sys
verbose
=
"
-v
"
in
sys
.
argv
# print("6-cycle replaced by matchings: %s" % (
# solve_gadget(sun(6), G6),))
print
(
"
3-cycle replaced by vertex: %s
"
%
(
solve_gadget
(
sun
(
3
),
[
CUBIC_VERTEX
]),))
print
(
"
4-cycle replaced by all 3 matchings: %s
"
%
(
solve_gadget
(
sun
(
4
),
G4f
),))
print
(
"
4-cycle replaced by noncrossing matchings: %s
"
%
(
solve_gadget
(
sun
(
4
),
G4f
[:
2
]),))
print
(
"
5-cycle replaced by a non-crossing cubic vertex and an edge: %s
"
%
(
solve_gadget
(
sun
(
5
),
G5fp
),))
print
(
"
5-cycle replaced by a tree: %s
"
%
(
solve_gadget
(
sun
(
5
),
G5t
),))
print
(
"
5-cycle replaced by a cubic vertex and an edge: %s
"
%
(
solve_gadget
(
sun
(
5
),
G5f
),))
print
(
"
5-cycle replaced by a non-crossing tree: %s
"
%
(
solve_gadget
(
sun
(
5
),
G5s
),))
# l = sorted(friend_boundary(sun(5)), key=lambda x: x[1])
# print(len(l))
# for x in l: print(x)
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