-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputProcessing.cpp
95 lines (88 loc) · 1.73 KB
/
outputProcessing.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
85
86
87
88
89
90
91
92
93
94
/*
* outputProcessing.cpp
*
* Created on: 01-Oct-2018
* Author: gaurav
*/
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
char* intToString(int x){
char* number = NULL;
if(x==0){
number = new char[10];
number[0]='\0';
return number;
}
number = intToString(x/10);
x = x%10;
char* digit= new char[2];
digit[0] = x+'0';
digit[1] = '\0';
strcat(number, digit);
//free Memory
delete[] digit;
digit = NULL;
return number;
}
int main(int argc, char* argv[]){
// getting File names
int len = strlen(argv[1]);
char inFilePath[len+10];
char outFilePath[len+10];
strcpy(inFilePath,argv[1]);
strcat(inFilePath,".satoutput");
strcpy(outFilePath,argv[1]);
strcat(outFilePath,".subgraphs");
ifstream in;
in.open(inFilePath);
ofstream out;
out.open(outFilePath);
string s;
in >> s;
int var;
int n, m, k;
ifstream graph;
graph.open("test.graph");
graph >> n >> m >> k;
bool truth[n][k];
if( s.compare("SAT") == 0){
//Assuming SAT will give value assignment for all the variables.
in >> var;
//cout << "Value of Var = " << var << endl;
for(int i =0; i < n; i++){
for(int j =0 ; j<k; j++){
if(var > 0)
truth[i][j] = true;
else if(var < 0)
truth[i][j] = false;
else break; // should only never happen
in >> var;
//cout << "Value of Var = " << var << endl;
}
}
int count;
string str;
for(int i = 0; i < k; i++){
count = 0;
str = "";
for(int j = 0; j < n; j++){
if(truth[j][i]){
count++;
string s;
str.append(string(intToString(j+1)) + " ");
}
}
if(count > 0){
out << "#" << i+1 << " " << count << endl;
out << str << endl;
}
}
}
else out << 0;
out.close();
graph.close();
in.close();
return 0;
}