Commit f0b20fae authored by msurl's avatar msurl
Browse files

corrected algorithm to add vertex separators lazily

parent 8513db27
......@@ -165,6 +165,44 @@ class ConnectedKHopDominatingSet(KHopDominatingSet):
ds = {i for i,x_i in enumerate(self.m.getVars()) if x_i.x > 0.5}
return ds
# Probably uncorrect version
# def elim_unconnectivity(model, where):
# if where == GRB.Callback.MIPSOL:
# vals = model.cbGetSolution(model._vars)
# ds = {i for i in model._vars.keys() if vals[i] > 0.5}
# G_prime_prime = model._G.subgraph(ds)
# if(not nx.is_connected(G_prime_prime)):
# C = [c for c in nx.algorithms.components.connected_components(G_prime_prime)]
# for i in range(len(C)-1):
# C_i = C[i]
# for j in range(i+1, len(C)):
# C_j = C[j]
# h = next(iter(C_i))
# l = next(iter(C_j))
# min_ij_sep = ConnectedKHopDominatingSet.min_ij_separator(model._G, h, l, C_i)
# model.cbLazy(gp.quicksum(model._vars[s] for s in min_ij_sep) >= model._vars[h] + model._vars[l] - 1)
# V1
# def elim_unconnectivity(model, where):
# if where == GRB.Callback.MIPSOL:
# vals = model.cbGetSolution(model._vars)
# ds = {i for i in model._vars.keys() if vals[i] > 0.5}
# G_prime_prime = model._G.subgraph(ds)
# if(not nx.is_connected(G_prime_prime)):
# C = [c for c in nx.algorithms.components.connected_components(G_prime_prime)]
# for i in range(len(C)):
# C_i = C[i]
# for j in range(len(C)):
# C_j = C[j]
# h = next(iter(C_i))
# l = next(iter(C_j))
# min_ij_sep = ConnectedKHopDominatingSet.min_ij_separator(model._G, h, l, C_i)
# if min_ij_sep:
# model.cbLazy(gp.quicksum(model._vars[s] for s in min_ij_sep) >= model._vars[h] + model._vars[l] - 1)
# V2
def elim_unconnectivity(model, where):
if where == GRB.Callback.MIPSOL:
vals = model.cbGetSolution(model._vars)
......@@ -173,15 +211,16 @@ class ConnectedKHopDominatingSet(KHopDominatingSet):
G_prime_prime = model._G.subgraph(ds)
if(not nx.is_connected(G_prime_prime)):
C = [c for c in nx.algorithms.components.connected_components(G_prime_prime)]
for i in range(len(C)-1):
for i in range(len(C)):
C_i = C[i]
for j in range(i+1, len(C)):
for j in range(len(C)):
C_j = C[j]
h = next(iter(C_i))
l = next(iter(C_j))
min_ij_sep = ConnectedKHopDominatingSet.min_ij_separator(model._G, h, l, C_i)
model.cbLazy(gp.quicksum(model._vars[s] for s in min_ij_sep) >= model._vars[h] + model._vars[l] - 1)
if min_ij_sep:
for w in C_i:
model.cbLazy(gp.quicksum(model._vars[s] for s in min_ij_sep) >= model._vars[w] + model._vars[l] - 1)
class RootedConnectecKHopDominatingSet(ConnectedKHopDominatingSet):
......@@ -192,10 +231,10 @@ 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()
print("single node separators:")
self.add_single_root_separators()
# print("neighborhood separators:")
# self.add_all_neighborhood_root_separators()
# print("single node separators:")
# self.add_single_root_separators()
def add_single_root_separators(self):
number_of_found_separators = 0
......
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