Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bachelor Mario Surlemont
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
general
albi
Bachelor Mario Surlemont
Commits
793dbb62
Commit
793dbb62
authored
5 years ago
by
msurl
Browse files
Options
Downloads
Patches
Plain Diff
added missing comments and print for number of preadded constraints
parent
ba531f39
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/conda package/k_hop_dominating_set_gurobi/k_hop_dominating_set_gurobi/k_hop_dom_set.py
+15
-35
15 additions, 35 deletions
...g_set_gurobi/k_hop_dominating_set_gurobi/k_hop_dom_set.py
with
15 additions
and
35 deletions
python/conda package/k_hop_dominating_set_gurobi/k_hop_dominating_set_gurobi/k_hop_dom_set.py
+
15
−
35
View file @
793dbb62
...
...
@@ -192,14 +192,19 @@ class RootedConnectecKHopDominatingSet(ConnectedKHopDominatingSet):
self
.
m
.
addConstr
(
self
.
nodes
[
root
]
>=
1
)
# self.add_all_combinations_root_separators()
print
(
"
neighborhood separators:
"
)
self
.
add_all_neighborhood_root_separators
()
# self.add_single_root_separators()
print
(
"
single node separators:
"
)
self
.
add_single_root_separators
()
def
add_single_root_separators
(
self
):
number_of_found_separators
=
0
for
i
in
self
.
G
.
nodes
:
min_ij_sep
=
ConnectedKHopDominatingSet
.
min_ij_separator
(
G
,
i
,
self
.
root
,
{
i
})
if
min_ij_sep
:
self
.
m
.
addConstr
(
gp
.
quicksum
(
self
.
nodes
[
s
]
for
s
in
min_ij_sep
)
>=
self
.
nodes
[
i
])
number_of_found_separators
+=
1
print
(
f
"
number of preadded separators:
{
number_of_found_separators
}
"
)
# ToDo: refactor!
def
add_all_neighborhood_root_separators
(
self
):
...
...
@@ -215,47 +220,25 @@ class RootedConnectecKHopDominatingSet(ConnectedKHopDominatingSet):
# V3
# to_add = set()
if
v
in
i_neighborhood
:
number_of_found_separators
+=
1
# V2
# number_of_found_separators += 1
min_ij_sep
=
ConnectedKHopDominatingSet
.
min_ij_separator
(
self
.
G
,
v
,
self
.
root
,
set
(
i_neighborhood
))
# V1
# V1
, V3
to_add
.
add
(
frozenset
(
min_ij_sep
))
# V2
# self.m.addConstr(gp.quicksum(self.nodes[s] for s in min_ij_sep) >= self.nodes[v])
# V3
# number_of_found_separators += len(i_neighborhood)
# V3
# self.m.addConstrs(gp.quicksum(self.nodes[s] for s in min_ij_sep_to_add) >= self.nodes[w] for w in i_neighborhood for min_ij_sep_to_add in to_add)
# V1
self
.
m
.
addConstrs
(
gp
.
quicksum
(
self
.
nodes
[
s
]
for
s
in
min_ij_sep
)
>=
self
.
nodes
[
v
]
for
min_ij_sep
in
to_add
)
def
add_all_combinations_root_separators
(
self
):
number_of_found_separators
=
0
cummulated_to_add
=
0
for
v
in
self
.
G
.
nodes
:
# V1
to_add
=
set
()
for
i
in
range
(
2
,
len
(
self
.
G
.
nodes
)):
V
=
{
w
for
w
in
self
.
G
.
neighbors
(
v
)}
V
.
update
([
v
])
for
i_neighborhood
in
combinations
(
V
,
i
):
if
v
in
i_neighborhood
:
min_ij_sep
=
ConnectedKHopDominatingSet
.
min_ij_separator
(
self
.
G
,
v
,
self
.
root
,
set
(
i_neighborhood
))
if
min_ij_sep
:
number_of_found_separators
+=
1
# V1
min_ij_sep_frozenset
=
frozenset
(
min_ij_sep
)
to_add
.
add
(
min_ij_sep_frozenset
)
number_of_found_separators
+=
len
(
to_add
)
# V2
# self.m.addConstr(gp.quicksum(self.nodes[s] for s in min_ij_sep) >= self.nodes[v])
# V1
cummulated_to_add
+=
len
(
to_add
)
# V1
self
.
m
.
addConstrs
(
gp
.
quicksum
(
self
.
nodes
[
s
]
for
s
in
min_ij_sep
)
>=
self
.
nodes
[
v
]
for
min_ij_sep
in
to_add
)
# print(cummulated_to_add, number_of_found_separators)
print
(
f
"
number of preadded separators:
{
number_of_found_separators
}
"
)
def
add_simple_path_length_constraint
(
self
):
...
...
@@ -273,9 +256,6 @@ class RootedConnectecKHopDominatingSet(ConnectedKHopDominatingSet):
def
intermediate_node_constraint
(
self
,
exclude
):
self
.
m
.
addConstrs
(
2
*
self
.
nodes
[
v
]
<=
gp
.
quicksum
(
self
.
nodes
[
w
]
for
w
in
G
.
neighbors
(
v
))
for
v
in
G
.
nodes
if
v
not
in
exclude
)
def
getVars
(
self
):
return
self
.
m
.
getVars
()
if
__name__
==
'
__main__
'
:
G
=
lp_to_nx_graph
.
read
(
sys
.
argv
[
1
])
...
...
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