diff --git a/src/algorithm.jl b/src/algorithm.jl index 825adb2..41ae12a 100644 --- a/src/algorithm.jl +++ b/src/algorithm.jl @@ -112,11 +112,35 @@ algorithm `algo` with verbose level `verbose`. """ function sample_scenarios end +function sample_scenarios(sp::AbstractStochasticProgram, n::Int, + depth_max=1000, to::TimerOutput=TimerOutput(), verbose::Int=0) + scenarios = [] + for i in 1:n + push!(scenarios,sample_scenario(sp, depth_max)) + end + return scenarios +end + +function sample_scenario(sp::AbstractStochasticProgram, depth_max=1000, + to::TimerOutput=TimerOutput(), verbose::Int=0) + node = get(sp,MasterNode()) + s = Vector{:= r + cdf += get(sp, Probability(), tr) + else + return tr + end + end + error("sum of probability $cdf < 1") +end + +struct IsLeaf <: AbstractNodeAttribute end +function get(sp::AbstractStochasticProgram, node::Int) + return isempty(get(sp, OutTransitions(), node)) +end +function is_empty(sp::AbstractStochasticProgram, node::Int) + return get(sp, IsLeaf(), node) +end