Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class Clause:
  2.  
  3. """
  4. cost: Integer, clause cost
  5. literals: Integer list, variables of clause
  6. """
  7. def __init__(self, cost, literals):
  8. self.cost = cost
  9. self.literals = literals
  10.  
  11. def add(self, literal):
  12. return Clause(self.cost, self.literals.append(literal))
  13.  
  14. def len(self):
  15. return len(set(map(abs, self.literals)))
  16.  
  17. @staticmethod
  18. def clause_from_dimacs_line(line):
  19. line_split = line.split()
  20. cost = int(line_split[0])
  21. literals = map(int,line_split[1:-1])
  22. return Clause(cost, literals)
  23.  
  24. def pretty_str(self):
  25. return "Cost: " + str(self.cost) + \
  26. " - Literals: [" + ", ".join(self.literals) + "]"
  27.  
  28. # Overrides
  29. def __str__(self):
  30. return str(self.cost) + " " + " ".join(map(str,self.literals)) + " 0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement