virtual void SetUp() { stinger_config = (struct stinger_config_t *)xcalloc(1,sizeof(struct stinger_config_t)); stinger_config->nv = 1<<13; stinger_config->nebs = 1<<16; stinger_config->netypes = 2; stinger_config->nvtypes = 2; stinger_config->memory_size = 1<<30; S = stinger_new_full(stinger_config); xfree(stinger_config); // A->B // A<->C // B->C // D->C stinger_insert_edge(S,0,0,1,1,1); stinger_insert_edge_pair(S,0,0,2,1,1); stinger_insert_edge(S,0,1,2,1,1); stinger_insert_edge(S,0,3,2,1,1); }
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); }
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(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 load_csv_graph (struct stinger * S, char * filename, int use_numerics) { FILE * fp = fopen (filename, "r"); if (!fp) { char errmsg[257]; snprintf (errmsg, 256, "Opening \"%s\" failed", filename); errmsg[256] = '\0'; perror (errmsg); exit (-1); } char * buf = NULL; char ** fields = NULL; uint64_t bufSize = 0; uint64_t * lengths = NULL; uint64_t fieldsSize = 0; uint64_t count = 0; int64_t line = 0; while (!feof(fp)) { int64_t src = 0; int64_t dst = 0; int64_t wgt = 0; int64_t time = 0; int64_t type = 0; line++; readCSVLineDynamic(',', fp, &buf, &bufSize, &fields, &lengths, &fieldsSize, &count); if (count <= 1) continue; if (count < 3) { E_A("ERROR: too few elemnts on line %ld", (long) line); continue; } if (!use_numerics) { /* values are strings */ stinger_mapping_create (S, fields[FIELD_SOURCE], lengths[FIELD_SOURCE], &src); stinger_mapping_create (S, fields[FIELD_DEST], lengths[FIELD_DEST], &dst); if (count > 2) wgt = atol(fields[FIELD_WEIGHT]); if (count > 3) time = atol(fields[FIELD_TIME]); if (count > 4) { type = stinger_etype_names_lookup_type (S, fields[FIELD_TYPE]); if (type == -1) { stinger_etype_names_create_type (S, fields[FIELD_TYPE], &type); } if (type == -1) { perror ("Failed to create new edge type"); exit(-1); } } } else { /* values are integers */ src = atol(fields[FIELD_SOURCE]); dst = atol(fields[FIELD_DEST]); if (count > 2) wgt = atol(fields[FIELD_WEIGHT]); if (count > 3) time = atol(fields[FIELD_TIME]); if (count > 4) type = atol(fields[FIELD_TYPE]); } //printf("Inserting type=%ld %ld %ld %ld %ld\n", type, src, dst, wgt, time); stinger_insert_edge (S, type, src, dst, wgt, time); } fclose (fp); return 0; }
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); } } }
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); } } }