Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
re6stnet
Commits
bde5fdec
Commit
bde5fdec
authored
Jul 13, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addition of a function to check the connectivity from a single node,
much faster than calculating distance distance
parent
f6113c52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
11 deletions
+63
-11
simulation/graph.cpp
simulation/graph.cpp
+31
-1
simulation/main.cpp
simulation/main.cpp
+17
-9
simulation/main.h
simulation/main.h
+6
-1
simulation/results.cpp
simulation/results.cpp
+9
-0
No files found.
simulation/graph.cpp
View file @
bde5fdec
#include "main.h"
#include <cmath>
#include <map>
#include <queue>
Graph
::
Graph
(
int
size
,
int
k
,
int
maxPeers
,
mt19937
&
rng
)
:
distrib
(
uniform_int_distribution
<
int
>
(
0
,
size
-
1
)),
...
...
@@ -49,6 +50,35 @@ void Graph::GetDistancesFrom(int node, int* distance)
}
}
int
Graph
::
CountUnreachableFrom
(
int
node
)
{
bool
accessibility
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++
)
accessibility
[
i
]
=
false
;
accessibility
[
node
]
=
true
;
int
unAccessible
=
size
;
queue
<
int
>
toVisit
;
toVisit
.
push
(
node
);
while
(
!
toVisit
.
empty
())
{
int
n
=
toVisit
.
front
();
for
(
int
i
:
adjacency
[
n
])
{
if
(
!
accessibility
[
i
])
{
toVisit
.
push
(
i
);
accessibility
[
i
]
=
true
;
}
}
unAccessible
--
;
toVisit
.
pop
();
}
return
unAccessible
;
}
// kill the last proportion*size machines of the graph
void
Graph
::
KillMachines
(
float
proportion
)
{
...
...
@@ -68,7 +98,7 @@ void Graph::KillMachines(float proportion)
int
Graph
::
GetMinCut
()
{
int
nIter
=
log
(
size
)
*
log
(
size
)
;
int
nIter
=
log
(
size
);
int
minCut
=
-
1
;
for
(
int
i
=
0
;
i
<
nIter
;
i
++
)
{
...
...
simulation/main.cpp
View file @
bde5fdec
...
...
@@ -2,6 +2,7 @@
#include "main.h"
#include <future>
#include <sstream>
#include <unistd.h>
const
char
*
outName
=
"out.csv"
;
...
...
@@ -14,10 +15,11 @@ Results Simulate(int seed, int n, int k, int maxPeer, int maxDistanceFrom, floa
{
Graph
graph
(
n
,
k
,
maxPeer
,
rng
);
graph
.
KillMachines
(
alivePercent
);
int
minCut
=
graph
.
GetMinCut
();
if
(
results
.
minKConnexity
==
-
1
||
results
.
minKConnexity
>
minCut
)
results
.
minKConnexity
=
minCut
;
results
.
UpdateArity
(
graph
);
results
.
AddAccessibilitySample
(((
double
)
graph
.
CountUnreachableFrom
(
0
))
/
((
double
)
n
));
//int minCut = graph.GetMinCut();
//if(results.minKConnexity == -1 || results.minKConnexity > minCut)
//results.minKConnexity = minCut;
//results.UpdateArity(graph);
// Compute the shortest path
/*for(int i=0; i<min(graph.size, maxDistanceFrom); i++)
...
...
@@ -38,21 +40,27 @@ int main(int argc, char** argv)
FILE
*
output
=
fopen
(
outName
,
"wt"
);
int
fno
=
fileno
(
output
);
fprintf
(
output
,
"n,k,a,maxPeer,avgDistance,disconnected,disconnectionProba,maxDistance,maxArityDistrib,minCut
\n
"
);
fprintf
(
output
,
"n,k,a,maxPeer,avgDistance,disconnected,disconnectionProba,"
"maxDistance,maxArityDistrib,minCut,accessibility
\n
"
);
vector
<
future
<
string
>>
outputStrings
;
for
(
int
n
=
2000
;
n
<=
2000
;
n
*=
2
)
for
(
int
k
=
10
;
k
<=
10
;
k
+=
5
)
for
(
float
a
=
1
;
a
<=
1
;
a
+=
0.05
)
for
(
float
a
=
0.0
1
;
a
<=
1
;
a
+=
0.05
)
{
int
seed
=
rng
();
outputStrings
.
push_back
(
async
(
launch
::
async
,
[
seed
,
n
,
k
,
a
]()
{
Results
results
=
Simulate
(
seed
,
n
,
k
,
3
*
k
,
10000
,
a
,
1
);
ostringstream
out
;
out
<<
n
<<
","
<<
k
<<
","
<<
a
<<
","
<<
3
*
k
<<
","
<<
results
.
avgDistance
<<
","
<<
results
.
disconnected
<<
","
<<
results
.
disconnectionProba
<<
","
<<
results
.
maxDistanceReached
<<
","
<<
results
.
arityDistrib
[
3
*
k
]
<<
","
<<
results
.
minKConnexity
out
<<
n
<<
","
<<
k
<<
","
<<
a
<<
","
<<
3
*
k
<<
","
<<
results
.
avgDistance
<<
","
<<
results
.
disconnected
<<
","
<<
results
.
disconnectionProba
<<
","
<<
results
.
maxDistanceReached
<<
","
<<
results
.
arityDistrib
[
3
*
k
]
<<
","
<<
results
.
minKConnexity
<<
","
<<
results
.
avgAccessibility
<<
endl
;
return
out
.
str
();
}));
...
...
simulation/main.h
View file @
bde5fdec
...
...
@@ -38,8 +38,10 @@ public:
~
Graph
()
{
delete
[]
adjacency
;
};
void
GetDistancesFrom
(
int
node
,
int
*
distance
);
void
KillMachines
(
float
proportion
);
int
GetMinCut
();
int
CountUnreachableFrom
(
int
node
);
void
KillMachines
(
float
proportion
);
//void SplitAS(float proportionAS1, float proportionAS2);
vector
<
int
>*
adjacency
;
...
...
@@ -58,12 +60,14 @@ public:
~
Results
();
void
UpdateArity
(
const
Graph
&
graph
);
void
AddAccessibilitySample
(
double
accessibility
);
void
UpdateDistance
(
int
*
distance
,
int
nSamples
);
void
Finalise
();
double
*
arityDistrib
;
double
*
distanceDistrib
;
double
avgDistance
;
double
avgAccessibility
;
int
maxDistanceReached
;
int
minKConnexity
;
...
...
@@ -81,4 +85,5 @@ private:
int64_t
nAritySample
;
int64_t
nDistanceSample
;
int64_t
nAccessibilitySample
;
};
simulation/results.cpp
View file @
bde5fdec
...
...
@@ -11,8 +11,10 @@ Results::Results(int maxArity, int maxDistance) :
for
(
int
i
=
0
;
i
<=
maxDistance
;
i
++
)
distanceDistrib
[
i
]
=
0
;
nAccessibilitySample
=
0
;
nAritySample
=
0
;
nDistanceSample
=
0
;
avgAccessibility
=
0
;
arityTooBig
=
0
;
distanceTooBig
=
0
;
disconnected
=
0
;
...
...
@@ -64,6 +66,12 @@ void Results::AddDistanceSample(int distance)
maxDistanceReached
=
max
(
maxDistanceReached
,
distance
);
}
void
Results
::
AddAccessibilitySample
(
double
accessibility
)
{
avgAccessibility
+=
accessibility
;
nAccessibilitySample
++
;
}
void
Results
::
Finalise
()
{
for
(
int
i
=
0
;
i
<=
maxArity
;
i
++
)
...
...
@@ -74,4 +82,5 @@ void Results::Finalise()
distanceTooBig
/=
nDistanceSample
;
arityTooBig
/=
nAritySample
;
avgDistance
/=
nDistanceSample
-
disconnected
;
avgAccessibility
/=
nAccessibilitySample
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment