#------------------------------------------- # une utilisation très simple de igraph # LIII BIM ASD # P. Coquillard, 2019 #------------------------------------------- # source ("http://www.grappa.univ-lille3.fr/~ppreux/ensg/miashs/l3-thg/tps/td2/graphes.exo.bipartite.R") source ("http://www.grappa.univ-lille3.fr/~ppreux/ensg/miashs/l3-thg/tps/td2/graphes.exo.coloriage.R") # ou bien : #install.packages("igraph") library(igraph) # demo(package="igraph") # help("igraph-package") # graphes pas tout a fait au hasard... t <-make_tree(15) plot(t) t <-make_star(10, mode = "out") plot(t) t <- make_full_graph(8) plot(t) t <- make_ring(10, directed = TRUE, mutual = TRUE) t summary(t) plot(t) t <- make_tree(10) vertex_attr(t) <- list(name = LETTERS[1:10], color = rep("green", gorder(t))) vertex_attr(t, "label") <- V(t)$name t plot(t) tkplot(t) t <- graph_from_literal( Anne +-- Julien +--+ Daniele, Cecile:Guy, Helenne +-- Anne ) t tkplot(t) # pour s'amuser.... library(rgl) t <- make_lattice( c(5,4,3) ) coords <- layout_with_fr(t, dim=3) rglplot(t, layout=coords) #-----------# # Notre graphe g <- graph( c(6,1, 1,2, 1,3, 1,4, 2,3, 3,4, 4,5, 3,5), n=6 ) g plot(g) # regarder attentivement les parametres de dfs help(dfs) gg <-dfs(g, root=6, neimode = c("out"), TRUE, TRUE, TRUE, TRUE, TRUE) names(gg) gg$father gg$dist gg$order gg$order.out gg2 <-dfs(g, root=2, neimode = c("in"), TRUE, TRUE, TRUE, TRUE, TRUE) gg2$father gg2$dist gg2$order gg2$order.out ##########------------------------------------------------