-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsat.cpp
executable file
·84 lines (60 loc) · 1.78 KB
/
sat.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
/***************************************************************************
* Copyright (C) 2015 Tian-Li Yu and Shih-Huan Hsu *
* tianliyu@ntu.edu.tw *
***************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "sat.h"
using namespace std;
double evaluateSAT(int *x, SATinstance *inst) {
double f=0;
bool b=false;
for(vector<int>::iterator it = inst->fvector.begin(); it != inst->fvector.end(); it++) {
if ( b && *it!=0 ) continue;
if (*it != 0) {
if (*it>0) {
if (x[(*it)-1] == 1)
b = true;
} else {
if (x[-1*(*it+1)]==0)
b = true;
}
} else {
if (!b)
f -= 1;
b = false;
}
}
return f;
}
void loadSAT(char *cnf_file_name, SATinstance *inst) {
int temp;
ifstream input;
string line;
input.open ( cnf_file_name );
if(!input) {
cout << "Fail to open file: " << cnf_file_name << endl;
exit(0);
}
getline ( input, line );
while (line[0] != 'p' || line[0] == 'P') {
getline ( input, line );
}
istringstream in( line );
in >> inst->type;
in >> inst->type;
in >> inst->var;
in >> inst->clau;
while(getline ( input, line )) {
if (line[0] == '%') break;
istringstream in( line );
while ( in >> temp ) inst->fvector.push_back(temp);
}
input.close();
}