Add edge attributes

I have weighted two graphs (G, and G_random), the one is a copy of the other. After using igraph_rewire on my G_random, I noticed the edge attributes do not carry over (perhaps that can be added to the documentation), and I would like to reassign them (randomly is fine). However,
some of the functions in Chapter 12. Graph, Vertex and Edge Attributes are documented very confusingly. For example igraph_cattribute_EAN_setv has the following:

2.2.25. igraph_cattribute_EAN_setv — Set a numeric edge attribute for all vertices.

int igraph_cattribute_EAN_setv(igraph_t *graph, const char *name, const igraph_vector_t *v);

The attribute will be added if not present yet.


graph : The graph.
name : Name of the attribute.
v : The new attribute values. The length of this vector must match the number of edges.

I think it assigns the values in v one-to-one to edges in G (or at least that is the function I am looking for), but given the reference to vertices, I am a bit confused. I would just like confirmation that the following makes sense:

Excerpt of C++ code:

// turn on attribute handling for igraph to handle edge weights
igraph_t G;
read_graph(infile, G, IGRAPH_ADD_WEIGHTS_YES);  // function that reads in a weighted graph

// make copy of G
igraph_t G_random;
igraph_copy(&G_random, &G);

// rewire the copy
igraph_rewire(&G_random, 3*E, IGRAPH_REWIRING_SIMPLE);

// fetch edge weights from original graph
igraph_vector_t edge_weights;
igraph_vector_init(&edge_weights, E);
igraph_cattribute_EANV(&G, "weight", igraph_ess_all(IGRAPH_EDGEORDER_ID), &edge_weights);

// assign them to edges in the graph copy
igraph_cattribute_EAN_setv(&G_random, "weight", &edge_weights);

// clean up

First I have to say that I have not programmed with attributes in C/igraph, so I am no more experienced in this particular topic than you.

I think you are right, and this is incorrect. Probably the descriptions were copied over and over and not properly edited.

Thanks for the suggestion! I looked at the implementation and the situation appears to be a bit messy. It seems that if only a few trials are made, it chooses a method that retains the attributes of non-rewired edges. However, if many trials are made, then it destroys all edge attributes.

I’ll let someone more familiar with the code deal with this. IMO it would be better to have some consistency in behaviour, and as a quick fix always kill all edge attributes.

My concern about this is that it’s unclear how the edge ordering changes during rewiring. This would depend on the specific implementation. Currently, there are two different implementations, dynamically chosen based on the number of requested trials. igraph gives no guarantees about the ordering.

Of course, the rewirings effectively shuffles the edge properties as well, but it’s unclear to me which specific shufflings are or aren’t possible depending on the graph structure.