27
ncnf.c
27
ncnf.c
@@ -60,6 +60,8 @@ cnf* readDIMACS(char* path) {
|
||||
|
||||
c->clausedat = calloc(*clausecnt, sizeof(u32) * 3);
|
||||
CHECK(c->clausedat, "Failed to allocate clause data\n")
|
||||
c->index = calloc(*varcnt, sizeof(u32));
|
||||
CHECK(c->index, "Failed to allocate clause index\n")
|
||||
c->variables = calloc(cap, sizeof(u32));
|
||||
CHECK(c->variables, "Failed to allocate literal variables\n")
|
||||
c->parities = calloc(cap, sizeof(u8));
|
||||
@@ -208,4 +210,29 @@ void sortlastnum(cnf* c) {
|
||||
}
|
||||
|
||||
free(d);
|
||||
|
||||
// TODO: Rewrite, the following is copied from Gábor Kusper's implementation
|
||||
u32 lastNum = 0;
|
||||
for (u32 i = c->cnts[1] - 1; i < c->cnts[1]; --i) {
|
||||
if (c->clausedat[3 * i + 2] > lastNum) {
|
||||
while (lastNum < c->clausedat[3 * i + 2]) {
|
||||
c->index[lastNum] = i + 1;
|
||||
lastNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
u32 corrInd = 0;
|
||||
while (c->index[corrInd] == c->cnts[1]) {
|
||||
corrInd++;
|
||||
}
|
||||
|
||||
if (corrInd != 0) {
|
||||
u32 goodVal = c->index[corrInd];
|
||||
do {
|
||||
corrInd--;
|
||||
c->index[corrInd] = goodVal;
|
||||
} while (corrInd != 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user