Skip to content

Commit

Permalink
Fix strategy synthesis with implicit sink state
Browse files Browse the repository at this point in the history
  • Loading branch information
Zinoex committed Jan 21, 2025
1 parent 5b44edb commit 5833bca
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IntervalMDP"
uuid = "051c988a-e73c-45a4-90ec-875cac0402c7"
authors = ["Frederik Baymler Mathiesen <[email protected]> and contributors"]
version = "0.4.2"
version = "0.4.3"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
1 change: 1 addition & 0 deletions src/models/IntervalMarkovDecisionProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ stateptr(mdp::IntervalMarkovDecisionProcess) = mdp.stateptr
max_actions(mdp::IntervalMarkovDecisionProcess) = maxdiff(stateptr(mdp))
Base.ndims(::IntervalMarkovDecisionProcess) = one(Int32)
product_num_states(mp::IntervalMarkovDecisionProcess) = (num_states(mp),)
source_shape(mp::IntervalMarkovDecisionProcess) = (length(stateptr(mp)) - 1,)
1 change: 1 addition & 0 deletions src/models/MixtureIntervalMarkovDecisionProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ max_actions(mdp::MixtureIntervalMarkovDecisionProcess) = maxdiff(stateptr(mdp))
Base.ndims(::MixtureIntervalMarkovDecisionProcess{N}) where {N} = Int32(N)
product_num_states(mp::MixtureIntervalMarkovDecisionProcess) =
num_target(transition_prob(mp))
source_shape(mp::MixtureIntervalMarkovDecisionProcess) = source_shape(transition_prob(mp))
1 change: 1 addition & 0 deletions src/models/OrthogonalIntervalMarkovDecisionProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ max_actions(mdp::OrthogonalIntervalMarkovDecisionProcess) = maxdiff(stateptr(mdp
Base.ndims(::OrthogonalIntervalMarkovDecisionProcess{N}) where {N} = Int32(N)
product_num_states(mp::OrthogonalIntervalMarkovDecisionProcess) =
num_target(transition_prob(mp))
source_shape(mp::OrthogonalIntervalMarkovDecisionProcess) = source_shape(transition_prob(mp))
2 changes: 1 addition & 1 deletion src/strategy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ depends on the configuration and the device to store the strategy depends on the
function construct_strategy_cache end

construct_strategy_cache(mp::IntervalMarkovProcess, config, strategy = NoStrategy()) =
construct_strategy_cache(mp, config, strategy, product_num_states(mp))
construct_strategy_cache(mp, config, strategy, source_shape(mp))

# Strategy cache for applying given policies - useful for dispatching
struct GivenStrategyCache{S <: AbstractStrategy} <: NonOptimizingStrategyCache
Expand Down
43 changes: 43 additions & 0 deletions test/base/synthesis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,46 @@ end

# The last time step (aka. the first value iteration step) has a different strategy.
@test policy[time_length(policy)] == [2, 1, 1]

@testset "implicit sink state" begin
prob1 = IntervalProbabilities(;
lower = [
0.0 0.5
0.1 0.3
0.2 0.1
],
upper = [
0.5 0.7
0.6 0.5
0.7 0.3
],
)

prob2 = IntervalProbabilities(;
lower = [
0.1 0.2
0.2 0.3
0.3 0.4
],
upper = [
0.6 0.6
0.5 0.5
0.4 0.4
],
)

transition_probs = [prob1, prob2]
mdp = IntervalMarkovDecisionProcess(transition_probs)

# Finite time reachability
prop = FiniteTimeReachability([3], 10)
spec = Specification(prop, Pessimistic, Maximize)
problem = Problem(mdp, spec)
policy, V, k, res = control_synthesis(problem)

@test policy isa TimeVaryingStrategy
@test time_length(policy) == 10
for k in 1:time_length(policy)
@test policy[k] == [1, 2]
end
end

2 comments on commit 5833bca

@Zinoex
Copy link
Owner Author

@Zinoex Zinoex commented on 5833bca Jan 21, 2025

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/123417

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" 5833bcafc49a4cbd0dcc47b620b55be33b90c564
git push origin v0.4.3

Please sign in to comment.