Hi ObiWahn,
welcome to the forum!
In the COPY_AND_DELETE
, the vertex ids should simply slide down towards zero as if you pulled the deleted vertices from under their feet. So if you have
0 1 2 3 4
and you want the subgraph induced by 2 and 4, then 2 > 0
and 4 > 1
. The code is a little twisted by that’s my understanding of it.
In case anyone wants to dig a little, here is the chain of functions called:
igraph_induced_subgraph

igraph_induced_subgraph_map
(with no maps)

igraph_i_subgraph_copy_and_delete
, which makes a copy of the graph and then deletes the vertices via…

igraph_delete_vertices_idx
(again, no maps)
The last function has this code snippet (simplified a little):
/* create vertex recoding vector */
for (remaining_vertices = 0, i = 0; i < no_of_nodes; i++) {
if (<vertex to be kept>) {
VECTOR(*my_vertex_recoding)[i] = remaining_vertices + 1; // < NEW VERTEX ID (+1)!
remaining_vertices++;
}
}
/* create edge recoding vector */
for (remaining_edges = 0, i = 0; i < no_of_edges; i++) {
long int from = (long int) VECTOR(graph>from)[i];
long int to = (long int) VECTOR(graph>to)[i];
if (VECTOR(*my_vertex_recoding)[from] != 0 &&
VECTOR(*my_vertex_recoding)[to ] != 0) {
VECTOR(edge_recoding)[i] = remaining_edges + 1;
remaining_edges++;
}
}
/* start creating the graph */
newgraph.n = (igraph_integer_t) remaining_vertices;
/* Add the edges */
for (i = 0, j = 0; j < remaining_edges; i++) {
if (VECTOR(edge_recoding)[i] > 0) {
long int from = (long int) VECTOR(graph>from)[i];
long int to = (long int) VECTOR(graph>to )[i];
VECTOR(newgraph.from)[j] = VECTOR(*my_vertex_recoding)[from]  1;
VECTOR(newgraph.to )[j] = VECTOR(*my_vertex_recoding)[to]  1;
j++;
}
}