-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAdMatrix.h
More file actions
98 lines (83 loc) · 1.92 KB
/
getAdMatrix.h
File metadata and controls
98 lines (83 loc) · 1.92 KB
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
95
96
97
98
#ifndef GETADMATRIX_H
#define GETADMATRIX_H
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define GRAPHS pair<vector<vector<bool>>, vector<vector<bool>>>
struct Edge
{
int parent;
int child;
};
GRAPHS readFile(string filename)
{
ifstream inFile;
inFile.open(filename);
if (!inFile)
{
cerr << "Unable to open file datafile.txt" << endl;
exit(1); // call system to stop
}
int x;
Edge num; //the key
vector<Edge> edgs;
bool nextGraph = false;
int tvers1 = 0;
int tvers2 = 0;
while (inFile >> x)
{
if(!nextGraph)
{
if(tvers1<x) tvers1 = x;
}
else
{
if(tvers2<x) tvers2 = x;
}
num.parent = x;
inFile>>x;
num.child = x;
if (num.parent == 0 && num.child == 0)
nextGraph = true;
if(!nextGraph)
{
if(tvers1<x) tvers1 = x;
}
else
{
if(tvers2<x) tvers2 = x;
}
edgs.push_back(num);
}
inFile.close();
vector<vector<bool>> Gemail(tvers2, vector<bool>(tvers2,false)); //if there is an edge from 1->2 then Gemail[12]=1
vector<vector<bool>> Gphone(tvers1, vector<bool>(tvers1,false));
int i=0;
for (i = 0; i < edgs.size() && edgs[i].parent!=0; i++)
{
Gphone[edgs[i].parent-1][edgs[i].child-1] = true;
}
i++;
for (;i < edgs.size() && edgs[i].parent!=0; i++)
{
Gemail[edgs[i].parent-1][edgs[i].child-1] = true;
}
return make_pair(Gphone, Gemail);
}
void printMatrix(vector<vector<bool>> graph)
{
for (int i = 0; i < graph.size(); i++)
{
for (int j = 0; j < graph[0].size(); j++)
{
if(graph[i][j])
{
cout << i+1 << " " << j+1 << endl;
}
}
}
}
#endif