Skip to content

Commit

Permalink
Merge pull request #4 from VaeterchenFrost/patch-1
Browse files Browse the repository at this point in the history
Correct filter in vertexcover.py
  • Loading branch information
hmarkus committed May 14, 2020
2 parents 5d92992 + 634fec0 commit b1ec21e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions dpdb/problems/vertexcover.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ def candidate_extra_cols(self,node):
def assignment_extra_cols(self,node):
return ["min(size) AS size"]

def filter(self,node):
# at least one of connected nodes has to be in the set
def filter(self, node):
"""Local problem filter:
([[u1]] OR [[v1]]) AND ... ([[uN]] OR [[vN]])
"""
# find (undirected!) edges in the subgraph
check = []
for c in node.vertices:
if node.needs_introduce(c):
nv = [v for v in self.edges[c] if v in node.vertices] + [c]
if len(nv) > 1:
check.append(" OR ".join(map(var2col,nv)))
for pos,c in enumerate(node.vertices[:-1]):
# if node.needs_introduce(c): Probably an error in one of the other functions as well.
nv = [(v, c) for v in self.edges[c] if
v in node.vertices[pos+1:]] # don't connect backwards
for edge in nv:
check.append(" OR ".join(map(var2col, edge)))
if check:
return "WHERE ({})".format(") AND (".join(check))
else:
Expand Down

0 comments on commit b1ec21e

Please sign in to comment.