# List of matrices
costs <- list(
matrix(c(1, 2, 3, 4), 2, 2),
matrix(c(5, 6, 7, 8), 2, 2)
)
lap_solve_batch(costs)
# 3D array
arr <- array(runif(2 * 2 * 10), dim = c(2, 2, 10))
lap_solve_batch(arr)
# Grouped data frame
library(dplyr)
df <- tibble(
sim = rep(1:5, each = 9),
source = rep(1:3, times = 15),
target = rep(1:3, each = 3, times = 5),
cost = runif(45, 1, 10)
)
df |> group_by(sim) |> lap_solve_batch(source, target, cost)
# Parallel execution (requires n_threads > 1)
lap_solve_batch(costs, n_threads = 2)
Run the code above in your browser using DataLab