-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsuficiente.cpp
More file actions
60 lines (53 loc) · 1.57 KB
/
Insuficiente.cpp
File metadata and controls
60 lines (53 loc) · 1.57 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
//compile using g++ -std=c++11 <programFileName>.cpp -o <executableName>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
#include <fstream>
#define MIN_PER_RANK 1 /* Nodes/Rank: How 'fat' the DAG should be. */
#define MAX_PER_RANK 1
#define MIN_RANKS 1000 /* MUDAR AQUI O NUMERO DE VERTICES. */
#define MAX_RANKS 1000
#define PERCENT 40 /* Chance of having an Edge. */
using namespace std;
int main (void)
{
ofstream temp, final;
temp.open(".temp");
final.open("output");
string line;
int i, j, k,nodes = 0;
int arestas = 0;
srand (time (NULL));
int ranks = MIN_RANKS
+ (rand () % (MAX_RANKS - MIN_RANKS + 1));
for (i = 0; i < ranks; i++)
{
/* New nodes of 'higher' rank than all nodes generated till now. */
int new_nodes = MIN_PER_RANK
+ (rand () % (MAX_PER_RANK - MIN_PER_RANK + 1));
/* Edges from old nodes ('nodes') to new ones ('new_nodes'). */
for (j = 0; j < nodes; j++){
for (k = 0; k < new_nodes; k++) {
if ( (rand () % 100) < PERCENT) {
temp<< to_string(j+1) << " " <<to_string(k + nodes+1) << "\n"; /* An Edge. */
arestas++;
}
}
}
nodes += new_nodes; /* Accumulate into old node set. */
}
temp.close();
ifstream temp2;
temp2.open(".temp");
final<<to_string(MAX_RANKS) << " "<<to_string(arestas) <<"\n";
while ( getline (temp2,line) )
{
final << line << '\n';
}
temp2.close();
final.close();
remove(".temp");
return 0;
}