forked from Guillem96/WPM-1-3-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClause.py
More file actions
27 lines (22 loc) · 750 Bytes
/
Copy pathClause.py
File metadata and controls
27 lines (22 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Clause:
"""
cost: Integer, clause cost
literals: Integer list, variables of clause
"""
def __init__(self, cost, literals):
self.cost = cost
self.literals = literals
def add(self, literal):
self.literals.append(literal)
@staticmethod
def clause_from_dimacs_line(line):
line_split = line.split()
cost = int(line_split[0])
literals = map(int,line_split[1:-1])
return Clause(cost, literals)
def pretty_str(self):
return "Cost: " + str(self.cost) + \
" - Literals: [" + ", ".join(self.literals) + "]"
# Overrides
def __str__(self):
return str(self.cost) + " " + " ".join(map(str,self.literals)) + " 0"