File: test_graph.maxflow.R

package info (click to toggle)
r-cran-igraph 1.0.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,232 kB
  • sloc: ansic: 173,538; cpp: 19,365; fortran: 4,550; yacc: 1,164; tcl: 931; lex: 484; makefile: 149; sh: 9
file content (15 lines) | stat: -rw-r--r-- 547 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

context("max_flow")

test_that("max_flow works", {
  library(igraph)
  E <- rbind( c(1,3,3), c(3,4,1), c(4,2,2), c(1,5,1), c(5,6,2), c(6,2,10))
  colnames(E) <- c("from", "to", "capacity")
  g1 <- graph_from_data_frame(as.data.frame(E))
  fl <- max_flow(g1, source="1", target="2")
  expect_that(fl$value, equals(2))
  expect_that(as.vector(fl$flow), equals(rep(1, 6)))
  expect_that(sort(as.vector(fl$cut)), equals(c(2,4)))
  expect_that(sort(as.vector(fl$partition1)), equals(1:2))
  expect_that(sort(as.vector(fl$partition2)), equals(3:6))
})