-
Notifications
You must be signed in to change notification settings - Fork 1
/
Clause.cpp
84 lines (76 loc) · 1.92 KB
/
Clause.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/////////////////
// OS Includes
//////////////
// Includes
#include "Clause.h"
#include "Debug.h"
/////////////
// Defines
///////////////////////////
// Static Initialization
//////////////////////////////////////////////////////////////////////////////////////////////////
// Public Methods
void Clause::vOutput(ostream& xOutputStream_) const
{
for (int i=0; i<_iVariableCount; i++) {
if (iIsNegated(i))
xOutputStream_ << '-';
xOutputStream_ << eConstrainedVariable(i)+1;
xOutputStream_ << ' ';
}
}
int Clause::iCompare(const Clause& xWithMe_) const
{
// Compare, first by length, then by lexical variable order.
// Assumes variables in the literal list are lexically sorted.
// Ignores negated/non-negated status of the literal.
if (iVariableCount() > xWithMe_.iVariableCount()) {
return 1;
}
else if (iVariableCount() < xWithMe_.iVariableCount()) {
return -1;
}
else {
for (int i=0; i<iVariableCount(); i++) {
if (eConstrainedVariable(i) >
xWithMe_.eConstrainedVariable(i)) {
return 1;
}
else if (eConstrainedVariable(i) <
xWithMe_.eConstrainedVariable(i)) {
return -1;
}
}
return 0;
}
}
boolean Clause::bIsEqual(const Clause& xWithMe_) const
{
// Assumes variable lists are sorted.
if (iVariableCount() != xWithMe_.iVariableCount()) {
return 0;
}
else {
for (int i=0; i<iVariableCount(); i++) {
if (eConstrainedLiteral(i) !=
xWithMe_.eConstrainedLiteral(i)) {
return 0;
}
}
return 1;
}
}
void Clause::vSortVariableList()
{
// Simple bubble sort to sort the (non-perma) variables in lexical order.
//return; // temp
for (int i=0; i<_iPermaCount-1; i++) {
for (int j=i+1; j<_iPermaCount; j++) {
if (eConstrainedVariable(i) > eConstrainedVariable(j)) {
LiteralID temp = _aConstrainedLiteral[i];
_aConstrainedLiteral[i] = _aConstrainedLiteral[j];
_aConstrainedLiteral[j] = temp;
}
}
}
}