1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
#' The DrL graph layout generator
#'
#' DrL is a force-directed graph layout toolbox focused on real-world
#' large-scale graphs, developed by Shawn Martin and colleagues at Sandia
#' National Laboratories.
#'
#' This function implements the force-directed DrL layout generator.
#'
#' The generator has the following parameters: \describe{ \item{edge.cut}{Edge
#' cutting is done in the late stages of the algorithm in order to achieve less
#' dense layouts. Edges are cut if there is a lot of stress on them (a large
#' value in the objective function sum). The edge cutting parameter is a value
#' between 0 and 1 with 0 representing no edge cutting and 1 representing
#' maximal edge cutting. } \item{init.iterations}{Number of iterations in the
#' first phase.} \item{init.temperature}{Start temperature, first phase.}
#' \item{init.attraction}{Attraction, first phase.}
#' \item{init.damping.mult}{Damping, first phase.}
#' \item{liquid.iterations}{Number of iterations, liquid phase.}
#' \item{liquid.temperature}{Start temperature, liquid phase.}
#' \item{liquid.attraction}{Attraction, liquid phase.}
#' \item{liquid.damping.mult}{Damping, liquid phase.}
#' \item{expansion.iterations}{Number of iterations, expansion phase.}
#' \item{expansion.temperature}{Start temperature, expansion phase.}
#' \item{expansion.attraction}{Attraction, expansion phase.}
#' \item{expansion.damping.mult}{Damping, expansion phase.}
#' \item{cooldown.iterations}{Number of iterations, cooldown phase.}
#' \item{cooldown.temperature}{Start temperature, cooldown phase.}
#' \item{cooldown.attraction}{Attraction, cooldown phase.}
#' \item{cooldown.damping.mult}{Damping, cooldown phase.}
#' \item{crunch.iterations}{Number of iterations, crunch phase.}
#' \item{crunch.temperature}{Start temperature, crunch phase.}
#' \item{crunch.attraction}{Attraction, crunch phase.}
#' \item{crunch.damping.mult}{Damping, crunch phase.}
#' \item{simmer.iterations}{Number of iterations, simmer phase.}
#' \item{simmer.temperature}{Start temperature, simmer phase.}
#' \item{simmer.attraction}{Attraction, simmer phase.}
#' \item{simmer.damping.mult}{Damping, simmer phase.}
#'
#' There are five pre-defined parameter settings as well, these are called
#' \code{drl_defaults$default}, \code{drl_defaults$coarsen},
#' \code{drl_defaults$coarsest}, \code{drl_defaults$refine} and
#' \code{drl_defaults$final}. }
#'
#' @aliases layout.drl drl_defaults igraph.drl.coarsen
#' igraph.drl.coarsest igraph.drl.default igraph.drl.final
#' igraph.drl.refine
#' @param graph The input graph, in can be directed or undirected.
#' @param use.seed Logical scalar, whether to use the coordinates given in the
#' \code{seed} argument as a starting point.
#' @param seed A matrix with two columns, the starting coordinates for the
#' vertices is \code{use.seed} is \code{TRUE}. It is ignored otherwise.
#' @param options Options for the layout generator, a named list. See details
#' below.
#' @param weights Optional edge weights. Supply \code{NULL} here if you want to
#' weight edges equally. By default the \code{weight} edge attribute is used if
#' the graph has one. Larger weights correspond to stronger connections,
#' and the vertices will be placed closer to each other.
#' @param fixed Logical vector, it can be used to fix some vertices. All
#' vertices for which it is \code{TRUE} are kept at the coordinates supplied in
#' the \code{seed} matrix. It is ignored it \code{NULL} or if \code{use.seed}
#' is \code{FALSE}.
#' @param dim Either \sQuote{2} or \sQuote{3}, it specifies whether we want a
#' two dimensional or a three dimensional layout. Note that because of the
#' nature of the DrL algorithm, the three dimensional layout takes
#' significantly longer to compute.
#' @return A numeric matrix with two columns.
#' @author Shawn Martin (\url{http://www.cs.otago.ac.nz/homepages/smartin/})
#' and Gabor Csardi \email{csardi.gabor@@gmail.com} for the R/igraph interface
#' and the three dimensional version.
#' @seealso \code{\link{layout}} for other layout generators.
#' @references See the following technical report: Martin, S., Brown, W.M.,
#' Klavans, R., Boyack, K.W., DrL: Distributed Recursive (Graph) Layout. SAND
#' Reports, 2008. 2936: p. 1-10.
#' @export
#' @importFrom stats runif
#' @keywords graphs
#' @examples
#'
#' g <- as.undirected(sample_pa(100, m=1))
#' l <- layout_with_drl(g, options=list(simmer.attraction=0))
#' \dontrun{
#' plot(g, layout=l, vertex.size=3, vertex.label=NA)
#' }
#'
layout_with_drl <- function(graph, use.seed = FALSE,
seed=matrix(runif(vcount(graph)*2), ncol=2),
options=drl_defaults$default,
weights=E(graph)$weight,
fixed=NULL,
dim=2)
{
if (!is_igraph(graph)) {
stop("Not a graph object")
}
if (dim != 2 && dim != 3) {
stop("`dim' must be 2 or 3")
}
use.seed <- as.logical(use.seed)
seed <- as.matrix(seed)
options.tmp <- drl_defaults$default
options.tmp[names(options)] <- options
options <- options.tmp
if (!is.null(weights)) {
weights <- as.numeric(weights)
}
if (!is.null(fixed)) {
fixed <- as.logical(fixed)
}
on.exit(.Call(C_R_igraph_finalizer))
if (dim==2) {
res <- .Call(C_R_igraph_layout_drl, graph, seed, use.seed, options,
weights, fixed)
} else {
res <- .Call(C_R_igraph_layout_drl_3d, graph, seed, use.seed, options,
weights, fixed)
}
res
}
#' @rdname layout_with_drl
#' @param ... Passed to \code{layout_with_drl}.
#' @export
with_drl <- function(...) layout_spec(layout_with_drl, ...)
#' @export
igraph.drl.default <- list(edge.cut=32/40,
init.iterations=0,
init.temperature=2000,
init.attraction=10,
init.damping.mult=1.0,
liquid.iterations=200,
liquid.temperature=2000,
liquid.attraction=10,
liquid.damping.mult=1.0,
expansion.iterations=200,
expansion.temperature=2000,
expansion.attraction=2,
expansion.damping.mult=1.0,
cooldown.iterations=200,
cooldown.temperature=2000,
cooldown.attraction=1,
cooldown.damping.mult=.1,
crunch.iterations=50,
crunch.temperature=250,
crunch.attraction=1,
crunch.damping.mult=0.25,
simmer.iterations=100,
simmer.temperature=250,
simmer.attraction=.5,
simmer.damping.mult=0)
#' @export
igraph.drl.coarsen <- list(edge.cut=32/40,
init.iterations=0,
init.temperature=2000,
init.attraction=10,
init.damping.mult=1.0,
liquid.iterations=200,
liquid.temperature=2000,
liquid.attraction=2,
liquid.damping.mult=1.0,
expansion.iterations=200,
expansion.temperature=2000,
expansion.attraction=10,
expansion.damping.mult=1.0,
cooldown.iterations=200,
cooldown.temperature=2000,
cooldown.attraction=1,
cooldown.damping.mult=.1,
crunch.iterations=50,
crunch.temperature=250,
crunch.attraction=1,
crunch.damping.mult=0.25,
simmer.iterations=100,
simmer.temperature=250,
simmer.attraction=.5,
simmer.damping.mult=0)
#' @export
igraph.drl.coarsest <- list(edge.cut=32/40,
init.iterations=0,
init.temperature=2000,
init.attraction=10,
init.damping.mult=1.0,
liquid.iterations=200,
liquid.temperature=2000,
liquid.attraction=2,
liquid.damping.mult=1.0,
expansion.iterations=200,
expansion.temperature=2000,
expansion.attraction=10,
expansion.damping.mult=1.0,
cooldown.iterations=200,
cooldown.temperature=2000,
cooldown.attraction=1,
cooldown.damping.mult=.1,
crunch.iterations=200,
crunch.temperature=250,
crunch.attraction=1,
crunch.damping.mult=0.25,
simmer.iterations=100,
simmer.temperature=250,
simmer.attraction=.5,
simmer.damping.mult=0)
#' @export
igraph.drl.refine <- list(edge.cut=32/40,
init.iterations=0,
init.temperature=50,
init.attraction=.5,
init.damping.mult=1.0,
liquid.iterations=0,
liquid.temperature=2000,
liquid.attraction=2,
liquid.damping.mult=1.0,
expansion.iterations=50,
expansion.temperature=500,
expansion.attraction=.1,
expansion.damping.mult=.25,
cooldown.iterations=50,
cooldown.temperature=250,
cooldown.attraction=1,
cooldown.damping.mult=.1,
crunch.iterations=50,
crunch.temperature=250,
crunch.attraction=1,
crunch.damping.mult=0.25,
simmer.iterations=0,
simmer.temperature=250,
simmer.attraction=.5,
simmer.damping.mult=0)
#' @export
igraph.drl.final <- list(edge.cut=32/40,
init.iterations=0,
init.temperature=50,
init.attraction=.5,
init.damping.mult=0,
liquid.iterations=0,
liquid.temperature=2000,
liquid.attraction=2,
liquid.damping.mult=1.0,
expansion.iterations=50,
expansion.temperature=2000,
expansion.attraction=2,
expansion.damping.mult=1.0,
cooldown.iterations=50,
cooldown.temperature=200,
cooldown.attraction=1,
cooldown.damping.mult=.1,
crunch.iterations=50,
crunch.temperature=250,
crunch.attraction=1,
crunch.damping.mult=0.25,
simmer.iterations=25,
simmer.temperature=250,
simmer.attraction=.5,
simmer.damping.mult=0)
#' @export
drl_defaults <- list(
coarsen = igraph.drl.coarsen,
coarsest = igraph.drl.coarsest,
default = igraph.drl.default,
final = igraph.drl.final,
refine = igraph.drl.refine
)
|