-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypercube.cpp
72 lines (57 loc) · 1.67 KB
/
hypercube.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
// hypercube.cpp
/*
Implementação da classe Hypercube
*/
#include <vector>
using std::vector;
#include <iostream>
using std::cout;
using std::endl;
typedef vector<vector<vector<vector<int> > > > Vector4D;
class Hypercube {
public:
// Parâmetro do construtor = nº de elementos de cada dimensão
Hypercube(int);
// override operador [] para a classe Hypercube
vector<vector<vector<int> > >& operator[](int i){
return int4vector[i];
}
// vector 4D
Vector4D int4vector;
// migrar métodos para o escalonador ???
bool isNeighbor(int, int); // verifica se 2 nodos são vizinhos (possuem conexão)
vector<int> bestRoute(int, int); // dados 2 nodos, retorna uma sequência de nodos indicando a melhor rota
};
// implementa Hypercube como um vector 4D, com 2 elementos cada.
Hypercube::Hypercube(int num) : int4vector(num){
for(int i = 0; i < num; i++){
int4vector[i].resize(num);
for(int j = 0; j < num; j++){
int4vector[i][j].resize(num);
for(int k = 0; k < num; k++){
int4vector[i][j][k].resize(num);
for(int l = 0; l < num; l++){
int4vector[i][j][k][l] = 8*i + 4*j + 2*k + l;
// armazenar pid do processo gerente?
// gerar processos gerentes no construtor do hypercubo?
}
}
}
}
}
#define NUM_ELEM 2 // bits possíveis 0 ou 1
// exemplo de uso da classe Hypercube
int main(){
cout << "Criando hypercube 4D com 0's e 1's" << endl;
Hypercube h(NUM_ELEM);
for(int i = 0; i < NUM_ELEM; i++){
for(int j = 0; j < NUM_ELEM; j++){
for(int k = 0; k < NUM_ELEM; k++){
for(int l = 0; l < NUM_ELEM; l++){
cout << "nodo " << i << j << k << l << "=" << h[i][j][k][l] << endl;
}
}
}
}
return 0;
}