int main() {
  
  igraph_t g;
  igraph_integer_t result;
  igraph_vector_t edges, res;
  igraph_vs_t vids;
  long i, n;
  
  igraph_tree(&g, 10, 3, IGRAPH_TREE_OUT);
  igraph_rewire(&g, 1000, IGRAPH_REWIRING_SIMPLE);
  
  n=igraph_vcount(&g);
  igraph_vector_init(&res, 0);
  igraph_degree(&g, &res, igraph_vss_all(), IGRAPH_IN, 0);
  for (i=0; i<n; i++)
    printf("%ld ", (long)igraph_vector_e(&res, i));
  printf("\n");
  
  igraph_degree(&g, &res, igraph_vss_all(), IGRAPH_OUT, 0);
  for (i=0; i<n; i++)
    printf("%ld ", (long)igraph_vector_e(&res, i));
  printf("\n");
    
  igraph_destroy(&g);
  igraph_vector_destroy(&res);
  
  return 0;
}
int main() {
  
  igraph_t g;
  igraph_vector_t result;
  long i;
  
  igraph_vector_init(&result, 0);

  igraph_small(&g, 7, 0, 0,1,0,2,0,3,1,2,1,3,2,3,3,4,4,5,4,6,5,6, -1);
  igraph_convergence_degree(&g, &result, 0, 0);
  for (i=0; i<igraph_ecount(&g); i++)
    printf("%.4f ", (float)igraph_vector_e(&result, i));
  printf("\n");
  igraph_destroy(&g);

  igraph_small(&g, 6, 1, 1,0,2,0,3,0,4,0,0,5, -1);
  igraph_convergence_degree(&g, &result, 0, 0);
  for (i=0; i<igraph_ecount(&g); i++)
    printf("%.4f ", (float)igraph_vector_e(&result, i));
  printf("\n");
  igraph_destroy(&g);

  igraph_vector_destroy(&result);
  
  return 0;
}
Exemple #3
0
static gboolean _tgengraph_hasSelfLoop(TGenGraph* g, igraph_integer_t vertexIndex) {
    TGEN_ASSERT(g);
    gboolean isLoop = FALSE;

    igraph_vector_t* resultNeighborVertices = g_new0(igraph_vector_t, 1);
    gint result = igraph_vector_init(resultNeighborVertices, 0);

    if(result == IGRAPH_SUCCESS) {
        result = igraph_neighbors(g->graph, resultNeighborVertices, vertexIndex, IGRAPH_OUT);
        if(result == IGRAPH_SUCCESS) {
            glong nVertices = igraph_vector_size(resultNeighborVertices);
            for (gint i = 0; i < nVertices; i++) {
                igraph_integer_t dstVertexIndex = igraph_vector_e(resultNeighborVertices, i);
                if(vertexIndex == dstVertexIndex) {
                    isLoop = TRUE;
                    break;
                }
            }
        }
    }

    igraph_vector_destroy(resultNeighborVertices);
    g_free(resultNeighborVertices);
    return isLoop;
}
Exemple #4
0
ostream& operator<<(std::ostream& out, const QoSLinkWeightMap & qm){
	QoSLinkWeightMap::const_iterator it = qm.begin();
	for (; it != qm.end(); ++it){
		out<<(int)it->first<<"\t";
		
		// Vector
		int vsize = igraph_vector_size(&it->second);
		for (int i=0; i<vsize; i++){
			out<<(int)igraph_vector_e(&it->second,i)<<"\t";
		}
		out<<endl;
	}
	
	return out;
}
Exemple #5
0
GQueue* tgengraph_getNextActions(TGenGraph* g, TGenAction* action) {
    TGEN_ASSERT(g);

    /* given an action, get all of the next actions in the dependency graph */

    gpointer key = tgenaction_getKey(action);
    igraph_integer_t srcVertexIndex = (igraph_integer_t) GPOINTER_TO_INT(key);

    /* initialize a vector to hold the result neighbor vertices for this action */
    igraph_vector_t* resultNeighborVertices = g_new0(igraph_vector_t, 1);

    /* initialize with 0 entries, since we dont know how many neighbors we have */
    gint result = igraph_vector_init(resultNeighborVertices, 0);
    if(result != IGRAPH_SUCCESS) {
        tgen_critical("igraph_vector_init return non-success code %i", result);
        g_free(resultNeighborVertices);
        return FALSE;
    }

    /* now get all outgoing 1-hop neighbors of the given action */
    result = igraph_neighbors(g->graph, resultNeighborVertices, srcVertexIndex, IGRAPH_OUT);
    if(result != IGRAPH_SUCCESS) {
        tgen_critical("igraph_neighbors return non-success code %i", result);
        igraph_vector_destroy(resultNeighborVertices);
        g_free(resultNeighborVertices);
        return NULL;
    }

    /* handle the results */
    glong nVertices = igraph_vector_size(resultNeighborVertices);
    tgen_debug("found %li neighbors to vertex %i", nVertices, (gint)srcVertexIndex);

    GQueue* nextActions = g_queue_new();

    for (gint i = 0; i < nVertices; i++) {
        igraph_integer_t dstVertexIndex = igraph_vector_e(resultNeighborVertices, i);
        TGenAction* nextAction = _tgengraph_getAction(g, dstVertexIndex);
        if(nextAction) {
            g_queue_push_tail(nextActions, nextAction);
        }
    }

    /* cleanup */
    igraph_vector_destroy(resultNeighborVertices);
    g_free(resultNeighborVertices);

    return nextActions;
}
Exemple #6
0
int main(void) {

    // This needs to be done *first*. See igraph doc for why.
    igraph_i_set_attribute_table(&igraph_cattribute_table);

    printf("sizeof(int)=%d sizeof(long)=%d sizeof(igraph_integer_t)=%d\n", (int) sizeof(int), (int) sizeof(long), (int) sizeof(igraph_integer_t));

    pause();

    printf("Loading graph from file...\n");
    FILE* f = fopen("donnees/arretes.test", "r");
    //FILE* f = fopen("graph_a.ncol", "r");
    igraph_t gr;
    igraph_read_graph_ncol(&gr, f, NULL, 1, 0, 0);
    fclose(f);
    f = NULL;
    long vcount = igraph_vcount(&gr);
    long ecount = igraph_ecount(&gr);
    printf("Main graph: |V| = %ld, |E| = %ld\n", vcount, ecount);

    pause();

    // get connected components
    printf("Computing connected components...\n");
    igraph_vector_t membership;
    igraph_vector_t csize;
    igraph_integer_t cnum = 0;
    igraph_vector_init(&membership, 1);
    igraph_vector_init(&csize, 1);
    igraph_clusters(&gr, &membership, &csize, &cnum, IGRAPH_STRONG);
    printf("There are %ld connected components.\n", (long) cnum);

    // work with connected components
    {  
        printf("Writing connected components to file...\n");
        // open file
        FILE* filout = fopen("groupes", "w");

        long membership_size = igraph_vector_size(&membership);
        if (membership_size != vcount) {
            fprintf(stderr, "FATAL ERROR: membership_size != vcount\n");
            exit(1);
        }
        for (long i = 0; i < membership_size; i++) {
            fprintf(filout,
                "%ld\t%s\n",
                // connected component id:
                (long) igraph_vector_e(&membership , i),
                // veretex name:
                igraph_cattribute_VAS(&gr, "name", i));
        }

        fclose(filout);
        filout = NULL;
        printf("Connected components written.\n");
    }


    pause();


    // free connected components
    igraph_vector_destroy(&membership);
    igraph_vector_destroy(&csize);
    // free main graph
    igraph_destroy(&gr);

    printf("Program ends.\n");

    pause();

    return 0;
}