-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRead_PCN.cpp
71 lines (57 loc) · 1.79 KB
/
Read_PCN.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
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
using std::fstream;
using std::ifstream;
#define Positive 1
#define Negative 2
#define DC 3
#define Zero 0
#define Vec_2D vector<vector<int>>
int cubeSize, cubeNo, count=0;
// Vec_2D Read_PCN(string filename);
Vec_2D Read_PCN(string filename){
//initialize the array size
vector<int> input_integers;//Holds the integers from the input file
int temp;//Used to create the 2D-Variables
Vec_2D Polarities;//Array to work on
int no_active = -1;//Number of active variables, negative to correct index error
int var_counted = 0;//To count the number of values read from the input_integers array WITHIN THAT LINE
int no_val_read = 1;//To count the number of values read from the input_integers array
ifstream input_file(filename);
int cnt= 0;
int x;
if(input_file.is_open()){
while ( input_file >> x){
input_integers.push_back(x);// and read integer from file, DEBUG: Use a 2D Vector
cnt++;
}
//close the file
input_file.close();
}
else{
cout<<"\n Error in opening I/P File";
}
cubeSize = input_integers[0];
cubeNo = input_integers[1];
for(int i = 0; i < cubeNo; i++){
vector<int> Variables;
no_active = input_integers[ ++no_val_read];
var_counted = 0;
for(int j = 0; j < cubeSize; j++){
if((j == abs(input_integers[no_val_read + 1] ) - 1) && (var_counted != no_active)){
temp = input_integers[++no_val_read] > 0 ? Positive : Negative;
Variables.push_back(temp);
var_counted++;
}
else{
temp = DC;
Variables.push_back(temp);
}
}
Polarities.push_back(Variables);
}
return Polarities;
}