tests/testthat/test-solve_SARSOP.R

library("testthat")
library("pomdp")

skip_if_not_installed("sarsop")
## context("solve_SARSOP")

### In case sarsop is not installed correctly (taken from the example in ? pomdpsol)
if(sarsop::assert_has_appl()) {

  data("Tiger")
  sol_SARSOP <- solve_SARSOP(Tiger)
  sol_POMDP <- solve_POMDP(Tiger)
  
  # sort policy by first alpha vector
  normalize_policy <- function(x) {
    if(!is.data.frame(x)) x <- x[[1]]
    x <- x[order(x[,1]),]
    x
  }
  
  pol_SARSOP <- normalize_policy(policy(sol_SARSOP))
  pol_POMDP <- normalize_policy(policy(sol_POMDP))
  
  # check actions
  expect_identical(pol_SARSOP$action, pol_POMDP$action)
  
  # check alpha vectors
  expect_true(all((pol_SARSOP[,1:2] - pol_POMDP[,1:2]) < 1e-3))
}

Try the pomdp package in your browser

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

pomdp documentation built on Sept. 9, 2023, 1:07 a.m.