Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Added random edges to geographical random networks
Browse files Browse the repository at this point in the history
  • Loading branch information
tolikzinovyev committed Apr 19, 2016
1 parent 49ce1cc commit 2ad4056
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
3 changes: 1 addition & 2 deletions bmlrp_simple.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ HEADERS += \
bmlrp.h \
misc.h \
graph.h \
stable.h \
debug.h \
test.h

OTHER_FILES += \
export.cpp \
export.h

PRECOMPILED_HEADER += stable.h
PRECOMPILED_HEADER = stable.h
6 changes: 4 additions & 2 deletions export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ void SetSeed_R(uint seed) {
}

// [[Rcpp::export]]
Network_R Random_R(int n, float r_coeff, int level, string filter, int label) {
return Network_R( GetNetworkLevel(Random(n, r_coeff), level), filter, label);
Network_R Random_R(int n, float r_coeff, float random_edges_ratio_nodes,
int level, string filter, int label)
{
return Network_R( GetNetworkLevel(Random(n, r_coeff, random_edges_ratio_nodes), level), filter, label);
}

// [[Rcpp::export]]
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace std;

int main() {
Gen.seed(3097);
Network net = Random(13, 2);
Network net = Random(13, 2, 0);

// Gen.seed(426);
// Network net = Random(6, 2);
Expand Down
6 changes: 4 additions & 2 deletions plots.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ Process <- function(data, draw, use_layout, ...) {
graph
}

Random <- function(n, r_coeff, level = 0, filter = "", label = 0, draw = T, layout = T, ...) {
Random <- function(n, r_coeff, random_edges_ratio_nodes = 0,
level = 0, filter = "", label = 0, draw = T, layout = T, ...)
{
SetSeed_R(Seed)
Process(Random_R(n, r_coeff, level, filter, label), draw, layout, ...)
Process(Random_R(n, r_coeff, random_edges_ratio_nodes, level, filter, label), draw, layout, ...)
}

Overlay <- function(n, m, level = 0, filter = "", label = 0, draw = T, layout = T, ...) {
Expand Down
16 changes: 14 additions & 2 deletions sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ bool Close(Point a, Point b, float r) {
return Sqr(a.x - b.x) + Sqr(a.y - b.y) <= Sqr(r);
}

Network Random(int n, float r_coeff) {
float r = r_coeff / sqrt(n);
Network Random(int n, float r_coeff, float random_edges_ratio_nodes) {
const float r = r_coeff / sqrt(n);
const int random_edges = n * random_edges_ratio_nodes / 2;

uniform_real_distribution<float> distFloat;
uniform_int_distribution<int> distInt;

vector<Addr> addrs(n);
vector<Point> points(n);
Expand All @@ -89,6 +91,16 @@ Network Random(int n, float r_coeff) {

ScalePoints(points);

for (int i = 0; i < random_edges; ++i) {
int a = distInt(Gen) % n;
int b = distInt(Gen) % n;
myassert(a >= 0 && b >= 0);

if (!res.Connected(a, b)) {
res.AddEdge(a, b);
}
}

return Network(res, addrs, points);
}

Expand Down
2 changes: 1 addition & 1 deletion sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Network {

Network GetNetworkLevel(const Network& net_level0, int level);

Network Random(int n, float r_coeff);
Network Random(int n, float r_coeff, float random_edges_ratio_nodes);
Network Overlay(int n, float deg);
Network Manual0();
Network Manual1();
Expand Down

0 comments on commit 2ad4056

Please sign in to comment.