int main() { igraph_t g, g2; igraph_vector_ptr_t sep; igraph_vs_t vs; igraph_small(&g, 7, IGRAPH_UNDIRECTED, 1,0, 2,0, 3,0, 4,0, 5,0, 6,0, -1); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); print_and_destroy(&sep); igraph_destroy(&g); /* ----------------------------------------------------------- */ igraph_small(&g, 5, IGRAPH_UNDIRECTED, 0,3, 1,3, 2,3, 0,4, 1,4, 2,4, -1); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); print_and_destroy(&sep); igraph_destroy(&g); /* ----------------------------------------------------------- */ igraph_small(&g, 5, IGRAPH_UNDIRECTED, 2,0, 3,0, 4,0, 2,1, 3,1, 4,1, -1); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); print_and_destroy(&sep); igraph_destroy(&g); /* ----------------------------------------------------------- */ igraph_small(&g, 10, IGRAPH_UNDIRECTED, 0,2, 0,3, 1,2, 1,3, 5,2, 5,3, 6,2, 6,3, 7,2, 7,3, 8,2, 8,3, 9,2, 9,3, 2,4, 4,3, -1); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); print_and_destroy(&sep); igraph_destroy(&g); /* ----------------------------------------------------------- */ igraph_full(&g, 4, IGRAPH_UNDIRECTED, /*loops=*/ 0); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); print_and_destroy(&sep); igraph_destroy(&g); /* ----------------------------------------------------------- */ igraph_small(&g, 23, IGRAPH_UNDIRECTED, 0,1, 0,2, 0,3, 0,4, 0,5, 1,2, 1,3, 1,4, 1,6, 2,3, 2,5, 2,6, 3,4, 3,5, 3,6, 4,5, 4,6, 4,20, 5,6, 6,7, 6,10, 6,13, 6,18, 7,8, 7,10, 7,13, 8,9, 9,11, 9,12, 10,11, 10,13, 11,15, 12,15, 13,14, 14,15, 16,17, 16,18, 16,19, 17,19, 17,20, 18,19, 18,21, 18,22, 19,20, 20,21, 20,22, 21,22, -1); igraph_vector_ptr_init(&sep, 0); igraph_minimum_size_separators(&g, &sep); printf("Orig:\n"); print_and_destroy(&sep); igraph_vector_ptr_init(&sep, 0); igraph_vs_vector_small(&vs, 0,1,2,3,4,5,6, 16,17,18,19,20,21,22, -1); igraph_induced_subgraph(&g, &g2, vs, IGRAPH_SUBGRAPH_AUTO); igraph_minimum_size_separators(&g2, &sep); printf("1-7,17-23:\n"); print_and_destroy(&sep); igraph_vs_destroy(&vs); igraph_destroy(&g2); igraph_vector_ptr_init(&sep, 0); igraph_vs_vector_small(&vs, 6,7,8,9,10,11,12,13,14,15, -1); igraph_induced_subgraph(&g, &g2, vs, IGRAPH_SUBGRAPH_AUTO); igraph_minimum_size_separators(&g2, &sep); printf("7-16:\n"); print_and_destroy(&sep); igraph_vs_destroy(&vs); igraph_destroy(&g2); igraph_vector_ptr_init(&sep, 0); igraph_vs_vector_small(&vs, 16,17,18,19,20,21,22, -1); igraph_induced_subgraph(&g, &g2, vs, IGRAPH_SUBGRAPH_AUTO); igraph_minimum_size_separators(&g2, &sep); printf("17-23:\n"); print_and_destroy(&sep); igraph_vs_destroy(&vs); igraph_destroy(&g2); igraph_vector_ptr_init(&sep, 0); igraph_vs_vector_small(&vs, 6,7,10,13, -1); igraph_induced_subgraph(&g, &g2, vs, IGRAPH_SUBGRAPH_AUTO); igraph_minimum_size_separators(&g2, &sep); printf("7,8,11,14:\n"); print_and_destroy(&sep); igraph_vs_destroy(&vs); igraph_destroy(&g2); igraph_vector_ptr_init(&sep, 0); igraph_vs_vector_small(&vs, 0,1,2,3,4,5,6, -1); igraph_induced_subgraph(&g, &g2, vs, IGRAPH_SUBGRAPH_AUTO); igraph_minimum_size_separators(&g2, &sep); printf("1-7:\n"); print_and_destroy(&sep); igraph_vs_destroy(&vs); igraph_destroy(&g2); igraph_destroy(&g); return 0; }
int igraph_decompose(const igraph_t *graph, igraph_vector_ptr_t *components, igraph_connectedness_t mode, long int maxcompno, long int minelements) { long int actstart; long int no_of_nodes=igraph_vcount(graph); long int resco=0; /* number of graphs created so far */ char *already_added; igraph_dqueue_t q; igraph_vector_t verts; igraph_vector_t neis; long int i; igraph_t *newg; if (!igraph_is_directed(graph)) { mode=IGRAPH_WEAK; } if (mode != IGRAPH_WEAK) { IGRAPH_ERROR("only 'IGRAPH_WEAK' is implemented", IGRAPH_EINVAL); } if (maxcompno<0) { maxcompno=LONG_MAX; } igraph_vector_ptr_clear(components); IGRAPH_FINALLY(igraph_decompose_destroy, components); already_added=igraph_Calloc(no_of_nodes, char); if (already_added==0) { IGRAPH_ERROR("Cannot decompose graph", IGRAPH_ENOMEM); } IGRAPH_FINALLY(igraph_free, already_added); IGRAPH_CHECK(igraph_dqueue_init(&q, 100)); IGRAPH_FINALLY(igraph_dqueue_destroy, &q); IGRAPH_VECTOR_INIT_FINALLY(&verts, 0); IGRAPH_VECTOR_INIT_FINALLY(&neis, 0); for(actstart=0; resco<maxcompno && actstart < no_of_nodes; actstart++) { if (already_added[actstart]) { continue; } IGRAPH_ALLOW_INTERRUPTION(); igraph_vector_clear(&verts); already_added[actstart]=1; IGRAPH_CHECK(igraph_vector_push_back(&verts, actstart)); IGRAPH_CHECK(igraph_dqueue_push(&q, actstart)); while (!igraph_dqueue_empty(&q) ) { long int actvert=(long int) igraph_dqueue_pop(&q); IGRAPH_CHECK(igraph_neighbors(graph, &neis, (igraph_integer_t) actvert, IGRAPH_ALL)); for (i=0; i<igraph_vector_size(&neis); i++) { long int neighbor=(long int) VECTOR(neis)[i]; if (already_added[neighbor]==1) { continue; } IGRAPH_CHECK(igraph_dqueue_push(&q, neighbor)); IGRAPH_CHECK(igraph_vector_push_back(&verts, neighbor)); already_added[neighbor]=1; } } /* ok, we have a component */ if (igraph_vector_size(&verts)<minelements) { continue; } newg=igraph_Calloc(1, igraph_t); if (newg==0) { IGRAPH_ERROR("Cannot decompose graph", IGRAPH_ENOMEM); } IGRAPH_CHECK(igraph_vector_ptr_push_back(components, newg)); IGRAPH_CHECK(igraph_induced_subgraph(graph, newg, igraph_vss_vector(&verts), IGRAPH_SUBGRAPH_AUTO)); resco++; } /* for actstart++ */ igraph_vector_destroy(&neis); igraph_vector_destroy(&verts); igraph_dqueue_destroy(&q); igraph_free(already_added); IGRAPH_FINALLY_CLEAN(5); /* + components */ return 0; }
static PyObject *ignp_fun_propagate(PyObject *self, PyObject *args) { long int num_active = 0; long int num_susc = 1; long int limit = 30; long int i; float lrAct; PyObject* mem_addr_o; long int mem_addr; /* StateTracker Vars */ PyArrayObject *py_trkr; // 'i64' /* By EdgeID */ PyArrayObject *py_tie_r; // 'f32' /* By NodeID */ PyArrayObject *py_act_n; // 'i8' PyArrayObject *py_thr_n; // 'f32' PyArrayObject *py_exp_n; // 'i64' /* By Infection Order*/ PyArrayObject *py_deg; // i64 PyArrayObject *py_nSuc; // i64 PyArrayObject *py_nAct; // i64 PyArrayObject *py_lrAct; // f32 PyArrayObject *py_hom; // i64 PyArrayObject *py_eComp; // i64 PyArrayObject *py_iComp; // i64 PyArrayObject *py_eTri; // i64 PyArrayObject *py_iTri; // i64 PyArrayObject *py_thr; // i32 PyArrayObject *py_exp; // i64 PyArrayObject *py_cTime; // i64 PyObject *g_obj; igraph_t *g; igraph_t gc; long int randID; long int low = 0; long int high = -1; long int ctime = 0; igraph_rng_t *rGen; igraph_vit_t nbr_iter; igraph_vs_t nbr_sel; igraph_integer_t eid; igraph_integer_t vdeg; igraph_integer_t e_comp = 0; igraph_integer_t i_comp = 0; igraph_integer_t e_tri = 0; igraph_integer_t i_tri = 0; int actv_nbr_count; //int res, j; igraph_vector_t temp; //igraph_vector_t actv_nbrs; //PySys_WriteStdout("Parse Started\n"); if (!PyArg_ParseTuple(args, "OO!O!O!O!O!O!O!O!O!O!O!O!O!O!O!O!O!", &g_obj, &PyArray_Type, &py_trkr, // i64 &PyArray_Type, &py_tie_r, // 'f32' &PyArray_Type, &py_act_n, // 'i8' &PyArray_Type, &py_thr_n, // 'i32' &PyArray_Type, &py_exp_n, // 'i64' &PyArray_Type, &py_deg, // i64 &PyArray_Type, &py_nSuc, // i64 &PyArray_Type, &py_nAct, // i64 &PyArray_Type, &py_lrAct, // f32 &PyArray_Type, &py_hom, // i64 &PyArray_Type, &py_eComp, // i64 &PyArray_Type, &py_iComp, // i64 &PyArray_Type, &py_eTri, // i64 &PyArray_Type, &py_iTri, // i64 &PyArray_Type, &py_thr, // i64 &PyArray_Type, &py_exp, // i64 &PyArray_Type, &py_cTime // i64 )) { printf("Parse Failed\n"); Py_RETURN_NONE; } //PySys_WriteStdout("Getting Tracker Vars\n"); num_active = (long) ax_i64(py_trkr, 0); num_susc = (long) ax_i64(py_trkr, 1); limit = (long) ax_i64(py_trkr, 2); mem_addr_o = PyObject_CallMethod(g_obj, "_raw_pointer", "()"); mem_addr = PyInt_AsLong(mem_addr_o); Py_DECREF(mem_addr_o); if (mem_addr == -1) { printf("PyInt to Long Failed"); return NULL; } g = (igraph_t*) mem_addr; //Setup Vars rGen = igraph_rng_default(); //igraph_rng_init(rGen, time(NULL)); high += (long) igraph_vcount(g); //PySys_WriteStdout("Propagate Starting with %li active of target %li with %li open\n", // num_active, limit, num_susc); //Propagate do { // get random node ctime += 1; randID = igraph_rng_get_integer(rGen, low, high); if ( ax_i8(py_act_n, randID) != 1 && ax_i64(py_exp_n, randID)>=ax_i32(py_thr_n, randID) ){ //activate ax_i8(py_act_n,randID) = 1; lrAct = 0; //update nbrs actv_nbr_count = 0; igraph_vs_adj( &nbr_sel, randID, IGRAPH_ALL); igraph_vit_create(g, nbr_sel, &nbr_iter); igraph_vs_size(g, &nbr_sel, &vdeg); igraph_vector_init(&temp, vdeg); while( !IGRAPH_VIT_END(nbr_iter) ){ i = (long int) IGRAPH_VIT_GET(nbr_iter); ax_i64( py_exp_n, i ) += 1; /* update active nbr count and collect id of active */ if ( ax_i8(py_act_n, i) == i ) { VECTOR(temp)[actv_nbr_count]=i; actv_nbr_count += 1; } /* update num_susc */ if ( ax_i8(py_act_n, i) == 0 && \ ax_i32(py_thr_n, i) > (float) (ax_i64(py_exp_n, i)-1) && \ ax_i32(py_thr_n, i) <= (float) ax_i64(py_exp_n, i) ){ /*PySys_WriteStdout("%li < %i <= %li\n", (ax_i64(py_exp_n, i)-1), ax_i32(py_thr_n, i), ax_i64(py_exp_n, i) );*/ num_susc += 1; } /* Get #active long ties */ if ( ax_i8(py_act_n, i) == 1 ){ igraph_get_eid(g, &eid, randID, i, 0, 1); lrAct += ax_f32( py_tie_r, eid )>2 ; } IGRAPH_VIT_NEXT(nbr_iter); } igraph_vit_destroy(&nbr_iter); igraph_vs_destroy(&nbr_sel); //Compute Components (among all and active nbrs) igraph_vs_adj( &nbr_sel, randID, IGRAPH_ALL); igraph_induced_subgraph(g, &gc, nbr_sel, IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH); igraph_clusters(&gc, NULL, NULL, &e_comp, IGRAPH_WEAK); e_tri = igraph_vcount(&gc); igraph_destroy(&gc); igraph_vs_destroy(&nbr_sel); igraph_induced_subgraph(g, &gc, igraph_vss_vector(&temp), \ IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH); igraph_clusters(&gc, NULL, NULL, &i_comp, IGRAPH_WEAK); i_tri = igraph_vcount(&gc); //Clean up igraph_destroy(&gc); igraph_vector_destroy(&temp); //PySys_WriteStdout("e_comp: %i, i_comp: %i\n", e_comp, i_comp); //PySys_WriteStdout("e_tri: %i, i_tri: %i\n", e_tri, i_tri); //update tracking vars ax_f32( py_lrAct, num_active ) = (npy_float32) lrAct; ax_i32( py_thr, num_active) = ax_i32(py_thr_n, randID); ax_i64( py_deg, num_active) = (npy_int64) vdeg; ax_i64( py_nSuc, num_active) = (npy_int64) num_susc; ax_i64( py_nAct, num_active) = (npy_int64) num_active; //ax_i64( py_hom, num_active) = (npy_int64) num_susc; ax_i64( py_eComp, num_active) = (npy_int64) e_comp; ax_i64( py_iComp, num_active) = (npy_int64) i_comp; ax_i64( py_eTri, num_active) = (npy_int64) e_tri; ax_i64( py_iTri, num_active) = (npy_int64) i_tri; ax_i64( py_exp, num_active) = ax_i64(py_exp_n, randID); ax_i64( py_cTime, num_active) = (npy_int64) ctime; num_active += 1; } } while( num_susc > num_active && num_active < limit); //PySys_WriteStdout("Propagate Finished with %li active of target %li with %li open\n", // num_active, limit, num_susc); //igraph_rng_destroy(rGen); ax_i64(py_trkr, 0) = (npy_int64) num_active; ax_i64(py_trkr, 1) = (npy_int64) num_susc ; ax_i64(py_trkr, 2) = (npy_int64) limit ; Py_RETURN_NONE; }