Commit 793dbb62 authored by msurl's avatar msurl
Browse files

added missing comments and print for number of preadded constraints

parent ba531f39
......@@ -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)
# 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)
number_of_found_separators += len(to_add)
print(f"number of preadded separators: {number_of_found_separators}")
def add_simple_path_length_constraint(self):
......@@ -271,10 +254,7 @@ class RootedConnectecKHopDominatingSet(ConnectedKHopDominatingSet):
self.m.addConstrs(self.nodes[v] <= gp.quicksum(self.nodes[w] * gp.quicksum(self.nodes[h] for h in self.G.neighbors(w) if h is not v) for w in self.G.neighbors(v)) for v in self.G.nodes if v not in exclude)
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()
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)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment