forked from yakosti/rapidnet-comp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreeGenerator.cc
74 lines (66 loc) · 1.67 KB
/
treeGenerator.cc
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
#include<iostream>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<sstream>
using namespace std;
void generateTree(int *nextNodeID, string currentPath, list<string> *pathList, int level,\
int minFanout, int maxFanout)
{
if(level > 0)
{
int fanout = rand()%(maxFanout-minFanout)+minFanout;
cout<<"FANOUT "<<fanout<<endl;
int i=0;
int rootID = *nextNodeID;
for(i=0;i<fanout;i++)
{
(*nextNodeID)++;
if(level-1 > 0)
{
cout<<"Adding at "<<rootID<<" "<<"."<<*nextNodeID<<currentPath<<endl;
stringstream newPath;
newPath<<"."<<*nextNodeID<<currentPath;
generateTree(nextNodeID,newPath.str(),pathList,level-1,minFanout,maxFanout);
}
else
{
cout<<"Adding at "<<rootID<<" "<<*nextNodeID<<currentPath<<endl;
stringstream newPath;
newPath<<*nextNodeID<<currentPath;
generateTree(nextNodeID,newPath.str(),pathList,level-1,minFanout,maxFanout);
}
}
}
else
{
(*pathList).push_back(currentPath);
}
}
int main(int argc, char* argv[])
{
srand(time(NULL));
if(argc == 5)
{
int nextNodeID = 2;
string path = ".";
list<string> pathList;
int minDepth = atoi(argv[1]);
int maxDepth = atoi(argv[2]);
int level = rand()%(maxDepth-minDepth)+minDepth;
cout<<"HEIGHT "<<level<<endl;
int minFanout = atoi(argv[3]);
int maxFanout = atoi(argv[4]);
generateTree(&nextNodeID,path,&pathList,level,minFanout,maxFanout);
cout<<"TOTAL NUMBER OF NODES : "<<nextNodeID<<endl;
list<string>::iterator iter = pathList.begin();
for(;iter!=pathList.end();iter++)
cout<<"URL "<<*iter<<endl;
}
else
{
cout<<"USAGE : treeGenerator minDepth maxDepth minFanout maxFanout"<<endl;
}
return 0;
}