use cobre_stochastic::context::ClassSchemes;
use cobre_stochastic::{
ClassDimensions, ForwardSampler, ForwardSamplerConfig, build_forward_sampler,
};
use crate::context::TrainingContext;
use crate::error::SddpError;
pub fn build_sampler_from_ctx<'a>(
ctx: &'a TrainingContext<'a>,
) -> Result<ForwardSampler<'a>, SddpError> {
let stochastic = ctx.stochastic;
build_forward_sampler(ForwardSamplerConfig {
class_schemes: ClassSchemes {
inflow: Some(ctx.inflow_scheme),
load: Some(ctx.load_scheme),
ncs: Some(ctx.ncs_scheme),
},
ctx: stochastic,
stages: ctx.stages,
dims: ClassDimensions {
n_hydros: stochastic.n_hydros(),
n_load_buses: stochastic.n_load_buses(),
n_ncs: stochastic.n_stochastic_ncs(),
},
historical_library: ctx.historical_library,
external_inflow_library: ctx.external_inflow_library,
external_load_library: ctx.external_load_library,
external_ncs_library: ctx.external_ncs_library,
})
.map_err(SddpError::Stochastic)
}