Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @licioromao 's changes to read more POMDPFIle formats #19

Open
wants to merge 145 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
16f465c
Adding the reading function of the initial distribution
licioromao Jan 25, 2024
3baebb6
Adding the functionality to read initial distributions
licioromao Jan 25, 2024
88ebad8
Merge branch 'master' of github.com:licioromao/POMDPFiles.jl
licioromao Jan 26, 2024
afc2db3
start incorporating the changes
licioromao Feb 5, 2024
d44ba94
Fixing the InitialStateParam structure
licioromao Feb 5, 2024
d8e00de
I have checked the preamble and initial distroibution parser in sever…
licioromao Feb 6, 2024
9650eb1
Making progress on the parser. I have implemented reading some lines …
licioromao Feb 7, 2024
71b54f3
Adding one more feature to the transition matrix
licioromao Feb 7, 2024
eea21f7
Making progress on transition probability parsing
licioromao Feb 7, 2024
e5ab4d4
Modifying the preamble parsing
licioromao Feb 7, 2024
dfa0425
The preamble and transition test are passing in all examples I have s…
licioromao Feb 7, 2024
1be8d3d
Making progress on the observation function
licioromao Feb 8, 2024
845e424
Adding some testing examples
licioromao Feb 8, 2024
88ead38
Making progress on parsing transition and observation probability
licioromao Feb 8, 2024
8e64845
I am almost done with transition probability and observation
licioromao Feb 8, 2024
3c2bd38
Finished transition parsing. Need to modify a few things in the obser…
licioromao Feb 9, 2024
0a1b257
Almost done with observation
licioromao Feb 9, 2024
c632d1c
First draft of transition and observability parsing
licioromao Feb 9, 2024
0b1366a
Final draft of the parser
licioromao Feb 10, 2024
9179bed
Small changes in the files. Need to work on observation and implement…
licioromao Feb 12, 2024
a6de9a4
Making changes on the transition data structure
licioromao Feb 14, 2024
868fea6
Fixing the transition probability function to allow for memory savings
licioromao Feb 14, 2024
4c7401a
Romeo left some comments to define the types. Have a look at it.
licioromao Feb 14, 2024
4f4ea4e
Starting changing the observasion parsing with the saving memory feature
licioromao Feb 14, 2024
f42a7c0
Finishing with parsing the observation
licioromao Feb 14, 2024
351d332
Finished writing the observation parsing with the new data structure
licioromao Feb 15, 2024
277da57
Finished with the reward function
licioromao Feb 15, 2024
e8fad59
Writing the POMDP file
licioromao Feb 15, 2024
51e4c3d
A first version of the parser is complete. I am now working on genera…
licioromao Feb 16, 2024
b39df2f
I will start simplifying the code
licioromao Feb 16, 2024
a365b13
Trying to simplify the code. Working on preamble
licioromao Feb 17, 2024
bb2ed01
Revising code to decrease its size. Done until the beginning of trans…
licioromao Feb 17, 2024
c9c151b
Need to work on reducing the size of the transition, obs, and value p…
licioromao Feb 17, 2024
41b24d7
Implementing the POMDP structure for the output of read_pomdp
licioromao Feb 18, 2024
50254ab
Parser working with all files
licioromao Feb 20, 2024
7a9fff1
Parser working with all files
licioromao Feb 20, 2024
528283d
Simplifying the transition probability function
licioromao Feb 21, 2024
2d4c4e0
Finishing restructuring the transition probability function
licioromao Feb 21, 2024
39d24fc
modifying .gitignore
licioromao Feb 23, 2024
a79cc98
modifying .gitignore
licioromao Feb 23, 2024
e2fe4a2
modifying .gitignore
licioromao Feb 23, 2024
3482d6b
modifying .gitignore
licioromao Feb 23, 2024
5e05ed0
modifying .gitignore
licioromao Feb 23, 2024
f05577f
Fisrt part of observation
licioromao Feb 23, 2024
2470a26
Parsing line equal 4
licioromao Feb 23, 2024
d3b0a75
Finished simplyfying the obs transition
licioromao Feb 24, 2024
26ce904
Fixing some typos in the variable names
licioromao Feb 24, 2024
739a24a
Need to further simplify the transition parsing. Started creating som…
licioromao Feb 24, 2024
51661b5
Need to further simplify the transition parsing. Started creating som…
licioromao Feb 24, 2024
a72741e
Finishing the data structure used to simplify the transition parsing
licioromao Feb 24, 2024
821ab15
Finished simplifying code of transition functions
licioromao Feb 25, 2024
6e9e0da
Finished simplifying code of transition functions
licioromao Feb 25, 2024
96d970f
This version of the code is running the solvers
licioromao Feb 25, 2024
033f928
This version of the code is running the solvers
licioromao Feb 25, 2024
e2e2fbb
Comments after meeting with Robert
licioromao Feb 27, 2024
aa24a8c
Defining types within POMDPFiles.jl
licioromao Mar 6, 2024
6d3feb0
Defining types within POMDPFiles.jl
licioromao Mar 6, 2024
158234a
Moved types within POMDPFiles.jl
licioromao Mar 6, 2024
de6aeeb
Moved types within POMDPFiles.jl
licioromao Mar 6, 2024
2eb7426
Some progress on feedback control
licioromao Mar 6, 2024
662668f
Fixing some bugs in the initial condition
licioromao Mar 8, 2024
b849bc4
Fixing some bugs in the initial condition
licioromao Mar 8, 2024
18f6e98
Fixing some bugs in the initial condition
licioromao Mar 8, 2024
4aee918
Creating the ValueType to simplifying transition parsing
licioromao Mar 8, 2024
737b7c6
First version of package
licioromao Mar 9, 2024
8a493db
First draft of parser
licioromao Mar 9, 2024
4e820bf
First version of parser
licioromao Mar 9, 2024
7e00140
Merge branch 'master' into master
licioromao Mar 9, 2024
2b22e2a
First version of parser
licioromao Mar 9, 2024
572ce69
Fixing test errors
licioromao Mar 9, 2024
246e94a
Cleaning up repo
licioromao Mar 9, 2024
b5a6fc4
Cleaning up repo
licioromao Mar 9, 2024
693bea0
Trying to create a test set
licioromao Mar 19, 2024
5aad149
Saving before introducing wild cards
licioromao Mar 29, 2024
2812675
Start simplifying the way I am processing the preamble
licioromao Mar 29, 2024
2e30401
fixing initial condition
licioromao Mar 29, 2024
3e57ff8
All tests seem to be ok now
licioromao Mar 29, 2024
6d64874
Fixing the tests
licioromao Mar 30, 2024
989dabd
Progress on setting up the tests.
licioromao Mar 30, 2024
1fb22eb
Progress on setting up the tests.
licioromao Mar 30, 2024
91b094c
progress on tests
licioromao Mar 30, 2024
be8394b
progress on tests
licioromao Mar 30, 2024
0b5bd20
progress on tests
licioromao Mar 30, 2024
ab47dc6
All tests are ok. I need to check the big ones
licioromao Mar 30, 2024
ef4044c
Cleaning up test folder
licioromao Mar 30, 2024
4755689
Cleaning up test folder
licioromao Mar 30, 2024
5344f42
All small POMDP tests are passing. I need to check the large ones
licioromao Mar 30, 2024
feb353f
Update CompatHelper.yml
licioromao Mar 31, 2024
5736fd1
All small POMDP tests are passing. I need to check the large ones
licioromao Mar 31, 2024
5fc4243
All small POMDP tests are passing. I need to check the large ones
licioromao Mar 31, 2024
0d151a7
Update CompatHelper.yml
licioromao Mar 31, 2024
37e27de
Update CI.yml
licioromao Mar 31, 2024
2bb08e7
Update CompatHelper.yml
licioromao Mar 31, 2024
adcc054
Update CI.yml
licioromao Mar 31, 2024
147e7c3
Update CI.yml
licioromao Mar 31, 2024
06e5e81
Update CI.yml
licioromao Mar 31, 2024
660bc06
Update CI.yml
licioromao Mar 31, 2024
9d88b05
Update CI.yml
licioromao Mar 31, 2024
53ffbf7
Update CI.yml
licioromao Mar 31, 2024
c273c0a
Update CI.yml
licioromao Mar 31, 2024
3fc7991
Update CI.yml
licioromao Mar 31, 2024
475a564
Update CI.yml
licioromao Mar 31, 2024
5009133
Update CI.yml
licioromao Mar 31, 2024
086f967
Update CI.yml
licioromao Mar 31, 2024
f599864
Update CI.yml
licioromao Mar 31, 2024
ff07781
Update README.md
licioromao Mar 31, 2024
3ff6e10
Update README.md
licioromao Mar 31, 2024
6b74b04
Update README.md
licioromao Mar 31, 2024
4017076
Update README.md
licioromao Mar 31, 2024
d3a4d7d
Working on the documentation
licioromao Mar 31, 2024
0252675
Updating README
licioromao Mar 31, 2024
36d3d16
Updating README
licioromao Mar 31, 2024
d39f287
Updating README
licioromao Mar 31, 2024
b4d7214
Updating README
licioromao Mar 31, 2024
67d9ede
Updating README
licioromao Mar 31, 2024
9e6ec7f
Updating README
licioromao Mar 31, 2024
ea185a9
Finished implementing new version of parse, without using OrderedDict
licioromao Apr 3, 2024
50014fe
Finished implementing new version of parse, without using OrderedDict
licioromao Apr 3, 2024
9b20a86
Finished implementing new version of parse, without using OrderedDict
licioromao Apr 3, 2024
4fad36a
Changing version in Project.toml
licioromao Apr 3, 2024
c2bbaac
Changing version in Project.toml
licioromao Apr 3, 2024
ea2eb7d
Changing version in Project.toml
licioromao Apr 3, 2024
0f03ed9
Update CI.yml
licioromao Apr 3, 2024
0917913
Update CI.yml
licioromao Apr 3, 2024
5ae4e1f
Update CI.yml
licioromao Apr 3, 2024
1ad9f48
Update CI.yml
licioromao Apr 3, 2024
cf18c85
Release of version 0.3.0
licioromao Apr 4, 2024
ad1ccea
Release of version 0.3.0
licioromao Apr 4, 2024
5bbe86c
Release of version 0.3.0
licioromao Apr 4, 2024
03f77b1
Release of version 0.3.0
licioromao Apr 4, 2024
122832e
Release version 0.3.0
licioromao Apr 5, 2024
d52fd7c
Release 0.3.0
licioromao Apr 5, 2024
a22acf8
Release 0.3.0
licioromao Apr 5, 2024
737083d
Release v0.3.0
licioromao Apr 5, 2024
3f69e01
Release v0.3.0
licioromao Apr 6, 2024
51cbefe
Release v0.3.0
licioromao Apr 6, 2024
dd951e3
Release v0.3.0
licioromao Apr 6, 2024
b60378a
Release v0.3.0
licioromao Apr 6, 2024
7b21ab2
Release v0.3.0
licioromao Apr 6, 2024
511fdbc
Release v0.3.0
licioromao Apr 6, 2024
92eefa0
Release v0.3.0
licioromao Apr 6, 2024
fb941ba
Release v0.3.0
licioromao Apr 6, 2024
6d67f48
Release v0.3.0
licioromao Apr 6, 2024
c5a42ed
Release v0.3.0
licioromao Apr 6, 2024
869e60f
Release v0.3.0
licioromao Apr 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: x64
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Adding WildcardArrays
run: |
julia --project -e 'using Pkg; Pkg.add(PackageSpec(url="[email protected]:licioromao/WildcardArrays.jl.git")); Pkg.instantiate()'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: actions/checkout@master
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v1
with:
file: ./lcov.info
flags: unittests
name: codecov-umbrella
name: codecov-umbrellav
2 changes: 2 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}


9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
Manifest.toml
Manifest.toml
scripts/


test/sources/txt-files/
test/sources/ejs/txt-files/
test/sources/cheng-examples/txt-files/
.*.swp
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
name = "POMDPFiles"
uuid = "9cf5b727-2e06-5671-8c87-8c6b0f729d5d"
repo = "https://github.com/JuliaPOMDP/POMDPFiles.jl"
version = "0.2.4"
version = "0.3.0"

[deps]
POMDPModels = "355abbd5-f08e-5560-ac9e-8b5f2592a0ca"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
POMDPTools = "7588e00f-9cae-40de-98dc-e0c70c48cdd7"
POMDPXFiles = "c6f6ee83-58c6-5336-a19f-2c76817e1af6"
POMDPs = "a93abf59-7444-517b-a68a-c42f96afdd7d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
WildcardArrays = "05d16eb0-506c-4fac-9187-f7ce7e253b09"

[compat]
POMDPTools = "0.1.4"
POMDPXFiles = "0.2"
POMDPs = "0.9"
Reexport = "0.2, 1"
julia = "1"
WildcardArrays = "0.1.0"
julia = "1.6"

[extras]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Downloads", "Test", "SHA"]
85 changes: 82 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,85 @@
# POMDPFiles
[![Build Status](https://github.com/licioromao/POMDPFiles.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/licioromao/POMDPFiles.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/licioromao/POMDPFiles.jl/branch/main/graph/badge.svg?token=btTBnBTQyw)](https://codecov.io/gh/licioromao/POMDPFiles.jl)

[![Build Status](https://github.com/JuliaPOMDP/POMDPFiles.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaPOMDP/POMDPFiles.jl/actions/workflows/CI.yml/)
[![codecov](https://codecov.io/gh/JuliaPOMDP/POMDPFiles.jl/branch/master/graph/badge.svg?token=6pQE1gHKIz)](https://codecov.io/gh/JuliaPOMDP/POMDPFiles.jl)
<!-- [![Build Status](https://github.com/licioromao/POMDPFiles.jl/actions/workflows/CI.yml/bagde.svg)](https://github.com/licioromao/POMDPFiles.jl/actions/workflows/CI.yml/) -->

Writes POMDP files (https://www.pomdp.org/code/pomdp-file-spec.html) for use in [POMDPSolve.jl](https://github.com/JuliaPOMDP/POMDPSolve.jl) from [POMDPs.jl models](https://github.com/JuliaPOMDP/POMDPs.jl).
This package constitutes the interface between the [POMDPs.jl](https://github.com/JuliaPOMDP/POMDPs.jl) package and the file format .pomdp defined in [POMDP.org](https://www.pomdp.org/code/pomdp-file-spec.html).

## Installation

Please use the following command to use this package
```julia
] add [email protected]:licioromao/POMDPFiles.jl.git
```
## API

```julia
WildcardArrayPOMDP(s::Int, a::Int, o::Int, initial_state::InitialStateParam, discount::Float64, T::WildcardArray{Float64, 3}, O::WildcardArray{Float64, 3}, R::WildcardArray{Float64, 4})

WildcardArrayPOMDP(filename::String)
```

Constructors for the `WilcardArrayPOMDP`. We allow the user to create this type either through a .POMDP file format or specifying manually the number of actions, initial distribution, and transitions using the type [WildcardArrays]([email protected]:sisl/WildcardArrays.jl.git). The API for the InitialStateParam is described below.

```julia
SWildcardArrayPOMDP(filename::String)

statenames(m::SWildcardArrayPOMDP)
actionnames(m::SWildcardArrayPOMDP)
obsnames(m::SWildcardArrayPOMDP)
```

To deal with pomdp specifications where states, actions, and observations are specified with strings, i.e., `ss = ["warm", "very-warm"], aa = ["north", "west", "east", "west"]`, one may use the SWildcardArrayPOMDP type. More details on the differences between these two types are presented below. Three methods, `statenames`, `actionnames`, and `obsnames`, are defined to retrieve the names associated with the corresponding field of an `SWildcardArrayPOMDP` type.

> **Warning:** Functions `statenames`, `actionnames`, `obsnames` are not implemented for a `WildcardArrayPOMDP` type.

```julia
mutable struct InitialStateParam
number::Int
type_of_distribution::String
support_of_distribution::Set{Int}
value_of_distribution::Vector{Float64}

end
InitialStateParam(number::Int) = InitialStateParam(number, " ", Set{Int}([]), Vector{Float64}([]))
InitialStateParam() = InitialStateParam(0)
```

This is interface used to define the initial distribution of `WildcardArrayPOMDP`. It contains information about the number of states, support of the distribution, and a probability vector representation the initial distribution. The parameter `type_of_distribution` can either be equal to `"uniform"` or `"general distribution"`.

<!-- TODO: Try to add a more complex example here -->
## Quick example

In the example below we download the *paint.95.POMDP* file from [POMDP.org](https://www.pomdp.org/examples/paint.95.POMDP) and parse the content into a `SWildcardArrayPOMDP` variable type defined in this package. We then illustrate a few functionalities from *POMDPs.jl*.

```julia
using HTTP, POMDPs, POMDPFiles

mktempdir() do tmp_dir
url = "https://www.pomdp.org/examples/paint.95.POMDP"
tmp_file_name = joinpath(tmp_dir, "paint.95.POMDP")
HTTP.download(url, tmp_file_name)

pomdp = SWildcardArrayPOMDP(tmp_file_name)

states(pomdp)
end
```
Some of the examples in [POMDP.org](https://www.pomdp.org/examples), for instance, the `mini-hall2`, specifies a POMDP without associating names with states, actions, and observations. In these cases, one may use the `WildcardArrayPOMDP` type as described in the example below.

```julia
using HTTP, POMDPs, POMDPFiles

mktempdir() do tmp_dir
url = "https://www.pomdp.org/examples/mini-hall2.POMDP"
tmp_file_name = joinpath(tmp_dir, "mini-hall2.POMDP")
HTTP.download(url, tmp_file_name)

pomdp = WildcardArrayPOMDP(tmp_file_name)

initialstate(pomdp)
end
```

Using `SWildcardArrayPOMDP` in the previous example would allow us to refer to states, actions, and observations by means of a $0$-based indexing.
14 changes: 11 additions & 3 deletions src/POMDPFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ using Reexport
using POMDPs
using POMDPTools
using Printf
using POMDPModels: TabularPOMDP
using WildcardArrays
using WildcardArrays: WildcardArray
using LinearAlgebra

@reexport using POMDPXFiles # for POMDPAlphas

import POMDPs: action, value
import POMDPs: transition, reward, discount, observation, states, stateindex, actions, actionindex, observations, obsindex, initialstate

export read_alpha, read_pomdp
export InitialStateParam
include("types.jl")

export WildcardArrayPOMDP, SWildcardArrayPOMDP, statenames, actionnames, obsnames
include("WildcardArrayPOMDPs.jl")

export read_alpha, read_pomdp
include("reader.jl")

export numericprint, symbolicprint
Expand Down
146 changes: 146 additions & 0 deletions src/WildcardArrayPOMDPs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
"""
WildcardArrayPOMDP is the main data structure of the package. It is used to represent a POMDP problem from a file.

ns: number of states
na: number of actions
no: number of observations

support_initialstate: support of the initial state distribution
initialstate_distribution: initial state distribution

discount: discount factor

T: transition matrix
O: observation matrix
R: reward matrix
"""
struct WildcardArrayPOMDP <: POMDP{Int, Int, Int}
ns::Int
na::Int
no::Int

support_initialstate::Set{Int}
initialstate_distribution::Vector{Float64}

discount::Float64

T::WildcardArray{Float64, 3}
O::WildcardArray{Float64, 3}
R::WildcardArray{Float64, 4}
end

"""
Constructors for the WildcardArrayPOMDP type.
"""
WildcardArrayPOMDP(s::Int, a::Int, o::Int, initial_state::InitialStateParam, discount::Float64, T::WildcardArray{Float64, 3}, O::WildcardArray{Float64, 3}, R::WildcardArray{Float64, 4})= WildcardArrayPOMDP(s, a, o, support(initial_state), prob(initial_state), discount, T, O, R)
WildcardArrayPOMDP(filename::String) = read_pomdp(filename; output=:WildcardArrayPOMDP)

"""
Implementing the functions required by the POMDP interface. See [POMDPs.jl](https://juliapomdp.github.io/POMDPs.jl/latest/) for more details on the interface.
"""
states(m::WildcardArrayPOMDP) = 1:m.ns
stateindex(m::WildcardArrayPOMDP, i::Int) = (i <= m.ns) ? i : error("Querying states outside the allowable range.")

actions(m::WildcardArrayPOMDP) = 1:m.na
actionindex(m::WildcardArrayPOMDP, i::Int) = (i <= m.na) ? i : error("Querying input outside the allowable range.")

observations(m::WildcardArrayPOMDP) = 1:m.no
obsindex(m::WildcardArrayPOMDP, i::Int) = (i <= m.no) ? i : error("Querying observations outside the allowable range.")

function initialstate(m::WildcardArrayPOMDP)
if !isempty(m.initialstate_distribution)
return SparseCat(states(m), m.initialstate_distribution)
else
return SparseCat(states(m), 1/m.ns*ones(m.ns))
end
end

function transition(m::WildcardArrayPOMDP, s::Int, a::Int)
prob_val = [m.T[a,s,sp] for sp in states(m)]
return SparseCat(states(m), prob_val)
end

function observation(m::WildcardArrayPOMDP, a::Int, sp::Int)
prob_obs = [m.O[a, sp, obs] for obs in observations(m)]
return SparseCat(observations(m), prob_obs)
end

reward(m::WildcardArrayPOMDP, s::Int, a::Int, sp::Int, obs::Int) = m.R[a,s,sp,obs]
reward(m::WildcardArrayPOMDP, s::Int, a::Int, sp::Int) = m.R[a,s,sp,1]
reward(m::WildcardArrayPOMDP, s::Int, a::Int) = m.R[a,s,1,1]

discount(m::WildcardArrayPOMDP) = m.discount

# Data structure with names
"""
SWildcardArrayPOMDP is used whenever the names of the states, actions, and observations are known. It is used to represent a POMDP problem from a file.

dic_states: dictionary with the names of the states
dic_actions: dictionary with the names of the actions
dic_obs: dictionary with the names of the observations
pomdp: WildcardArrayPOMDP structure
"""
struct SWildcardArrayPOMDP <: POMDP{String, String, String}
dic_states::Dict{String, Int}
dic_actions::Dict{String, Int}
dic_obs::Dict{String, Int}
pomdp::WildcardArrayPOMDP

function SWildcardArrayPOMDP(dic_ss::Dict{String, Int}, dic_aa::Dict{String, Int}, dic_oo::Dict{String, Int}, pomdp::WildcardArrayPOMDP)
@assert length(dic_ss) == pomdp.ns
@assert length(dic_aa) == pomdp.na
@assert length(dic_oo) == pomdp.no

new(dic_ss, dic_aa, dic_oo, pomdp)
end
end
SWildcardArrayPOMDP(filename::String) = read_pomdp(filename; output=:SWildcardArrayPOMDP)
"""
Implementing the functions required by the POMDP interface. See [POMDPs.jl](https://juliapomdp.github.io/POMDPs.jl/latest/) for more details on the interface.
"""
states(m::SWildcardArrayPOMDP) = states(m.pomdp)
stateindex(m::SWildcardArrayPOMDP, key::Int) = stateindex(m.pomdp, key)
statenames(m::SWildcardArrayPOMDP) = collect(keys(m.dic_states))
function stateindex(m::SWildcardArrayPOMDP, key::String)
i = m.dic_states[key]
return stateindex(m, i)
end

actions(m::SWildcardArrayPOMDP) = actions(m.pomdp)
actionindex(m::SWildcardArrayPOMDP, key::Int) = actionindex(m.pomdp, key)
actionnames(m::SWildcardArrayPOMDP) = collect(keys(m.dic_actions))
function actionindex(m::SWildcardArrayPOMDP, key::String)
i = m.dic_actions[key]
return actionindex(m, i)
end

observations(m::SWildcardArrayPOMDP) = observations(m.pomdp)
obsindex(m::SWildcardArrayPOMDP, i::Int) = obsindex(m.pomdp, i)
obsnames(m::SWildcardArrayPOMDP) = collect(keys(m.dic_obs))
function obsindex(m::SWildcardArrayPOMDP, key::String)
i = m.dic_obs[key]
return obsindex(m, i)
end

initialstate(m::SWildcardArrayPOMDP) = initialstate(m.pomdp)

transition(m::SWildcardArrayPOMDP, s::Int, a::Int) = transition(m.pomdp, s, a)
function transition(m::SWildcardArrayPOMDP, s::String, a::String)
is = m.dic_states[s]; ia = m.dic_actions[a]
return transition(m, is, ia)
end

observation(m::SWildcardArrayPOMDP, a::Int, sp::Int) = observation(m.pomdp, a, sp)
function observation(m::SWildcardArrayPOMDP, a::String, sp::String)
isp = m.dic_states[sp]; ia = m.dic_actions[a]
return observation(m, ia, isp)
end

reward(m::SWildcardArrayPOMDP, s::Int, a::Int, sp::Int, obs::Int) = reward(m.pomdp, s, a, sp, obs)
reward(m::SWildcardArrayPOMDP, s::String, a::String, sp::String, obs::String) = reward(m.pomdp, m.dic_states[s], m.dic_actions[a], m.dic_states[sp], m.dic_obs[obs])
reward(m::SWildcardArrayPOMDP, s::Int, a::Int, sp::Int) = reward(m.pomdp, s, a, sp)
reward(m::SWildcardArrayPOMDP, s::String, a::String, sp::String) = reward(m.pomdp, m.dic_states[s], m.dic_actions[a], m.dic_states[sp])
reward(m::SWildcardArrayPOMDP, s::Int, a::Int) = reward(m.pomdp, s, a)
reward(m::SWildcardArrayPOMDP, s::String, a::String) = reward(m.pomdp, m.dic_states[s], m.dic_actions[a])

discount(m::SWildcardArrayPOMDP) = discount(m.pomdp)
Loading