-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphUtils.cpp
43 lines (34 loc) · 1.35 KB
/
GraphUtils.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
#include "GraphUtils.h"
#include <math.h>
using namespace ADS;
double GraphUtils::getDensity (unsigned int uiNVertices, unsigned int uiNEdges,
bool bDirectedGraph)
{
return (static_cast<double>(uiNEdges) /
static_cast<double>(getMaxNumberOfEdges (uiNVertices, bDirectedGraph)));
}
unsigned int GraphUtils::getMaxNumberOfEdges (unsigned int uiNVertices,
bool bDirectedGraph)
{
unsigned int uiEdges = uiNVertices * (uiNVertices - 1);
if (!bDirectedGraph)
uiEdges = uiEdges / 2;
return uiEdges;
}
unsigned int GraphUtils::getNumberOfEdges (unsigned int uiNVertices,
unsigned int uiDensity,
bool bDirectedGraph)
{
if ((uiDensity == 0) || (uiDensity > 100))
return 0;
return getNumberOfEdges (uiNVertices, static_cast<double>(uiDensity) / 100.0f,
bDirectedGraph);
}
unsigned int GraphUtils::getNumberOfEdges (unsigned int uiNVertices,
double dDensity,
bool bDirectedGraph)
{
if ((dDensity <= 0.0f) || (dDensity > 1.0f))
return 0;
return static_cast<unsigned int>(ceil (dDensity * getMaxNumberOfEdges (uiNVertices, bDirectedGraph)));
}