int main() { igraph_t graph; igraph_vector_t walk, weights; igraph_integer_t ec, i; igraph_rng_seed(igraph_rng_default(), 137); igraph_vector_init(&walk, 0); igraph_vector_init(&weights, 0); /* This directed graph has loop edges. It also has multi-edges when considered as undirected. */ igraph_de_bruijn(&graph, 3, 2); ec = igraph_ecount(&graph); /* unweighted, directed */ igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN); assert(igraph_vector_size(&walk) == 1000); /* unweighted, undirected */ igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN); assert(igraph_vector_size(&walk) == 1000); igraph_vector_resize(&weights, ec); for (i=0; i < ec; ++i) VECTOR(weights)[i] = igraph_rng_get_unif01(igraph_rng_default()); /* weighted, directed */ igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN); assert(igraph_vector_size(&walk) == 1000); /* weighted, undirecetd */ igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN); assert(igraph_vector_size(&walk) == 1000); igraph_destroy(&graph); /* 1-vertex graph, should get stuck */ igraph_empty(&graph, 1, /* directed = */ 0); igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN); assert(igraph_vector_size(&walk) == 0); igraph_destroy(&graph); igraph_vector_destroy(&weights); igraph_vector_destroy(&walk); return 0; }

void multi_yw(double *acf, int *pn, int *pomax, int *pnser, double *coef, double *pacf, double *var, double *aic, int *porder, int *useaic) { int i, m; int omax = *pomax, n = *pn, nser=*pnser, order=*porder; double aicmin; Array acf_array, p_forward, p_back, v_forward, v_back; Array *A, *B; int dim[3]; dim[0] = omax+1; dim[1] = dim[2] = nser; acf_array = make_array(acf, dim, 3); p_forward = make_array(pacf, dim, 3); v_forward = make_array(var, dim, 3); /* Backward equations (discarded) */ p_back= make_zero_array(dim, 3); v_back= make_zero_array(dim, 3); A = (Array *) R_alloc(omax+2, sizeof(Array)); B = (Array *) R_alloc(omax+2, sizeof(Array)); for (i = 0; i <= omax; i++) { A[i] = make_zero_array(dim, 3); B[i] = make_zero_array(dim, 3); } whittle(acf_array, omax, A, B, p_forward, v_forward, p_back, v_back); /* Model order selection */ for (m = 0; m <= omax; m++) { aic[m] = n * ldet(subarray(v_forward,m)) + 2 * m * nser * nser; } if (*useaic) { order = 0; aicmin = aic[0]; for (m = 0; m <= omax; m++) { if (aic[m] < aicmin) { aicmin = aic[m]; order = m; } } } else order = omax; *porder = order; for(i = 0; i < vector_length(A[order]); i++) coef[i] = VECTOR(A[order])[i]; }

int igraph_is_connected_weak(const igraph_t *graph, igraph_bool_t *res) { long int no_of_nodes=igraph_vcount(graph); char *already_added; igraph_vector_t neis=IGRAPH_VECTOR_NULL; igraph_dqueue_t q=IGRAPH_DQUEUE_NULL; long int i, j; already_added=igraph_Calloc(no_of_nodes, char); if (already_added==0) { IGRAPH_ERROR("is connected (weak) failed", IGRAPH_ENOMEM); } IGRAPH_FINALLY(free, already_added); /* TODO: hack */ IGRAPH_DQUEUE_INIT_FINALLY(&q, 10); IGRAPH_VECTOR_INIT_FINALLY(&neis, 0); /* Try to find at least two clusters */ already_added[0]=1; IGRAPH_CHECK(igraph_dqueue_push(&q, 0)); j=1; while ( !igraph_dqueue_empty(&q)) { long int actnode=igraph_dqueue_pop(&q); IGRAPH_ALLOW_INTERRUPTION(); IGRAPH_CHECK(igraph_neighbors(graph, &neis, actnode, IGRAPH_ALL)); for (i=0; i <igraph_vector_size(&neis); i++) { long int neighbor=VECTOR(neis)[i]; if (already_added[neighbor] != 0) { continue; } IGRAPH_CHECK(igraph_dqueue_push(&q, neighbor)); j++; already_added[neighbor]++; } } /* Connected? */ *res = (j == no_of_nodes); igraph_Free(already_added); igraph_dqueue_destroy(&q); igraph_vector_destroy(&neis); IGRAPH_FINALLY_CLEAN(3); return 0; }

int igraph_i_2dgrid_addvertices(igraph_2dgrid_t *grid, igraph_vector_t *eids, igraph_integer_t vid, igraph_real_t r, long int x, long int y) { long int act; igraph_real_t *v=VECTOR(grid->next); r=r*r; act=(long int) MATRIX(grid->startidx, x, y); while (act != 0) { if (igraph_2dgrid_dist2(grid, vid, act-1) < r) { IGRAPH_CHECK(igraph_vector_push_back(eids, act-1)); } act=(long int) v[act-1]; } return 0; }

int splicing_dgesdd(const splicing_matrix_t *matrix, splicing_vector_t *values) { splicing_matrix_t tmp; int m=splicing_matrix_nrow(matrix); int n=splicing_matrix_ncol(matrix); int lda=m, minmn= m < n ? m : n, maxmn = m < n ? n : m; int lwork=-1; int info=0; splicing_vector_t work; splicing_vector_int_t iwork; char jobz='N'; int dummy=1; double dummy2; SPLICING_CHECK(splicing_matrix_copy(&tmp, matrix)); SPLICING_FINALLY(splicing_matrix_destroy, &tmp); SPLICING_CHECK(splicing_vector_init(&work, 1)); SPLICING_FINALLY(splicing_vector_destroy, &work); SPLICING_CHECK(splicing_vector_int_init(&iwork, 8*minmn)); SPLICING_FINALLY(splicing_vector_int_destroy, &iwork); SPLICING_CHECK(splicing_vector_resize(values, minmn)); /* Get the optiomal lwork first*/ splicingdgesdd_(&jobz, &m, &n, &MATRIX(tmp,0,0), &lda, VECTOR(*values), /*U=*/ &dummy2, /*LDU=*/ &dummy, /*VT=*/ &dummy2, /*LDVT=*/ &dummy, VECTOR(work), &lwork, VECTOR(iwork), &info); lwork = VECTOR(work)[0]; SPLICING_CHECK(splicing_vector_resize(&work, lwork)); /* Now do the SVD */ splicingdgesdd_(&jobz, &m, &n, &MATRIX(tmp,0,0), &lda, VECTOR(*values), /*U=*/ &dummy2, /*LDU=*/ &dummy, /*VT=*/ &dummy2, /*LDVT=*/ &dummy, VECTOR(work), &lwork, VECTOR(iwork), &info); if (info != 0) { SPLICING_ERROR("Cannot calculate SVD", SPLICING_ELAPACK); } splicing_vector_destroy(&work); splicing_vector_int_destroy(&iwork); splicing_matrix_destroy(&tmp); SPLICING_FINALLY_CLEAN(3); return 0; }

/*-<==>----------------------------------------------------------------- / Save the new camera position and target point. / Define the axis of the camera (front, up, left) in world coordinates / based on the current values of the vectors target & loc /---------------------------------------------------------------------*/ void CCamera::lookAt(const VECTOR &src_point, const VECTOR &dst_point) { loc = src_point;//position target = dst_point;//target // Pendiente de implementar correctamente // ... front = target-loc; front.normalize(); VECTOR aux_up = VECTOR(0,1,0); left=aux_up.cross(front); left.normalize(); aux_up.normalize(); up = front.cross(left); up.normalize(); // REVISADA }

VALUE cIGraph_community_spinglass_single(VALUE self, VALUE weights, VALUE vertex, VALUE spins, VALUE update_rule, VALUE gamma){ igraph_t *graph; igraph_vector_t weights_vec; igraph_vector_t community; igraph_real_t cohesion; igraph_real_t adhesion; VALUE group; VALUE res; int i; Data_Get_Struct(self, igraph_t, graph); igraph_vector_init(&community,0); igraph_vector_init(&weights_vec,RARRAY_LEN(weights)); for(i=0;i<RARRAY_LEN(weights);i++){ VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]); } igraph_community_spinglass_single(graph, igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL, cIGraph_get_vertex_id(self, vertex), &community, &cohesion, &adhesion, NULL, NULL, NUM2INT(spins),NUM2INT(update_rule), NUM2DBL(gamma)); group = rb_ary_new(); for(i=0;i<igraph_vector_size(&community);i++){ rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } res = rb_ary_new3(3,group, rb_float_new(cohesion), rb_float_new(adhesion)); igraph_vector_destroy(&community); igraph_vector_destroy(&weights_vec); return res; }

int main() { igraph_t g; igraph_vector_ptr_t vecs, evecs; long int i; igraph_vs_t vs; igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 1); igraph_vector_ptr_init(&vecs, 5); igraph_vector_ptr_init(&evecs, 5); for (i=0; i<igraph_vector_ptr_size(&vecs); i++) { VECTOR(vecs)[i] = calloc(1, sizeof(igraph_vector_t)); igraph_vector_init(VECTOR(vecs)[i], 0); VECTOR(evecs)[i] = calloc(1, sizeof(igraph_vector_t)); igraph_vector_init(VECTOR(evecs)[i], 0); } igraph_vs_vector_small(&vs, 1, 3, 5, 2, 1, -1); igraph_get_shortest_paths(&g, &vecs, &evecs, 0, vs, IGRAPH_OUT); check_evecs(&g, &vecs, &evecs, 10); for (i=0; i<igraph_vector_ptr_size(&vecs); i++) { print_vector(VECTOR(vecs)[i]); igraph_vector_destroy(VECTOR(vecs)[i]); free(VECTOR(vecs)[i]); igraph_vector_destroy(VECTOR(evecs)[i]); free(VECTOR(evecs)[i]); } igraph_vector_ptr_destroy(&vecs); igraph_vector_ptr_destroy(&evecs); igraph_vs_destroy(&vs); igraph_destroy(&g); if (!IGRAPH_FINALLY_STACK_EMPTY) return 1; return 0; }

int igraph_i_maximal_cliques_select_pivot(const igraph_vector_int_t *PX, int PS, int PE, int XS, int XE, const igraph_vector_int_t *pos, const igraph_adjlist_t *adjlist, int *pivot, igraph_vector_int_t *nextv, int oldPS, int oldXE) { igraph_vector_int_t *pivotvectneis; int i, pivotvectlen, j, usize=-1; int soldPS=oldPS+1, soldXE=oldXE+1, sPS=PS+1, sPE=PE+1; /* Choose a pivotvect, and bring up P vertices at the same time */ for (i=PS; i<=XE; i++) { int av=VECTOR(*PX)[i]; igraph_vector_int_t *avneis=igraph_adjlist_get(adjlist, av); int *avp=VECTOR(*avneis); int avlen=igraph_vector_int_size(avneis); int *ave=avp+avlen; int *avnei=avp, *pp=avp; for (; avnei < ave; avnei++) { int avneipos=VECTOR(*pos)[(int)(*avnei)]; if (avneipos < soldPS || avneipos > soldXE) { break; } if (avneipos >= sPS && avneipos <= sPE) { if (pp != avnei) { int tmp=*avnei; *avnei = *pp; *pp = tmp; } pp++; } } if ((j=pp-avp) > usize) { *pivot = av; usize=j; } } igraph_vector_int_push_back(nextv, -1); pivotvectneis=igraph_adjlist_get(adjlist, *pivot); pivotvectlen=igraph_vector_int_size(pivotvectneis); for (j=PS; j <= PE; j++) { int vcand=VECTOR(*PX)[j]; igraph_bool_t nei=0; int k=0; for (k=0; k < pivotvectlen; k++) { int unv=VECTOR(*pivotvectneis)[k]; int unvpos=VECTOR(*pos)[unv]; if (unvpos < sPS || unvpos > sPE) { break; } if (unv == vcand) { nei=1; break; } } if (!nei) { igraph_vector_int_push_back(nextv, vcand); } } return 0; }

int splicing_iso_to_genomic(const splicing_gff_t *gff, size_t gene, const splicing_vector_int_t *isoform, const splicing_gff_converter_t *converter, splicing_vector_int_t *position) { size_t i, n=splicing_vector_int_size(position); splicing_gff_converter_t vconverter, *myconverter = (splicing_gff_converter_t*) converter; if (!converter) { myconverter=&vconverter; SPLICING_CHECK(splicing_gff_converter_init(gff, gene, myconverter)); SPLICING_FINALLY(splicing_gff_converter_destroy, myconverter); } /* Do the shifting */ for (i=0; i<n; i++) { int iso=VECTOR(*isoform)[i]; size_t pos=VECTOR(*position)[i]; int ex; if (pos==-1) { continue; } for (ex=VECTOR(myconverter->exidx)[iso]; ex < VECTOR(myconverter->exidx)[iso+1] && VECTOR(myconverter->exlim)[ex] <= pos; ex++) ; if (ex < VECTOR(myconverter->exidx)[iso+1]) { VECTOR(*position)[i] = pos + VECTOR(myconverter->shift)[ex]; } else { VECTOR(*position)[i] = -1; } } if (!converter) { splicing_gff_converter_destroy(myconverter); SPLICING_FINALLY_CLEAN(1); } return 0; }

int splicing_genomic_to_iso(const splicing_gff_t *gff, size_t gene, const splicing_vector_int_t *position, const splicing_gff_converter_t *converter, splicing_matrix_int_t *isopos) { size_t r, i, noreads=splicing_vector_int_size(position); splicing_gff_converter_t vconverter, *myconverter = (splicing_gff_converter_t*) converter; if (!converter) { myconverter=&vconverter; SPLICING_CHECK(splicing_gff_converter_init(gff, gene, myconverter)); SPLICING_FINALLY(splicing_gff_converter_destroy, myconverter); } SPLICING_CHECK(splicing_matrix_int_resize(isopos, myconverter->noiso, noreads)); for (r=0; r<noreads; r++) { for (i=0; i<myconverter->noiso; i++) { size_t pos=VECTOR(*position)[r]; size_t startpos=VECTOR(myconverter->exidx)[i]; size_t endpos=VECTOR(myconverter->exidx)[i+1]; int ex; for (ex=startpos; ex < endpos && VECTOR(myconverter->exend)[ex] < pos; ex++) ; if (ex < endpos && VECTOR(myconverter->exstart)[ex] <= pos && pos <= VECTOR(myconverter->exend)[ex]) { MATRIX(*isopos, i, r) = VECTOR(*position)[r] - VECTOR(myconverter->shift)[ex]; } else { MATRIX(*isopos, i, r) = -1; } } } if (!converter) { splicing_gff_converter_destroy(myconverter); SPLICING_FINALLY_CLEAN(1); } return 0; }

/* -------------------------------------------------------------------------------------------------- - check collision with stairs -------------------------------------------------------------------------------------------------- */ bool PlanesPhysicHandler::ColisionWithCornerStair(const AABB & actorBB, const VECTOR &Speed, VECTOR &ModifiedSpeed) { float moveX = Speed.x; float moveZ = Speed.z; // calculate norm of speed VECTOR speedNorm = Speed.unit(); float startX = (actorBB.P.x+actorBB.E.x)/2.0f; float startZ = (actorBB.P.z+actorBB.E.z)/2.0f; std::vector<CornerStairPlane>::const_iterator it = _corner_stairs.begin(); std::vector<CornerStairPlane>::const_iterator end = _corner_stairs.end(); // for each stairs for(int i=0; it != end; ++it, ++i) { // project point to plane and check if we cross it float DotProduct=speedNorm.dot(it->Normal); // Determine If Ray Parallel To Plane if (abs(DotProduct) > 0.000001f) { // Find Distance To Collision Point float l2=(it->Normal.dot(it->C1-VECTOR(startX, actorBB.P.y, startZ)))/DotProduct; // Test If Collision Behind Start or after end if (l2 > 0 && l2 < Speed.length()) { float collionsX = startX + (speedNorm.x * l2); float collionsZ = startZ + (speedNorm.z * l2); if(it->tr_wh_y.contains(Point2D(collionsX, collionsZ))) { VECTOR spmY(Speed.x, 0, Speed.z); VECTOR Vt(it->Normal.dot(spmY)*it->Normal); VECTOR Vn(spmY - Vt); ModifiedSpeed = Vn; return true; } } } } return false; }

/******************************* ** Minimalization of the GB *** *******************************/ void gbB::minimalize_gb() { if (minimal_gb_valid) return; delete minimal_gb; minimal_gb = ReducedGB::create(originalR,F,Fsyz); VECTOR(POLY) polys; for (int i=first_gb_element; i<gb.size(); i++) { if (gb[i]->minlevel & ELEMB_MINGB) polys.push_back(gb[i]->g); } minimal_gb->minimalize(polys); minimal_gb_valid = true; }

int igraph_vector_order2(igraph_vector_t *v) { igraph_indheap_t heap; igraph_indheap_init_array(&heap, VECTOR(*v), igraph_vector_size(v)); IGRAPH_FINALLY(igraph_indheap_destroy, &heap); igraph_vector_clear(v); while (!igraph_indheap_empty(&heap)) { IGRAPH_CHECK(igraph_vector_push_back(v, igraph_indheap_max_index(&heap)-1)); igraph_indheap_delete_max(&heap); } igraph_indheap_destroy(&heap); IGRAPH_FINALLY_CLEAN(1); return 0; }

int isZeroHMMlinear(Hmm *m){ int u, v, zero = 1; for (u = 0; u < m->uu; u ++){ if (VECTOR(m->logB)[u] != 0){ zero = 0; break; } for (v = 0; v < m->uu; v ++){ if (MATRIX(m->logA)[u][v] != 0){ zero = 0; break; } } if (zero == 0) break; } return zero; }

int pysplicing_to_vector_int(PyObject *pv, splicing_vector_int_t *v) { int i, n; if (!PyTuple_Check(pv)) { PyErr_SetString(PyExc_TypeError, "Need a tuple"); return 1; } n=PyTuple_Size(pv); splicing_vector_int_init(v, n); for (i=0; i<n; i++) { PyObject *it=PyTuple_GetItem(pv, i); VECTOR(*v)[i]=PyInt_AsLong(it); } return 0; }

/** * \function igraph_maximal_independent_vertex_sets * \brief Find all maximal independent vertex sets of a graph * * </para><para> * A maximal independent vertex set is an independent vertex set which * can't be extended any more by adding a new vertex to it. * * </para><para> * The algorithm used here is based on the following paper: * S. Tsukiyama, M. Ide, H. Ariyoshi and I. Shirawaka. A new algorithm for * generating all the maximal independent sets. SIAM J Computing, * 6:505--517, 1977. * * </para><para> * The implementation was originally written by Kevin O'Neill and modified * by K M Briggs in the Very Nauty Graph Library. I simply re-wrote it to * use igraph's data structures. * * </para><para> * If you are interested in the size of the largest independent vertex set, * use \ref igraph_independence_number() instead. * * \param graph The input graph. * \param res Pointer to a pointer vector, the result will be stored * here, ie. \c res will contain pointers to \c igraph_vector_t * objects which contain the indices of vertices involved in an independent * vertex set. The pointer vector will be resized if needed but note that the * objects in the pointer vector will not be freed. * \return Error code. * * \sa \ref igraph_maximal_cliques(), \ref * igraph_independence_number() * * Time complexity: TODO. */ int igraph_maximal_independent_vertex_sets(const igraph_t *graph, igraph_vector_ptr_t *res) { igraph_i_max_ind_vsets_data_t clqdata; long int no_of_nodes = igraph_vcount(graph), i; if (igraph_is_directed(graph)) IGRAPH_WARNING("directionality of edges is ignored for directed graphs"); clqdata.matrix_size=no_of_nodes; clqdata.keep_only_largest=0; IGRAPH_CHECK(igraph_adjlist_init(graph, &clqdata.adj_list, IGRAPH_ALL)); IGRAPH_FINALLY(igraph_adjlist_destroy, &clqdata.adj_list); clqdata.IS = igraph_Calloc(no_of_nodes, igraph_integer_t); if (clqdata.IS == 0) IGRAPH_ERROR("igraph_maximal_independent_vertex_sets failed", IGRAPH_ENOMEM); IGRAPH_FINALLY(igraph_free, clqdata.IS); IGRAPH_VECTOR_INIT_FINALLY(&clqdata.deg, no_of_nodes); for (i=0; i<no_of_nodes; i++) VECTOR(clqdata.deg)[i] = igraph_vector_size(igraph_adjlist_get(&clqdata.adj_list, i)); clqdata.buckets = igraph_Calloc(no_of_nodes+1, igraph_set_t); if (clqdata.buckets == 0) IGRAPH_ERROR("igraph_maximal_independent_vertex_sets failed", IGRAPH_ENOMEM); IGRAPH_FINALLY(igraph_i_free_set_array, clqdata.buckets); for (i=0; i<no_of_nodes; i++) IGRAPH_CHECK(igraph_set_init(&clqdata.buckets[i], 0)); igraph_vector_ptr_clear(res); /* Do the show */ clqdata.largest_set_size=0; IGRAPH_CHECK(igraph_i_maximal_independent_vertex_sets_backtrack(graph, res, &clqdata, 0)); /* Cleanup */ for (i=0; i<no_of_nodes; i++) igraph_set_destroy(&clqdata.buckets[i]); igraph_adjlist_destroy(&clqdata.adj_list); igraph_vector_destroy(&clqdata.deg); igraph_free(clqdata.IS); igraph_free(clqdata.buckets); IGRAPH_FINALLY_CLEAN(4); return 0; }

void LTRandmat::work() { tuple *recv = make_tuple("s?", REQUEST); tuple *tmpInit = make_tuple("s?", "randmat state"); tuple *init = NULL; IntVector initVector = NULL; // satisfy randmat requests. while (1) { // block until we receive a tuple. tuple* gotten = get_tuple(recv, &ctx); // grab a copy of the initializer, tuple if we haven't already if (!init) { init = read_tuple(tmpInit, &ctx); initVector = (IntVector) init->elements[1].data.s.ptr; } // copy over row co-ordinate of the computation; create // a buffer for the results of the computation. size_t row = gotten->elements[1].data.i; tuple *send = make_tuple("sis", "randmat done", row, ""); IntVector buffer = (IntVector) NEW_VECTOR_SZ(INT_TYPE, RANDMAT_NC); send->elements[2].data.s.len = sizeof(INT_TYPE) * RANDMAT_NC; send->elements[2].data.s.ptr = (char*) buffer; // perform the actual computation for this row. buffer[0] = VECTOR(initVector, row); for (int x = 1; x < RANDMAT_NC; ++x) { buffer[x] = (aPrime * buffer[x-1] + cPrime) % RAND_M; } // send off the new tuple and purge local memory of the one we got put_tuple(send, &ctx); destroy_tuple(gotten); destroy_tuple(send); delete[] buffer; } // TODO destroy the template tuples; must send tuples for this // destroy_tuple(recv); }

void __init init_IRQ(void) { #if defined(CONFIG_RAMKERNEL) int i; unsigned long *ramvec,*ramvec_p; const unsigned long *trap_entry; const int *saved_vector; ramvec = get_vector_address(); if (ramvec == NULL) panic("interrupt vector serup failed."); else printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec); /* create redirect table */ ramvec_p = ramvec; trap_entry = h8300_trap_table; saved_vector = h8300_saved_vectors; for ( i = 0; i < NR_IRQS; i++) { if (i == *saved_vector) { ramvec_p++; saved_vector++; } else { if ( i < NR_TRAPS ) { if (*trap_entry) *ramvec_p = VECTOR(*trap_entry); ramvec_p++; trap_entry++; } else *ramvec_p++ = REDIRECT(interrupt_entry); } } interrupt_redirect_table = ramvec; #ifdef DUMP_VECTOR ramvec_p = ramvec; for (i = 0; i < NR_IRQS; i++) { if ((i % 8) == 0) printk(KERN_DEBUG "\n%p: ",ramvec_p); printk(KERN_DEBUG "%p ",*ramvec_p); ramvec_p++; } printk(KERN_DEBUG "\n"); #endif #endif }

int igraph_bipartite_projection(const igraph_t *graph, const igraph_vector_bool_t *types, igraph_t *proj1, igraph_t *proj2, igraph_vector_t *multiplicity1, igraph_vector_t *multiplicity2, igraph_integer_t probe1) { long int no_of_nodes=igraph_vcount(graph); /* t1 is -1 if proj1 is omitted, it is 0 if it belongs to type zero, it is 1 if it belongs to type one. The same for t2 */ int t1, t2; if (igraph_vector_bool_size(types) != no_of_nodes) { IGRAPH_ERROR("Invalid bipartite type vector size", IGRAPH_EINVAL); } if (probe1 >= no_of_nodes) { IGRAPH_ERROR("No such vertex to probe", IGRAPH_EINVAL); } if (probe1 >= 0 && !proj1) { IGRAPH_ERROR("`probe1' given, but `proj1' is a null pointer", IGRAPH_EINVAL); } if (probe1 >=0) { t1=VECTOR(*types)[(long int)probe1]; if (proj2) { t2=1-t1; } else { t2=-1; } } else { t1 = proj1 ? 0 : -1; t2 = proj2 ? 1 : -1; } IGRAPH_CHECK(igraph_i_bipartite_projection(graph, types, proj1, t1, multiplicity1)); IGRAPH_FINALLY(igraph_destroy, proj1); IGRAPH_CHECK(igraph_i_bipartite_projection(graph, types, proj2, t2, multiplicity2)); IGRAPH_FINALLY_CLEAN(1); return 0; }

int test_graph_from_leda_tutorial() { /* Test graph from the LEDA tutorial: * http://www.leda-tutorial.org/en/unofficial/ch05s03s05.html */ igraph_t graph; igraph_vector_bool_t types; igraph_vector_long_t matching; igraph_integer_t matching_size; igraph_bool_t is_matching; int i; igraph_small(&graph, 0, 0, 0, 8, 0, 12, 0, 14, 1, 9, 1, 10, 1, 13, 2, 8, 2, 9, 3, 10, 3, 11, 3, 13, 4, 9, 4, 14, 5, 14, 6, 9, 6, 14, 7, 8, 7, 12, 7, 14 , -1); igraph_vector_bool_init(&types, 15); for (i = 0; i < 15; i++) VECTOR(types)[i] = (i >= 8); igraph_vector_long_init(&matching, 0); igraph_i_maximum_bipartite_matching_unweighted(&graph, &types, &matching_size, &matching); if (matching_size != 6) { printf("matching_size is %ld, expected: 6\n", (long)matching_size); return 1; } igraph_is_maximal_matching(&graph, &types, &matching, &is_matching); if (!is_matching) { printf("not a matching: "); igraph_vector_long_print(&matching); return 3; } else igraph_vector_long_print(&matching); igraph_vector_long_destroy(&matching); igraph_vector_bool_destroy(&types); igraph_destroy(&graph); return 0; }

/* turns the coordsystem es to ee. i,j give the axis to turn, k is the axis to turn around, i,j,k are 0,1,2; 1,2,0 or 2,0,1 */ void turn(struct point *es, struct point *ee, int i, int j, int k, float angle) { struct point ne1, ne2; int l; for (l = 0; l < 3; l++) { ne1.x[l] = cos(angle) * es[i].x[l] + sin(angle) * es[j].x[l]; ne2.x[l] = -sin(angle) * es[i].x[l] + cos(angle) * es[j].x[l]; } ee[i] = ne1; ee[j] = ne2; VECTOR(&ee[k], &ee[i], &ee[j]); normalize(&ee[j]); normalize(&ee[i]); normalize(&ee[k]); }

static boolean callback_callback(set_t s, graph_t *g, clique_options *opt) { igraph_vector_t *clique; struct callback_data *cd; int i, j; CLIQUER_ALLOW_INTERRUPTION(); cd = (struct callback_data *) opt->user_data; clique = (igraph_vector_t *) malloc(sizeof(igraph_vector_t)); igraph_vector_init(clique, set_size(s)); i = -1; j = 0; while ((i = set_return_next(s,i)) >= 0) VECTOR(*clique)[j++] = i; return (*(cd->handler))(clique, cd->arg); }

/* call-seq: * graph.eigenvector_centrality(scale, weights) -> Array * * Returns a two-element arrar, the first element of which is an Array of * eigenvector centrality scores for graph, and the second of which is the * eigenvalue. * * scale is a boolean value. If true, the scores will be weighted so that the * absolute value of the maximum centrality is one. * * weights is an Array giving the weights of the edges. If nil, the edges are unweighted. */ VALUE cIGraph_eigenvector_centrality(VALUE self, VALUE scale, VALUE weights) { int i; igraph_t *graph; igraph_vector_t vec; igraph_real_t val; igraph_vector_t wgts; igraph_arpack_options_t arpack_opt; igraph_bool_t sc = 0; VALUE eigenvector = rb_ary_new(); VALUE rb_res = rb_ary_new(); IGRAPH_FINALLY(igraph_vector_destroy, &vec); IGRAPH_FINALLY(igraph_vector_destroy, &wgts); IGRAPH_CHECK(igraph_vector_init(&vec,0)); IGRAPH_CHECK(igraph_vector_init(&wgts,0)); igraph_arpack_options_init(&arpack_opt); if (scale == Qtrue) sc = 1; Data_Get_Struct(self, igraph_t, graph); if (weights == Qnil) { IGRAPH_CHECK(igraph_eigenvector_centrality(graph, &vec, &val, sc, NULL, &arpack_opt)); } else { for(i = 0; i < RARRAY_LEN(weights); i++) IGRAPH_CHECK(igraph_vector_push_back(&wgts, NUM2DBL(RARRAY_PTR(weights)[i]))); IGRAPH_CHECK(igraph_eigenvector_centrality(graph, &vec, &val, sc, &wgts, &arpack_opt)); } for(i = 0; i < igraph_vector_size(&vec); i++) rb_ary_push(eigenvector, rb_float_new(VECTOR(vec)[i])); igraph_vector_destroy(&vec); igraph_vector_destroy(&wgts); rb_ary_push(rb_res, eigenvector); rb_ary_push(rb_res, rb_float_new(val)); IGRAPH_FINALLY_CLEAN(2); return rb_res; }

int igraph_i_eigen_adjacency_arpack_sym_cb(igraph_real_t *to, const igraph_real_t *from, int n, void *extra) { igraph_adjlist_t *adjlist = (igraph_adjlist_t *) extra; igraph_vector_int_t *neis; int i, j, nlen; for (i=0; i<n; i++) { neis=igraph_adjlist_get(adjlist, i); nlen=igraph_vector_int_size(neis); to[i] = 0.0; for (j=0; j<nlen; j++) { int nei = VECTOR(*neis)[j]; to[i] += from[nei]; } } return 0; }

/* call-seq: * graph.betweenness(vs,mode) -> Array * * Returns an Array of betweenness centrality measures for the vertices given * in the vs Array. mode defines whether directed paths or considered for * directed graphs. */ VALUE cIGraph_betweenness(VALUE self, VALUE vs, VALUE directed){ igraph_t *graph; igraph_vs_t vids; igraph_vector_t vidv; igraph_bool_t dir = 0; igraph_vector_t res; int i; VALUE betweenness = rb_ary_new(); if(directed == Qtrue) dir = 1; //vector to hold the results of the degree calculations IGRAPH_FINALLY(igraph_vector_destroy, &res); IGRAPH_FINALLY(igraph_vector_destroy, &vidv); IGRAPH_FINALLY(igraph_vs_destroy,&vids); IGRAPH_CHECK(igraph_vector_init(&res,0)); Data_Get_Struct(self, igraph_t, graph); //Convert an array of vertices to a vector of vertex ids IGRAPH_CHECK(igraph_vector_init_int(&vidv,0)); cIGraph_vertex_arr_to_id_vec(self,vs,&vidv); //create vertex selector from the vecotr of ids IGRAPH_CHECK(igraph_vs_vector(&vids,&vidv)); IGRAPH_CHECK(igraph_betweenness(graph,&res,vids,dir)); for(i=0;i<igraph_vector_size(&res);i++){ rb_ary_push(betweenness,rb_float_new((float)VECTOR(res)[i])); } igraph_vector_destroy(&vidv); igraph_vector_destroy(&res); igraph_vs_destroy(&vids); IGRAPH_FINALLY_CLEAN(3); return betweenness; }

static boolean collect_cliques_callback(set_t s, graph_t *g, clique_options *opt) { igraph_vector_ptr_t *list; igraph_vector_t *clique; int i, j; CLIQUER_ALLOW_INTERRUPTION(); list = (igraph_vector_ptr_t *) opt->user_data; clique = (igraph_vector_t *) malloc(sizeof(igraph_vector_t)); igraph_vector_init(clique, set_size(s)); i = -1; j = 0; while ((i = set_return_next(s,i)) >= 0) VECTOR(*clique)[j++] = i; igraph_vector_ptr_push_back(list, clique); return TRUE; }

igraph_bool_t handler(igraph_vector_t *clique, void *arg) { struct userdata *ud; igraph_bool_t cont; ud = (struct userdata *) arg; cont = 1; /* true */ if (compare_vectors(&clique, &(VECTOR(*(ud->list))[ud->i])) != 0) { printf("igraph_cliques() and igraph_cliques_callback() give different results.\n"); cont = 0; /* false */ } igraph_vector_destroy(clique); igraph_free(clique); ud->i += 1; return cont; }

int igraph_i_eigenvector_centrality(igraph_real_t *to, const igraph_real_t *from, long int n, void *extra) { igraph_adjlist_t *adjlist=extra; igraph_vector_t *neis; long int i, j, nlen; for (i=0; i<n; i++) { neis=igraph_adjlist_get(adjlist, i); nlen=igraph_vector_size(neis); to[i]=0.0; for (j=0; j<nlen; j++) { long int nei=VECTOR(*neis)[j]; to[i] += from[nei]; } } return 0; }

int _graph_edges_to(const graph_t *graph, vector_int *eids, int vid) { assert(vid >= 0); assert(vid < graph_vertices_count(graph)); int length = (VECTOR(graph->os)[vid+1] - VECTOR(graph->os)[vid]); vector_int_resize(eids, length); int idx = 0; int j = VECTOR(graph->os)[vid+1]; for (int i = VECTOR(graph->os)[vid]; i < j; i++) VECTOR(*eids)[idx++] = VECTOR(graph->oi)[i]; return 0; }