File: print.R

package info (click to toggle)
r-cran-igraph 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,044 kB
  • sloc: ansic: 204,981; cpp: 21,711; fortran: 4,090; yacc: 1,229; lex: 519; sh: 52; makefile: 8
file content (845 lines) | stat: -rw-r--r-- 26,152 bytes parent folder | download
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

## ----------------------------------------------------------------------
##
##   IGraph R package
##   Copyright (C) 2005-2014  Gabor Csardi <csardi.gabor@gmail.com>
##   334 Harvard street, Cambridge, MA 02139 USA
##
##   This program is free software; you can redistribute it and/or modify
##   it under the terms of the GNU General Public License as published by
##   the Free Software Foundation; either version 2 of the License, or
##   (at your option) any later version.
##
##   This program is distributed in the hope that it will be useful,
##   but WITHOUT ANY WARRANTY; without even the implied warranty of
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##   GNU General Public License for more details.
##
##   You should have received a copy of the GNU General Public License
##   along with this program; if not, write to the Free Software
##   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
##   02110-1301 USA
##
## ----------------------------------------------------------------------

###################################################################
# Convert graphs to human readable forms
###################################################################

.get.attr.codes <- function(object) {
  ga <- va <- ea <- ""
  gal <- graph_attr_names(object)
  if (length(gal) != 0) {
    ga <- paste(
      sep = "", gal, " (g/",
      .Call(R_igraph_get_attr_mode, object, 2L),
      ")"
    )
  }
  val <- vertex_attr_names(object)
  if (length(val) != 0) {
    va <- paste(
      sep = "", val, " (v/",
      .Call(R_igraph_get_attr_mode, object, 3L),
      ")"
    )
  }
  eal <- edge_attr_names(object)
  if (length(eal) != 0) {
    ea <- paste(
      sep = "", edge_attr_names(object), " (e/",
      .Call(R_igraph_get_attr_mode, object, 4L),
      ")"
    )
  }
  c(ga, va, ea)
}

.print.header <- function(object, id = igraph_opt("print.id")) {
  ensure_igraph(object)

  title <- paste0(
    "IGRAPH ",
    if (id) paste0(substr(graph_id(object), 1, 7), " "),
    c("U", "D")[is_directed(object) + 1],
    c("-", "N")[is_named(object) + 1],
    c("-", "W")[is_weighted(object) + 1],
    c("-", "B")[is_bipartite(object) + 1],
    " ",
    vcount(object),
    " ",
    ecount(object),
    " -- "
  )
  w <- getOption("width")
  if (nchar(title) < w && "name" %in% graph_attr_names(object)) {
    title <- substring(paste(sep = "", title, as.character(object$name)[1]), 1, w - 1)
  }
  cat(title, "\n", sep = "")

  atxt <- .get.attr.codes(object)
  atxt <- paste(atxt[atxt != ""], collapse = ", ")
  if (atxt != "") {
    atxt <- strwrap(paste(sep = "", "+ attr: ", atxt),
      prefix = "| ",
      initial = ""
    )
    cat(atxt, sep = "\n")
  }
  1 + if (length(atxt) == 1 && atxt == "") 0 else length(atxt)
}

#' @importFrom utils capture.output
.print.graph.attributes <- function(x, full, max.lines) {
  list <- graph_attr_names(x)
  if (length(list) != 0) {
    cat("+ graph attributes:\n")
    out <- capture.output({
      lapply(list, function(n) {
        cat(sep = "", "+ ", n, ":\n")
        indent_print(graph_attr(x, n), .indent = "  ")
      })
      invisible(NULL)
    })
    indent_print(out, sep = "\n", .indent = "| ", .printer = cat)
    length(out) + 1
  } else {
    0
  }
}

## IGRAPH U--- 10 10 -- Ring graph
## + attr: name (g/c), mutual (g/l), circular (g/l)
## + graph attributes:
## | + name:
## |   [1] "Ring graph"
## | + mutual:
## |   [1] FALSE
## | + circular=
## |   [1] TRUE
## | + layout =
## |            [,1]          [,2]
## |    [1,]  0.000000  0.000000e+00
## |    [2,]  1.000000  0.000000e+00
## |    [3,]  0.809017  5.877853e-01
## |    [4,]  0.309017  9.510565e-01
## |    [5,] -0.309017  9.510565e-01
## |    [6,] -0.809017  5.877853e-01
## |    [7,] -1.000000  1.224647e-16
## |    [8,] -0.809017 -5.877853e-01
## |    [9,] -0.309017 -9.510565e-01
## |   [10,]  0.309017 -9.510565e-01
## |   [11,]  0.809017 -5.877853e-01
## + edges:
##  [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 9--10 1--10

.print.vertex.attributes <- function(x, full, max.lines) {
  pf <- function(x) .print.vertex.attributes.old(x, full, max.lines)
  if (length(vertex_attr_names(x))) cat("+ vertex attributes:\n")
  indent_print(x, .indent = "| ", .printer = pf)
}

.print.vertex.attributes.old <- function(x, full, max.lines) {
  vc <- vcount(x)
  list <- vertex_attr_names(x)
  if (length(list) != 0) {
    mp <- getOption("max.print")
    options(max.print = 1000000000)
    if (vc <= mp) {
      omitted.vertices <- 0
      ind <- as.numeric(V(x))
    } else {
      omitted.vertices <- vc - mp
      ind <- seq(length.out = mp)
    }
    if (vc == 0 ||
      all(sapply(list, function(v) {
        is.numeric(vertex_attr(x, v)) ||
          is.character(vertex_attr(x, v)) ||
          is.logical(vertex_attr(x, v))
      }))) {
      ## create a table
      tab <- data.frame(v = paste(sep = "", "[", ind, "]"), row.names = "v")
      for (i in list) {
        tab[i] <- vertex_attr(x, i, ind)
      }
      print(tab)
    } else {
      for (i in ind) {
        cat(sep = "", "[[", i, "]]\n")
        lapply(list, function(n) {
          cat(sep = "", "[[", i, "]][[", n, "]]\n")
          print(vertex_attr(x, n, i))
        })
      }
    }
    options(max.print = mp)
    if (omitted.vertices != 0) {
      cat(paste(
        '[ reached getOption("max.print") -- omitted',
        omitted.vertices, "vertices ]\n\n"
      ))
    }
  }
}

.print.edges.edgelist <- function(x, edges = E(x), names) {
  ec <- length(edges)
  list <- edge_attr_names(x)
  list <- list[list != "name"]
  arrow <- ifelse(is_directed(x), "->", "--")
  if (is_named(x)) {
    cat("+ edges (vertex names) and their attributes:\n")
  } else {
    cat("+ edges and their attributes:\n")
  }
  if (names && !"name" %in% vertex_attr_names(x)) {
    names <- FALSE
  }
  if (names && "name" %in% vertex_attr_names(x) &&
    !is.numeric(vertex_attr(x, "name")) &&
    !is.character(vertex_attr(x, "name")) &&
    !is.logical(vertex_attr(x, "name"))) {
    cli::cli_warn("Can't print vertex names, complex {.val name} vertex attribute.")
    names <- FALSE
  }

  mp <- getOption("max.print")
  if (mp >= ec) {
    omitted.edges <- 0
    el <- ends(x, edges, names = names)
  } else {
    omitted.edges <- ec - mp
    el <- ends(x, ends[seq_len(mp)])
    if (names) {
      el[] <- V(x)$name[el]
    }
  }
  ename <- if ("name" %in% edge_attr_names(x)) {
    paste(sep = "", "'", E(x)$name, "'")
  } else {
    seq(length.out = nrow(el))
  }
  if (ec == 0 ||
    all(sapply(list, function(v) {
      is.numeric(edge_attr(x, v)) |
        is.character(edge_attr(x, v)) |
        is.logical(edge_attr(x, v))
    }))) {
    ## create a table
    tab <- data.frame(row.names = paste(sep = "", "[", ename, "]"))
    if (is.numeric(el)) {
      w <- nchar(max(el))
    } else {
      w <- max(nchar(el))
    }
    tab["edge"] <- paste(
      sep = "", format(el[, 1], width = w),
      arrow, format(el[, 2], width = w)
    )
    for (i in list) {
      tab[i] <- edge_attr(x, i)
    }
    print(tab)
  } else {
    i <- 1
    apply(el, 1, function(v) {
      cat(sep = "", "[", ename[i], "] ", v[1], " ", arrow, " ", v[2])
      lapply(list, function(n) {
        cat(sep = "", "\n[[", i, "]][[", n, "]]\n")
        print(edge_attr(x, n, i))
      })
      cat("\n")
      i <<- i + 1
    })
  }
  if (omitted.edges != 0) {
    cat(paste(
      '[ reached getOption("max.print") -- omitted', omitted.edges,
      "edges ]\n\n"
    ))
  }
}

.print.edges.compressed <- function(x,
                                    edges = E(x),
                                    names,
                                    num = FALSE,
                                    max.lines = igraph_opt("auto.print.lines"),
                                    id = igraph_opt("print.id")) {
  len <- length(edges)
  gid <- graph_id(edges)

  title <- "+" %+%
    (if (num) {
      " " %+% chr(len) %+% "/" %+%
        (if (is.null(x)) "?" else chr(gsize(x)))
    } else {
      ""
    }) %+%
    (if (len == 1) " edge" else " edges") %+%
    (if (isTRUE(id) && !is.na(gid)) paste(" from", substr(gid, 1, 7)) else "") %+%
    (if (is.null(x)) " (deleted)" else "") %+%
    (if (is.null(attr(edges, "vnames"))) "" else " (vertex names)") %+%
    ":\n"
  cat(title)

  if (is_single_index(edges) && !is.null(x)) {
    ## Double bracket
    ea <- edge_attr(x)
    if (all(sapply(ea, is.atomic))) {
      etail <- tail_of(x, edges)
      ehead <- head_of(x, edges)
      df <- data.frame(
        stringsAsFactors = FALSE,
        tail = as_ids(etail),
        head = as_ids(ehead),
        tid = as.vector(etail),
        hid = as.vector(ehead)
      )
      if (length(ea)) {
        ea <- do_call(data.frame, .args = ea, stringsAsFactors = FALSE)
        df <- cbind(df, ea[as.vector(edges), , drop = FALSE])
      }
      print(df)
    } else {
      print(lapply(ea, "[", as.vector(edges)))
    }
  } else if (is.null(max.lines)) {
    .print.edges.compressed.all(x, edges, names)
  } else {
    .print.edges.compressed.limit(x, edges, names, max.lines)
  }
}

.print.edges.compressed.all <- function(x, edges, names) {
  if (!is.null(x)) {
    arrow <- c("--", "->")[is_directed(x) + 1]

    el <- ends(x, edges, names = names)
    pr <- paste(sep = "", format(el[, 1]), arrow, format(el[, 2]))
    print(pr, quote = FALSE)
  } else {
    if (!is.null(attr(edges, "vnames"))) {
      print(as.vector(attr(edges, "vnames")), quote = FALSE)
    } else if (!is.null(names(edges))) {
      print(names(edges), quote = FALSE)
    } else {
      print(as.vector(edges))
    }
  }
}

#' @importFrom utils capture.output
.print.edges.compressed.limit <- function(x, edges, names, max.lines) {
  if (!is.null(x)) {
    arrow <- c("--", "->")[is_directed(x) + 1]

    can_max <- NA
    el <- NA

    fun <- function(q, no) {
      if (q == "length") {
        length(edges)
      } else if (q == "min_width") {
        5
      } else if (q == "width") {
        el <<- ends(x, edges[seq_len(no)], names = names)
        cummax(nchar(el[, 1])) + nchar(arrow) + cummax(nchar(el[, 2])) + 1
      } else if (q == "print") {
        el <<- el[seq_len(no), , drop = FALSE]
        out <- paste(sep = "", format(el[, 1]), arrow, format(el[, 2]))
        capture.output(print(out, quote = FALSE))
      } else if (q == "max") {
        can_max <<- no
      } else if (q == "done") {
        if (no["tried_items"] < length(edges) ||
          no["printed_lines"] < no["tried_lines"]) {
          cat("+ ... omitted several edges\n")
        }
      }
    }

    fun <- printer_callback(fun)
    head_print(fun, max_lines = max.lines)
  } else {
    if (!is.null(attr(edges, "vnames"))) {
      head_print(as.vector(attr(edges, "vnames")), quote = FALSE)
    } else if (!is.null(names(edges))) {
      head_print(names(edges), quote = FALSE)
    } else {
      head_print(as.vector(edges))
    }
  }
}

.print.edges.adjlist <- function(x) {
  ## TODO: getOption("max.print")
  cat("+ edges:\n")
  vc <- vcount(x)
  arrow <- c(" -- ", " -> ")[is_directed(x) + 1]
  al <- as_adj_list(x, mode = "out")
  w <- nchar(max(which(degree(x, mode = "in") != 0)))
  mpl <- trunc((getOption("width") - nchar(arrow) - nchar(vc)) / (w + 1))
  if (any(sapply(al, length) > mpl)) {
    ## Wrapping needed
    mw <- nchar(vcount(x))
    sm <- paste(collapse = "", rep(" ", mw + 4))
    alstr <- lapply(seq_along(al), function(x) {
      len <- length(al[[x]])
      fac <- rep(1:(len / mpl + 1), each = mpl, length.out = len)
      nei <- tapply(format(al[[x]], width = mw), fac, paste, collapse = " ")
      mark <- paste(sep = "", format(x, width = mw), arrow)
      mark <- c(mark, rep(sm, max(0, length(nei) - 1)))
      paste(sep = "", mark, nei)
    })
    cat(unlist(alstr), sep = "\n")
  } else {
    alstr <- sapply(al, function(x) {
      paste(format(x, width = w), collapse = " ")
    })
    mark <- paste(sep = "", format(seq_len(vc)), arrow)
    alstr <- paste(sep = "", mark, alstr)
    maxw <- max(nchar(alstr))
    sep <- "   "
    ncol <- trunc((getOption("width") - 1 + nchar(sep)) / (maxw + nchar(sep)))
    if (ncol > 1) {
      alstr <- format(alstr, width = maxw, justify = "left")
      fac <- rep(1:(vc / ncol + 1), each = ncol, length.out = vc)
      alstr <- tapply(alstr, fac, paste, collapse = sep)
    }
    cat(alstr, sep = "\n")
  }
}

.print.edges.adjlist.named <- function(x, edges = E(x)) {
  ## TODO getOption("max.print")
  cat("+ edges (vertex names):\n")

  arrow <- c(" -- ", " -> ")[is_directed(x) + 1]
  vn <- V(x)$name

  al <- as_adj_list(x, mode = "out")
  alstr <- sapply(al, function(x) {
    paste(collapse = ", ", vn[x])
  })
  alstr <- paste(sep = "", format(vn), arrow, alstr)
  alstr <- strwrap(alstr, exdent = max(nchar(vn)) + nchar(arrow))
  cat(alstr, sep = "\n")
}

#' @family print
#' @export
print_all <- function(object, ...) {
  print.igraph(object, full = TRUE, ...)
}



#' Print graphs to the terminal
#'
#' These functions attempt to print a graph to the terminal in a human readable
#' form.
#'
#' `summary.igraph` prints the number of vertices, edges and whether the
#' graph is directed.
#'
#' `print_all()` prints the same information, and also lists the edges, and
#' optionally graph, vertex and/or edge attributes.
#'
#' `print.igraph()` behaves either as `summary.igraph` or
#' `print_all()` depending on the `full` argument. See also the
#' \sQuote{print.full} igraph option and [igraph_opt()].
#'
#' The graph summary printed by `summary.igraph` (and `print.igraph()`
#' and `print_all()`) consists of one or more lines. The first line contains
#' the basic properties of the graph, and the rest contains its attributes.
#' Here is an example, a small star graph with weighted directed edges and named
#' vertices: \preformatted{    IGRAPH badcafe DNW- 10 9 -- In-star
#'     + attr: name (g/c), mode (g/c), center (g/n), name (v/c),
#'       weight (e/n) }
#' The first line always
#' starts with `IGRAPH`, showing you that the object is an igraph graph.
#' Then a seven character code is printed, this the first seven characters
#' of the unique id of the graph. See [graph_id()] for more.
#' Then a four letter long code string is printed. The first letter
#' distinguishes between directed (\sQuote{`D`}) and undirected
#' (\sQuote{`U`}) graphs. The second letter is \sQuote{`N`} for named
#' graphs, i.e. graphs with the `name` vertex attribute set. The third
#' letter is \sQuote{`W`} for weighted graphs, i.e. graphs with the
#' `weight` edge attribute set. The fourth letter is \sQuote{`B`} for
#' bipartite graphs, i.e. for graphs with the `type` vertex attribute set.
#'
#' This is followed by the number of vertices and edges, then two dashes.
#'
#' Finally, after two dashes, the name of the graph is printed, if it has one,
#' i.e. if the `name` graph attribute is set.
#'
#' From the second line, the attributes of the graph are listed, separated by a
#' comma. After the attribute names, the kind of the attribute -- graph
#' (\sQuote{`g`}), vertex (\sQuote{`v`}) or edge (\sQuote{`e`})
#' -- is denoted, and the type of the attribute as well, character
#' (\sQuote{`c`}), numeric (\sQuote{`n`}), logical
#' (\sQuote{`l`}), or other (\sQuote{`x`}).
#'
#' As of igraph 0.4 `print_all()` and `print.igraph()` use the
#' `max.print` option, see [base::options()] for details.
#'
#' As of igraph 1.1.1, the `str.igraph` function is defunct, use
#' `print_all()`.
#'
#' @aliases print.igraph print_all summary.igraph str.igraph
#' @param x The graph to print.
#' @param full Logical scalar, whether to print the graph structure itself as
#'   well.
#' @param graph.attributes Logical constant, whether to print graph attributes.
#' @param vertex.attributes Logical constant, whether to print vertex
#'   attributes.
#' @param edge.attributes Logical constant, whether to print edge attributes.
#' @param names Logical constant, whether to print symbolic vertex names (i.e.
#'   the `name` vertex attribute) or vertex ids.
#' @param max.lines The maximum number of lines to use. The rest of the
#'   output will be truncated.
#' @param id Whether to print the graph ID.
#' @param object The graph of which the summary will be printed.
#' @param \dots Additional agruments.
#' @return All these functions return the graph invisibly.
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @export
#' @method print igraph
#' @rawNamespace export(print.igraph)
#' @family print
#' @keywords graphs
#' @examples
#'
#' g <- make_ring(10)
#' g
#' summary(g)
#'
print.igraph <- function(x, full = igraph_opt("print.full"),
                         graph.attributes = igraph_opt("print.graph.attributes"),
                         vertex.attributes = igraph_opt("print.vertex.attributes"),
                         edge.attributes = igraph_opt("print.edge.attributes"),
                         names = TRUE, max.lines = igraph_opt("auto.print.lines"),
                         id = igraph_opt("print.id"),
                         ...) {
  ensure_igraph(x)

  head_lines <- .print.header(x, id)
  if (is.logical(full) && full) {
    if (graph.attributes) {
      head_lines <- head_lines + .print.graph.attributes(x, full, max.lines)
    }
    if (vertex.attributes) {
      head_lines <- head_lines + .print.vertex.attributes(x, full, max.lines)
    }
    if (ecount(x) == 0) {
      ## Do nothing
    } else if (edge.attributes && length(edge_attr_names(x)) != 0) {
      .print.edges.edgelist(x, names = names)
    } else if (median(degree(x, mode = "out")) < 3) {
      .print.edges.compressed(x, names = names, max.lines = NULL, id = id)
    } else if (is_named(x)) {
      .print.edges.adjlist.named(x)
    } else {
      .print.edges.adjlist(x)
    }
  } else if (full == "auto") {
    .print.edges.compressed(
      x,
      names = names,
      max.lines = max(0, max.lines - head_lines),
      id = id
    )
  }

  invisible(x)
}

#' @rdname print.igraph
#' @method summary igraph
#' @family print
#' @export
summary.igraph <- function(object, ...) {
  .print.header(object)
  invisible(object)
}

"
####################################################################
## Various designs for printing graphs

## Summary

IGRAPH UNW- 5 5 -- A ring
Attr: name (g/c), name (v/c), weight (e/n)

IGRAPH D-W- 100 200 -- Gnm random graph

## Printing, edge list

IGRAPH-UNW--V5-E5----------------------------------------- A ring -
+ attributes: name (g), name (v), weight (e).
+ edges:
     edge  weight
[1]' a--b       1
[2]' b--c       2
[3]' c--d      -1
[4]' d--e     0.5
[5]' a--e       1

## Compressed edge list

IGRAPH UNW- 5 10 -- A ring
+ attributes: name (g/c), name (v/n), weight (e/n)
+ edges:
[1]' 1--2 2--3 3--4 4--5 1--5 2--5 5--1
[8]' 1--4 4--2 1--3

## This is good if vertices are named

IGRAPH UNW- 10 18 -- Krackhardt kite
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
Andre    -- [1] Beverly, Carol, Diane, Fernando
Beverly  -- [1] Andre, Diane, Ed, Garth
Carol    -- [1] Andre, Diane, Fernando
Diane    -- [1] Andre, Beverly, Carol, Diane, Ed
         -- [6] Garth
Ed       -- [1] Beverly, Diane, Garth
Fernando -- [1] Andre, Carol, Diane, Garth
Garth    -- [1] Beverly, Diane, Ed, Fernando
Heather  -- [1] Fernando, Garth
Ike      -- [1] Heather, Jane
Jane     -- [1] Ike

IGRAPH UNW- 10 18 -- Krackhardt kite
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
Andre    -- Beverly, Carol, Diane, Fernando
Beverly  -- Andre, Diane, Ed, Garth
Carol    -- Andre, Diane, Fernando
Diane    -- Andre, Beverly, Carol, Diane, Ed, Garth
Ed       -- Beverly, Diane, Garth
Fernando -- Andre, Carol, Diane, Garth
Garth    -- Beverly, Diane, Ed, Fernando
Heather  -- Fernando, Garth
Ike      -- Heather, Jane
Jane     -- Ike

## This is the good one if vertices are not named

IGRAPH U--- 100 200 -- Gnm random graph
+ edges:
[  1] 28 46 89 90                 [  2] 47 69 72 89
[  3] 29                          [  4] 17 20
[  5] 11 40 42 51 78 89           [  6] 27 32 70 87 93
[  7] 18 27 87                    [  8] 18 24 82
[  9] 18 20 85 94                 [ 10] 24 70 77 91
[ 11]  5 12 34 61 62              [ 12] 11 41 44 61 65 80
...

## Alternative designs, summary

IGRAPH-UNW--V5-E5,---------------------------------------- A ring -
+ attributes: name (g/c), name (v/c), weight (e/n)

IGRAPH. |V|=5, |E|=5, undirected, named, weighted.
Attributes: name (g/c), name (v/c), weight (e/n)

IGRAPH: 'A ring'
Graph attributes: |V|=5, |E|=5, undirected, name.
Vertex attributes: name.
Edge attributes: weight.

## Alternative designs, printing

IGRAPH-UNW--V5-E5----------------------------------------- A ring -
'- attributes: name (g), name (v), weight (e).
'         edge  weight
[1] 'a' -- 'b'       1
[2] 'b' -- 'c'       2
[3] 'c' -- 'd'      -1
[4] 'd' -- 'e'     0.5
[5] 'a' -- 'e'       1

IGRAPH-UNW--V-5-E-10-------------------------------------- A ring -
|- attributes: name (g), name (v), weight (e).
|- edges:
[1] 'a'--'b'  'b'--'c'  'c'--'d'  'd'--'e'  'a'--'e'  'b'-'e'
[7] 'e'--'a'  'a'--'d'  'd'--'b'  'a'--'c'


IGRAPH-UNW--V-5-E-10-------------------------------------- A ring -
+ attributes: name (g), name (v), weight (e).
+ vertices:
|     name
| [1]    a
| [2]    b
| [3]    c
| [4]    d
| [5]    e
+ edges:
[1] 'a'--'b'  'b'--'c'  'c'--'d'  'd'--'e'  'a'--'e'  'b'-'e'
[7] 'e'--'a'  'a'--'d'  'd'--'b'  'a'--'c'




IGRAPH-UNW--V-5-E-10-------------------------------------- A ring -
+ graph attributes: name
+ vertex attributes: name
+ edge attributes: weight
+ vertices:
|   name
|1]    a
|2]    b
|3]    c
|4]    d
|5]    e
+ edges:
|1] a--b  b--c  c--d  d--e  a--e  b-e
|7] e--a  a--d  d--b  a--c



IGRAPH-UNW--V-5-E-10-------------------------------------- A ring -
+ graph attributes:  name (c)
+ vertex attributes: name (c)
+ edge attributes:   weight (n)
+ edges:
[1] a--b  b--c  c--d  d--e  a--e  b-e
[7] e--a  a--d  d--b  a--c


IGRAPH-UNW--V-5-E-10-------------------------------------- A ring -
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[ 1] a--b b--c c--d d--e a--e b--e e--a a--d d--b
[10] a--c

IGRAPH-DNW--V-5-E-10-------------------------------------- A ring -
+ attributes: name (g/c), name (v/n), weight (e/n)
+ edges:
[1]' 1->2 2->3 3->4 4->5 1->5 2->5 5->1
[8]' 1->4 4->2 1->3


IGRAPH-UNW--V-5-E-20-------------------------------------- A ring -
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[ 1] a-b b-c c-d d-e a-e b-e e-a a-d d-b a-c
[11] a-b b-c c-d d-e a-e b-e e-a a-d d-b a-c


IGRAPH-UNW--V-8-E-10-------------------------------------- A ring -
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[a] b c e f h
[b] a c e
[c] a b d
[d] a b c h
[e] a b d
[f] a
[g]
[h] a d

IGRAPH-UNW--V-10-E-18------------------------------------- A ring -
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[a] a--{b,c,e,f,h}  b--{a,c,e}  c--{a,b,d}  d--{a,b,c,h}
[e] e--{a,b,d}      f--{a}      g--{}       h--{a,d}


IGRAPH-UNW--V10-E18------------------------------Krackhardt kite--
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[   Andre][1] Beverly  Carol    Diane    Fernando
[ Beverly][1] Andre    Diane    Ed       Garth
[   Carol][1] Andre    Diane    Fernando
[   Diane][1] Andre    Beverly  Carol    Diane    Ed
[   Diane][6] Garth
[      Ed][1] Beverly  Diane    Garth
[Fernando][1] Andre    Carol    Diane    Garth
[   Garth][1] Beverly  Diane    Ed       Fernando
[ Heather][1] Fernando Garth
[     Ike][1] Heather  Jane
[    Jane][1] Ike

IGRAPH-UNW--V10-E18-------------------------------Krackhardt kite--
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[   Andre][1] Beverly/1  Carol/3    Diane/3    Fernando/1
[ Beverly][1] Andre/1    Diane/1    Ed/2       Garth/2
[   Carol][1] Andre/2    Diane/2    Fernando/1
[   Diane][1] Andre/5    Beverly/1  Carol/0.4  Diane/2
[   Diane][5] Ed/1.5     Garth/2.5
[      Ed][1] Beverly/-1 Diane/1.5  Garth/2
[Fernando][1] Andre/1    Carol/2    Diane/1    Garth/1
[   Garth][1] Beverly/2  Diane/3    Ed/1       Fernando/-1
[ Heather][1] Fernando/3 Garth/1
[     Ike][1] Heather/1  Jane/-1
[    Jane][1] Ike/-2


IGRAPH-UNW--V10-E18-------------------------------Krackhardt kite--
+ attributes: name (g/c), name (v/c), weight (e/n)
+ edges:
[   Andre][1] Beverly (1)  Carol (3)    Diane (3)    Fernando (1)
[ Beverly][1] Andre (1)    Diane (1)    Ed (2)       Garth (2)
[   Carol][1] Andre (2)    Diane (2)    Fernando (1)
[   Diane][1] Andre (5)    Beverly (1)  Carol (0.5)  Diane (2)
[   Diane][5] Ed (1.5)     Garth (2.5)
[      Ed][1] Beverly (-1) Diane (1.5)  Garth (2)
[Fernando][1] Andre (1)    Carol (2)    Diane (1)    Garth (1)
[   Garth][1] Beverly (2)  Diane (3)    Ed (1)       Fernando (-1)
[ Heather][1] Fernando (3) Garth (1)
[     Ike][1] Heather (1)  Jane (-1)
[    Jane][1] Ike (-2)

IGRAPH UNW- V10 E18 -- Krackhardt kite
+ attr: name (g/c), name (v/c), weight (e/n)
+ edges:
[   Andre][1] Beverly (1)  Carol (3)    Diane (3)    Fernando (1)
[ Beverly][1] Andre (1)    Diane (1)    Ed (2)       Garth (2)
[   Carol][1] Andre (2)    Diane (2)    Fernando (1)
[   Diane][1] Andre (5)    Beverly (1)  Carol (0.5)  Diane (2)
[   Diane][5] Ed (1.5)     Garth (2.5)
[      Ed][1] Beverly (-1) Diane (1.5)  Garth (2)
[Fernando][1] Andre (1)    Carol (2)    Diane (1)    Garth (1)
[   Garth][1] Beverly (2)  Diane (3)    Ed (1)       Fernando (-1)
[ Heather][1] Fernando (3) Garth (1)
[     Ike][1] Heather (1)  Jane (-1)
[    Jane][1] Ike (-2)



IGRAPH-U----V100-E200----------------------------Gnm random graph--
+ edges:
[  1] 28 46 89 90
[  2] 47 69 72 89
[  3] 29
[  4] 17 20
[  5] 11 40 42 51 78 89
[  6] 27 32 70 87 93
[  7] 18 27 87
[  8] 18 24 82
[  9] 18 20 85 94
[ 10] 24 70 77 91
[ 11]  5 12 34 61 62
[ 12] 11 41 44 61 65 80
...

IGRAPH-U----100-200------------------------------Gnm random graph--
+ edges:
[  1] 28 46 89 90                 [  2] 47 69 72 89
[  3] 29                          [  4] 17 20
[  5] 11 40 42 51 78 89           [  6] 27 32 70 87 93
[  7] 18 27 87                    [  8] 18 24 82
[  9] 18 20 85 94                 [ 10] 24 70 77 91
[ 11]  5 12 34 61 62              [ 12] 11 41 44 61 65 80
...



"