Skip to contents

Reads and writes a POMDP file suitable for the pomdp-solve program.

Usage

write_POMDP(x, file, digits = 7, labels = FALSE)

read_POMDP(file, parse = TRUE, normalize = FALSE, verbose = FALSE)

Arguments

x

an object of class POMDP.

file

a file name. read_POMDP() also accepts connections including URLs.

digits

precision for writing numbers (digits after the decimal point).

labels

logical; write original labels or use index numbers? Labels are restricted to [a-zA-Z0-9_-] and the first character has to be a letter.

parse

logical; try to parse the model matrices. Solvers still work with unparsed matrices, but helpers for simulation are not available.

normalize

logical; should the description be normalized for faster access (see normalize_POMDP())?

verbose

logical; report parsed lines. This is useful for debugging a POMDP file.

Value

read_POMDP() returns a POMDP object.

Details

POMDP objects read from a POMDP file have an extra element called problem which contains the original POMDP specification. The original specification is directly used by external solvers. In addition, the file is parsed using an experimental POMDP file parser. The parsed information can be used with auxiliary functions in this package that use fields like the transition matrix, the observation matrix and the reward structure.

The range of useful rewards is restricted by the solver. Here the values are restricted to the range [-1e10, 1e10]. Unavailable actions have a reward of -Inf which is translated to -2 times the maximum absolute reward value used in the model.

Notes: The parser for POMDP files is experimental. Please report problems here: https://github.com/mhahsler/pomdp/issues.

References

POMDP solver website: https://www.pomdp.org

Author

Hossein Kamalzadeh, Michael Hahsler

Examples

data(Tiger)

## show the POMDP file that would be written.
write_POMDP(Tiger, file = stdout())
#> # POMDP File: Tiger Problem
#> # Produced with R package pomdp (created: Sun Oct  4 17:05:42 2026)
#> 
#> discount: 0.75
#> values: reward
#> states: 2
#> actions: 3
#> observations: 2
#>  
#> start: uniform
#>  
#> T: 0
#> identity
#> 
#> T: 1
#> uniform
#> 
#> T: 2
#> uniform
#> 
#> O: 0
#> 0.8500000 0.1500000
#> 0.1500000 0.8500000
#> 
#> O: 1
#> uniform
#> 
#> O: 2
#> uniform
#> 
#> R: 0 : * : * : * -1.0000000
#> R: 1 : 0 : * : * -100.0000000
#> R: 1 : 1 : * : * 10.0000000
#> R: 2 : 0 : * : * 10.0000000
#> R: 2 : 1 : * : * -100.0000000