Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Initialize formula
- formula = wcnf.WCNFFormula()
- # Create variable
- nodes = [formula.new_var() for _ in range(self.n_nodes)]
- # Create soft clauses
- for n in nodes:
- formula.add_clause([-n], weight=1)
- # Create hard clauses
- for n1, n2 in self.edges:
- v1, v2 = nodes[n1 - 1], nodes[n2 -1]
- formula.add_clause([v1, v2], weight=wcnf.TOP_WEIGHT)
- # Solve formula
- opt, model = solver.solve(formula)
- # Translate model
- return [n for n in model if n > 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement