Hi,
You did not mention whether you are working with igraph in C, R or Python so I can give you only some generic ideas:
I want to filter a graph that I made. If a vertex has a degree 1 and is connected to another vertex who has also got degree 1 -> delete both vertices (and also the corresponding edge).
But if a vertex has a degree 1 and is connected to a vertex with degree > 1 do not delete the vertex.
1. Find all vertices with degree 1 and store their IDs in a list. (Use igraph_degree in C, degree() in R, Graph.degree() in Python)
2. Find all the edges connecting these vertices. (Use igraph_es_fromto in C, E(g)[vertices %--% vertices] in R, or Graph.es.select(_within=vertices) in Python.
3. Delete the selected edges. (Use igraph_delete_edges in C, delete.edges in R, or the delete() method of whatever was returned by Graph.es.select(...) in Python).
Second,
I want to layout the graph but I want to add the coordinates as attributes to the nodes instead of plotting it as an image file. How to go about this? I cannot find any examples.
The layout algorithms in igraph (e.g., layout.fruchterman.reingold in R) simply return a matrix. Just assign these to the vertices as attributes.
In R:
layout <- layout.fruchterman.reingold(g)
V(g)$x <- layout[,1]
V(g)$y <- layout[,2]
In Python:
layout = g.layout("fr")
g.vs["x"], g.vs["y"] = zip(*layout)
--
T.
_______________________________________________
igraph-help mailing list