tests/testthat/test-graph.maxflow.R

test_that("max_flow works", {
  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))
})

Try the igraph package in your browser

Any scripts or data that you put into this service are public.

igraph documentation built on Aug. 10, 2023, 9:08 a.m.