-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplexGraphUtils.cpp
More file actions
93 lines (73 loc) · 2.4 KB
/
MultiplexGraphUtils.cpp
File metadata and controls
93 lines (73 loc) · 2.4 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
/*
8888ba.88ba 888888ba a88888b. dP
88 `8b `8b 88 `8b d8' `88 88
88 88 88 a88aaaa8P' 88 .d8888b. dP dP 88d888b. d8888P
88 88 88 88 88 88' `88 88 88 88' `88 88
88 88 88 88 Y8. .88 88. .88 88. .88 88 88 88
dP dP dP dP Y88888P' `88888P' `88888P' dP dP dP
MPCount
Pedro M P Ribeiro - pribeiro@fc.up.pt
Andre Couto Meira - andre.meira@fc.up.pt
*/
/*
* Utilities for reading multiplex graphs.
*
* Last Update: 02/2026
*
*/
#include "MultiplexGraphUtils.h"
#include "Common.h"
#include "Error.h"
#include <stdio.h>
#include <vector>
/***************************************************/
char *MultiplexGraphUtils::layers[MAX_LAYERS];
/***************************************************/
void MultiplexGraphUtils::readFileTxt(MultiplexGraph *g, const char *s,
bool dir) {
FILE *f = fopen(s, "r");
if (!f)
Error::msg(NULL);
int i, a, b, l, size, maxN, maxL;
vector<int> va, vb, vl;
int flagN, flagL;
size = maxN = maxL = flagN = flagL = 0;
while (fscanf(f, "%d %d %d", &l, &a, &b) == 3) {
if ((flagN == 0) && ((a == 0) || (b == 0)))
flagN = 1;
if ((flagL == 0) && (l == 0))
flagL = 1;
va.push_back(a);
vb.push_back(b);
vl.push_back(l);
if (a > maxN)
maxN = a;
if (b > maxN)
maxN = b;
if (l > maxL)
maxL = l;
size++;
}
fclose(f);
if (flagL || flagN)
Error::msg("Index 0 (zero) not allowed");
if (dir)
g->createGraph(maxN, maxL, DIRECTED);
else
g->createGraph(maxN, maxL, UNDIRECTED);
for (i = 0; i < size; i++) {
if (va[i] == vb[i]) {
fprintf(stderr, "Self-Loop on %d ignored\n", va[i]);
continue; // discard self loops!
}
if (!g->isConnected(va[i] - 1, vb[i] - 1, vl[i] - 1))
g->addEdge(va[i] - 1, vb[i] - 1, vl[i] - 1);
else
fprintf(stderr, "Repeated connection! (%d -- %d)(%d)\n", va[i], vb[i], vl[i]);
if (!dir)
g->addEdge(vb[i] - 1, va[i] - 1, vl[i] - 1);
}
va.clear();
vb.clear();
vl.clear();
}