TEST_F(ShortestPathsTest, medium_DAG){ stinger_insert_edge(S, 0, 0, 6, 1, 1); stinger_insert_edge(S, 0, 1, 2, 10, 1); stinger_insert_edge(S, 0, 1, 3, 10, 1); stinger_insert_edge(S, 0, 1, 4, 10, 1); stinger_insert_edge(S, 0, 1, 5, 10, 1); stinger_insert_edge(S, 0, 1, 6, 10, 1); stinger_insert_edge(S, 0, 2, 7, 9, 1); stinger_insert_edge(S, 0, 2, 8, 9, 1); stinger_insert_edge(S, 0, 2, 9, 9, 1); stinger_insert_edge(S, 0, 3, 10, 8, 1); stinger_insert_edge(S, 0, 3, 11, 8, 1); stinger_insert_edge(S, 0, 4, 12, 8, 1); stinger_insert_edge(S, 0, 8, 18, 7, 1); stinger_insert_edge(S, 0, 9, 16, 6, 1); stinger_insert_edge(S, 0, 9, 17, 6, 1); stinger_insert_edge(S, 0, 10, 15, 5, 1); stinger_insert_edge(S, 0, 11, 14, 5, 1); stinger_insert_edge(S, 0, 12, 13, 5, 1); int64_t nv = stinger_max_active_vertex(S)+1; std::vector<int64_t> paths; paths = dijkstra(S, nv, 1, false); EXPECT_EQ(7+9+10, paths[18]); paths = dijkstra(S, nv, 1, true); EXPECT_EQ(3, paths[18]); }
int main (int argc, char ** argv) { stinger_t * S = stinger_new(); /* insert your data now */ load_benchmark_data_into_stinger (S, argv[1],0); /* get number of vertices */ uint64_t nv = stinger_max_active_vertex (S); nv++; print_fragmentation_stats (S, nv); /* auxiliary data structure */ double * pagerank_scores = xmalloc (nv * sizeof(int64_t)); double * pagerank_scores_tmp = xmalloc (nv * sizeof(int64_t)); /* the algorithm itself (timed) */ bench_start(); pagerank (S, nv, pagerank_scores, pagerank_scores_tmp, 1e-8, 0.85, 100); bench_end(); printf("Done.\n"); /* cleanup */ free (pagerank_scores); free (pagerank_scores_tmp); stinger_free_all (S); return 0; }
TEST_F(PagerankPrincetonTest, PagerankDirectedType) { for (int i=10; i < 100; i++) { int64_t timestamp = i+1; for (int j=i+1; j < 100; j++) { stinger_insert_edge_pair(S, 1, i, j, 1, timestamp); } } int64_t nv = stinger_max_active_vertex(S)+1; tmp_pr = (double *)xcalloc(nv, sizeof(double)); pr = (double *)xcalloc(nv, sizeof(double)); for(uint64_t v = 0; v < nv; v++) { pr[v] = 1 / ((double)nv); } page_rank_type_directed(S, nv, pr, tmp_pr, EPSILON_DEFAULT, DAMPINGFACTOR_DEFAULT, 100, 0); double expected_pr[4] = { 1.49, 0.78, 1.58, 0.15 }; double tol = 0.01; double ratio = expected_pr[0] / pr[0]; double leftover = 1.0; for (int64_t v=0; v < stinger_max_active_vertex(S) + 1; v++) { if (v < 4) { EXPECT_NEAR(expected_pr[v],pr[v]*ratio,tol); leftover -= pr[v]; } else { EXPECT_NEAR(leftover / 96.0,pr[v],.0000001); } } xfree(tmp_pr); xfree(pr); }
TEST_F(PagerankPrincetonTest, PagerankSubset) { for (int i=10; i < 100; i++) { int64_t timestamp = i+1; for (int j=i+1; j < 100; j++) { stinger_insert_edge_pair(S, 0, i, j, 1, timestamp); } } int64_t nv = stinger_max_active_vertex(S)+1; uint8_t * vtx_subset = (uint8_t *)xcalloc(nv,sizeof(uint8_t)); tmp_pr = (double *)xcalloc(nv, sizeof(double)); pr = (double *)xcalloc(nv, sizeof(double)); for (int64_t i = 0; i < 4; i++) { vtx_subset[i] = 1; } page_rank_subset(S, nv, vtx_subset, 4, pr, tmp_pr, EPSILON_DEFAULT, DAMPINGFACTOR_DEFAULT, 100); xfree(vtx_subset); double expected_pr[4] = { 1.49 / 4.0, 0.78 / 4.0, 1.58 / 4.0, 0.15 / 4.0 }; double tol = 0.001; for (int64_t v=0; v < stinger_max_active_vertex(S) + 1; v++) { if (v < 4) { EXPECT_NEAR(expected_pr[v],pr[v],tol); } else { EXPECT_DOUBLE_EQ(0.0,pr[v]); } } xfree(tmp_pr); xfree(pr); }
TEST_F(HITSTest, DirectedBipartite) { stinger_insert_edge(S, 0, 0, 5, 1, 1); stinger_insert_edge(S, 0, 0, 6, 1, 1); stinger_insert_edge(S, 0, 0, 7, 1, 1); stinger_insert_edge(S, 0, 0, 8, 1, 1); stinger_insert_edge(S, 0, 0, 9, 1, 1); stinger_insert_edge(S, 0, 1, 5, 1, 1); stinger_insert_edge(S, 0, 1, 6, 1, 1); stinger_insert_edge(S, 0, 1, 7, 1, 1); stinger_insert_edge(S, 0, 1, 8, 1, 1); stinger_insert_edge(S, 0, 1, 9, 1, 1); stinger_insert_edge(S, 0, 2, 5, 1, 1); stinger_insert_edge(S, 0, 2, 6, 1, 1); stinger_insert_edge(S, 0, 2, 7, 1, 1); stinger_insert_edge(S, 0, 2, 8, 1, 1); stinger_insert_edge(S, 0, 2, 9, 1, 1); stinger_insert_edge(S, 0, 3, 5, 1, 1); stinger_insert_edge(S, 0, 3, 6, 1, 1); stinger_insert_edge(S, 0, 3, 7, 1, 1); stinger_insert_edge(S, 0, 3, 8, 1, 1); stinger_insert_edge(S, 0, 3, 9, 1, 1); stinger_insert_edge(S, 0, 4, 5, 1, 1); stinger_insert_edge(S, 0, 4, 6, 1, 1); stinger_insert_edge(S, 0, 4, 7, 1, 1); stinger_insert_edge(S, 0, 4, 8, 1, 1); stinger_insert_edge(S, 0, 4, 9, 1, 1); int64_t nv = stinger_max_active_vertex(S)+1; double_t * auth = (double_t *)xcalloc(nv, sizeof(double_t)); double_t * hubs = (double_t *)xcalloc(nv, sizeof(double_t)); hits_centrality(S, nv, hubs, auth, 100); for (int64_t v = 1; v< 5; v++){ if (auth[v-1] != auth[v]){ EXPECT_EQ(0,1); } if (hubs[v-1] != hubs[v]){ EXPECT_EQ(0,1); } } for (int64_t v = 6; v< 10; v++){ if (auth[v-1] != auth[v]){ EXPECT_EQ(0,1); } if (hubs[v-1] != hubs[v]){ EXPECT_EQ(0,1); } } }
int main(int argc, char *argv[]) { double vel_keep = 0.333; double accel_keep = 0.333; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Setup and register algorithm with the server * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_registered_alg * alg = stinger_register_alg( .name="rate_monitor", .data_per_vertex=sizeof(double)*2, .data_description="dd wgtd_edge_vel wgtd_edge_accel", .host="localhost", ); if(!alg) { LOG_E("Registering algorithm failed. Exiting"); return -1; } bzero(alg->alg_data, sizeof(double) * 2 * alg->stinger->max_nv); double * vel = (double *)alg->alg_data; double * accel = vel + alg->stinger->max_nv; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Initial static computation * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_alg_begin_init(alg); { } stinger_alg_end_init(alg); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Streaming Phase * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ while(alg->enabled) { /* Pre processing */ if(stinger_alg_begin_pre(alg)) { /* nothing to do */ stinger_alg_end_pre(alg); } /* Post processing */ if(stinger_alg_begin_post(alg)) { update_rates(alg, stinger_max_active_vertex(alg->stinger)+1, vel, accel, vel_keep, accel_keep); stinger_alg_end_post(alg); } } LOG_I("Algorithm complete... shutting down"); }
TEST_F(PagerankPrincetonTest, DirectedPagerank) { tmp_pr = (double *)xcalloc(stinger_max_active_vertex(S)+1, sizeof(double)); pr = (double *)xcalloc(stinger_max_active_vertex(S)+1, sizeof(double)); page_rank_directed(S, stinger_max_active_vertex(S)+1, pr, tmp_pr, EPSILON_DEFAULT, DAMPINGFACTOR_DEFAULT, 100); double expected_pr[4] = { 1.49 / 4.0, 0.78 / 4.0, 1.58 / 4.0, 0.15 / 4.0 }; double tol = 0.001; for (int64_t v=0; v < stinger_max_active_vertex(S) + 1; v++) { EXPECT_NEAR(expected_pr[v],pr[v],tol); } xfree(tmp_pr); xfree(pr); }
TEST_F(ShortestPathsTest, simple_directed) { stinger_insert_edge(S, 0, 0, 1, 1, 1); stinger_insert_edge(S, 0, 0, 4, 1, 1); stinger_insert_edge(S, 0, 1, 3, 10, 1); stinger_insert_edge(S, 0, 2, 1, 1, 1); stinger_insert_edge(S, 0, 3, 2, 1, 1); stinger_insert_edge(S, 0, 4, 2, 1, 1); stinger_insert_edge(S, 0, 4, 5, 1, 1); stinger_insert_edge(S, 0, 5, 6, 1, 1); stinger_insert_edge(S, 0, 6, 4, 1, 1); int64_t nv = stinger_max_active_vertex(S)+1; int64_t path_length = a_star(S, nv, 5, 2, true); EXPECT_EQ(3,path_length); path_length = a_star(S, nv, 2, 3, true); EXPECT_EQ(2,path_length); path_length = a_star(S, nv, 5, 0, true); EXPECT_EQ(std::numeric_limits<int64_t>::max(),path_length); }
int main (int argc, char ** argv) { stinger_t * S = stinger_new(); /* insert your data now */ load_benchmark_data_into_stinger (S, argv[1],1); int64_t source_vertex = 3; if (argc > 2) { source_vertex = atoll(argv[2]); } /* get number of vertices */ uint64_t nv = stinger_max_active_vertex (S); nv++; print_fragmentation_stats (S, nv); stinger_free_all (S); return 0; }
TEST_F(HITSTest, UndirectedLoop) { stinger_insert_edge(S, 0, 0, 1, 1, 1); stinger_insert_edge(S, 0, 0, 8, 1, 1); stinger_insert_edge(S, 0, 1, 0, 1, 1); stinger_insert_edge(S, 0, 1, 2, 1, 1); stinger_insert_edge(S, 0, 2, 1, 1, 1); stinger_insert_edge(S, 0, 2, 3, 1, 1); stinger_insert_edge(S, 0, 3, 2, 1, 1); stinger_insert_edge(S, 0, 3, 4, 1, 1); stinger_insert_edge(S, 0, 4, 3, 1, 1); stinger_insert_edge(S, 0, 4, 5, 1, 1); stinger_insert_edge(S, 0, 5, 4, 1, 1); stinger_insert_edge(S, 0, 5, 6, 1, 1); stinger_insert_edge(S, 0, 6, 5, 1, 1); stinger_insert_edge(S, 0, 6, 7, 1, 1); stinger_insert_edge(S, 0, 7, 6, 1, 1); stinger_insert_edge(S, 0, 7, 8, 1, 1); stinger_insert_edge(S, 0, 8, 7, 1, 1); stinger_insert_edge(S, 0, 8, 0, 1, 1); int64_t nv = stinger_max_active_vertex(S)+1; double_t * auth = (double_t *)xcalloc(nv, sizeof(double_t)); double_t * hubs = (double_t *)xcalloc(nv, sizeof(double_t)); hits_centrality(S, nv, hubs, auth, 10); for (int64_t v = 1; v< nv; v++){ if (auth[v-1] != auth[v]){ EXPECT_EQ(0,1); } if (hubs[v-1] != hubs[v]){ EXPECT_EQ(0,1); } } }
TEST_F(BetweennessTest, DirectedGraphOverSample) { stinger_insert_edge(S, 0, 0, 1, 1, 1); stinger_insert_edge(S, 0, 1, 2, 1, 1); stinger_insert_edge(S, 0, 1, 3, 1, 1); stinger_insert_edge(S, 0, 1, 4, 1, 1); stinger_insert_edge(S, 0, 2, 8, 1, 1); stinger_insert_edge(S, 0, 3, 5, 1, 1); stinger_insert_edge(S, 0, 3, 6, 1, 1); stinger_insert_edge(S, 0, 4, 5, 1, 1); stinger_insert_edge(S, 0, 5, 6, 1, 1); stinger_insert_edge(S, 0, 5, 7, 1, 1); stinger_insert_edge(S, 0, 7, 8, 1, 1); int64_t nv = stinger_max_active_vertex(S)+1; double * bc = (double *)xcalloc(nv, sizeof(double)); int64_t * times_found = (int64_t *)xcalloc(nv, sizeof(int64_t)); sample_search(S, nv, 100, bc, times_found); double expected_bc[9] = { 0.0, 7.0, 2.0, 4.0, 2.0, 7.0, 0.0, 3.0, 0.0 }; for (int64_t v = 0; v < nv; v++) { EXPECT_DOUBLE_EQ(expected_bc[v],bc[v]) << "v = " << v; } }
TEST_F(BetweennessTest, UndirectedGraph) { stinger_insert_edge_pair(S, 0, 0, 1, 1, 1); stinger_insert_edge_pair(S, 0, 1, 2, 1, 1); stinger_insert_edge_pair(S, 0, 1, 3, 1, 1); stinger_insert_edge_pair(S, 0, 1, 4, 1, 1); stinger_insert_edge_pair(S, 0, 2, 8, 1, 1); stinger_insert_edge_pair(S, 0, 3, 5, 1, 1); stinger_insert_edge_pair(S, 0, 3, 6, 1, 1); stinger_insert_edge_pair(S, 0, 4, 5, 1, 1); stinger_insert_edge_pair(S, 0, 5, 6, 1, 1); stinger_insert_edge_pair(S, 0, 5, 7, 1, 1); stinger_insert_edge_pair(S, 0, 7, 8, 1, 1); int64_t nv = stinger_max_active_vertex(S)+1; double * bc = (double *)xcalloc(nv, sizeof(double)); int64_t * times_found = (int64_t *)xcalloc(nv, sizeof(int64_t)); sample_search(S, nv, 9, bc, times_found); double expected_bc[9] = { 0.0, 24.333333333333, 7.333333333333, 10.0, 4.0, 15.666666666666, 0.0, 6.666666666666, 4.0 }; for (int64_t v = 0; v < nv; v++) { EXPECT_NEAR(expected_bc[v],bc[v],0.00001) << "v = " << v; } }
int main(int argc, char *argv[]) { if (getenv ("COMPUTE")) initial_compute = 1; if (argc > 1) { if (0 == strcmp(argv[1], "--compute")) initial_compute = 1; else if (0 == strcmp(argv[1], "--help") || 0 == strcmp(argv[1], "-h")) { fprintf (stderr, "Pass --compute or set COMPUTE env. var to compute\n" "an initial community map."); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Setup and register algorithm with the server * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_registered_alg * alg = stinger_register_alg( .name="simple_communities", .data_per_vertex=sizeof(int64_t), .data_description="l community_label", .host="localhost", ); if(!alg) { LOG_E("Registering algorithm failed. Exiting"); return -1; } nv = stinger_max_active_vertex(alg->stinger)+1; cmap = (int64_t *)alg->alg_data; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Initial static computation * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_alg_begin_init(alg); { const struct stinger * S = alg->stinger; init_empty_community_state (&cstate, nv, 2*nv); free (cstate.cmap); cstate.cmap = cmap; if (initial_compute) init_cstate_from_stinger (&cstate, S); else init_empty_community_state (&cstate, nv, (1+stinger_total_edges(S))/2); } stinger_alg_end_init(alg); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Streaming Phase * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ while(alg->enabled) { /* Pre processing */ if(stinger_alg_begin_pre(alg)) { /* Must be here to find the removal weights. */ cstate_preproc_alg (&cstate, alg); stinger_alg_end_pre(alg); } /* Post processing */ if(stinger_alg_begin_post(alg)) { cstate_update (&cstate, alg->stinger); stinger_alg_end_post(alg); } } LOG_I("Algorithm complete... shutting down"); finalize_community_state (&cstate); }
int main(int argc, char *argv[]) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Options and arg parsing * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ int64_t max_iter = 5; char * alg_name = "community_detection"; int opt = 0; while(-1 != (opt = getopt(argc, argv, "i:n:x?h"))) { switch(opt) { case 'i': { max_iter = atol(optarg); if(max_iter < 1) { max_iter = 5; } } break; case 'n': { alg_name = optarg; } break; default: printf("Unknown option '%c'\n", opt); case '?': case 'h': { printf( "Louvain Community detection\n" "==================================\n" "\n" "This approach returns the first level of Louvain's Community detection\n" "\n" " -i <num> Set the max number of iterations (%ld by default)\n" " -n <str> Set the algorithm name (%s by default)\n" "\n", max_iter,alg_name ); return(opt); } } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Setup and register algorithm with the server * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_registered_alg * alg = stinger_register_alg( .name=alg_name, .data_per_vertex=sizeof(int64_t), .data_description="l partitions", .host="localhost", ); if(!alg) { LOG_E("Registering algorithm failed. Exiting"); return -1; } int64_t * partitions = (int64_t *)alg->alg_data; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Initial static computation * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ stinger_alg_begin_init(alg); { if (stinger_max_active_vertex(alg->stinger) > 0) community_detection(alg->stinger, stinger_max_active_vertex(alg->stinger) + 1, partitions, max_iter); } stinger_alg_end_init(alg); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Streaming Phase * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ while(alg->enabled) { /* Pre processing */ if(stinger_alg_begin_pre(alg)) { /* nothing to do */ stinger_alg_end_pre(alg); } /* Post processing */ if(stinger_alg_begin_post(alg)) { int64_t nv = (stinger_mapping_nv(alg->stinger))?stinger_mapping_nv(alg->stinger)+1:0; if (nv > 0) { community_detection(alg->stinger, nv, partitions, max_iter); } stinger_alg_end_post(alg); } } LOG_I("Algorithm complete... shutting down"); }