Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ repo = "https://github.com/JuliaPOMDP/POMDPXFiles.jl"
version = "0.2.4"

[deps]
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
POMDPTools = "7588e00f-9cae-40de-98dc-e0c70c48cdd7"
POMDPs = "a93abf59-7444-517b-a68a-c42f96afdd7d"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"

[compat]
LightXML = "0.9"
POMDPTools = "0.1"
POMDPs = "0.7.3, 0.8, 0.9"
julia = "1"
Expand All @@ -20,4 +20,4 @@ POMDPModels = "355abbd5-f08e-5560-ac9e-8b5f2592a0ca"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["POMDPModels", "Test"]
test = ["POMDPModels", "Test"]
2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

15 changes: 5 additions & 10 deletions src/POMDPXFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ module POMDPXFiles
using POMDPs
using POMDPTools
using ProgressMeter
import POMDPs: action, value

# import o avoid naming conflict in POMDPs.jl (value is overloaded in LightXML)
import LightXML: parse_file, root, get_elements_by_tagname, attribute, content
using Parameters

import EzXML
import EzXML: Node, XMLDocument, ElementNode, addelement!, link!, write, readxml, root, findfirst, findall, nodecontent, setroot!, prettyprint

export
AbstractPOMDPXFile,
POMDPXFile,
MOMDPXFile,
Alphas,
POMDPAlphas,

read_pomdp,
action,
value

read_pomdp

include("writer.jl")
include("policy.jl")
include("read.jl")
include("reader.jl")

end # module
119 changes: 0 additions & 119 deletions src/read.jl

This file was deleted.

41 changes: 41 additions & 0 deletions src/reader.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Parses a Policy XML file and returns `alphavectors` and `alphaactions`
This should be able to handle any policy in the `.policy` format, which includes
policies written by `POMDPs.jl` or `APPL`.

`alphavectors` is a matrix containing the alpha vectors where each row corresponds to a
different alpha vector.

`alphaactions` is a vector containing the list of action indices, where ach index
corresponds to action associated with the alpha vector row.
These are `0-indexed`, so `0` maps to the first action.
"""

function read_pomdp(filename::String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an exceedingly strange name for a function that reads in alpha vectors. I think we could name it something better and deprecate read_pomdp.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also confused by its name. 😅

Perhaps read_policy?

Then read_pomdp (at some time TBD) would go from .pomdpx to POMDP? Though I’m not sure the utility of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like read_policy, but let's also have a deprecation for any downstream packages to transition smoothly.

xml = readxml(open(filename, "r"))
policy = root(xml) # The <Polciy ..> node

av_node = findfirst("AlphaVector", policy)

alphavectors = Array{Real}[]
alphaactions = []

# Create alpha vector and alpha action lists
vectors = findall("Vector", av_node)
for vector in vectors
push!(alphavectors, parse.(Float64, split(nodecontent(vector))))
push!(alphaactions, vector["action"])
end
alphavectors = transpose(mapreduce(permutedims, vcat, alphavectors))

n_vectors = parse(Int, av_node["numVectors"])
vector_len = parse(Int, av_node["vectorLength"])
@assert size(alphavectors) == (vector_len, n_vectors)

# TODO handle sparsevectors
sparsevectors = findall("SparseVector", av_node)
for vector in sparsevectors
# Turn these into vectors
end

return (alphavectors=alphavectors, alphaactions=parse.(Int64, alphaactions))
end
Loading