-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIncidenceMatrix.cpp
56 lines (47 loc) · 1.32 KB
/
IncidenceMatrix.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
#include "IncidenceMatrix.h"
IncidenceMatrix::IncidenceMatrix()
{
}
IncidenceMatrix::IncidenceMatrix(const char* fileName):
GraphRepresentation(fileName)
{
if (!fin.fail()) {
//  ïåðâîé ñòðîêå ôàéëà äàíû äâà ÷èñëà:
// n - êîëè÷åñòâî âåðøèí ãðàôà,
// m - êîëè÷åñòâî ð¸áåð ãðàôà.
fin >> verticesCnt >> edgesCnt;
incidenceMatrix = new int*[verticesCnt];
// Äàëåå ñîäåðæèòñÿ ìàòðèöà èíöèäåíöèé ðàçìåðîì (n x m):
for (int n = 0; n < verticesCnt; ++n) {
incidenceMatrix[n] = new int[edgesCnt];
for (int m = 0; m < edgesCnt; ++m) {
fin >> incidenceMatrix[n][m];
}
}
}
}
IncidenceMatrix::~IncidenceMatrix()
{
if (incidenceMatrix) {
for (int n = 0; n < verticesCnt; ++n) {
delete [] incidenceMatrix[n];
}
delete [] incidenceMatrix;
}
}
int IncidenceMatrix::isEdgeBetween(int vertex1, int vertex2)
{
for (int m = 0; m < edgesCnt; ++m) {
// Åñëè vertex1 èíöèäåíòíà ðåáðó m, è ÿâëÿåòñÿ åãî êîíöîì
// È vertex2 èíöèäåíòíà ðåáðó m, è ÿâëÿåòñÿ åãî íà÷àëîì:
if (incidenceMatrix[vertex1][m] < 0 && incidenceMatrix[vertex2][m] > 0)
return -1;
else if (incidenceMatrix[vertex1][m] != 0 && incidenceMatrix[vertex2][m] != 0)
return 1;
}
return 0;
}
int IncidenceMatrix::getEdgeWeightBetween(int vertex1, int vertex2)
{
return 1;
}