@@ -71,8 +71,9 @@ function generate_scenario end
7171
7272Enrich `instance_sample` with observable context drawn from `rng`.
7373Returns a new `DataSample` extending the instance: `.x` is the final ML feature vector
74- (possibly augmented with context features) and `.extra` holds any latent context fields
75- needed by [`generate_scenario`](@ref).
74+ (possibly augmented with context features). Any latent fields needed by
75+ [`generate_scenario`](@ref) must go into `.context` (they are spread as kwargs via
76+ `ctx.context...`), not into `.extra`.
7677
7778**Default**: returns `instance_sample` unchanged — no context augmentation.
7879Non-contextual benchmarks (e.g. SVS) use this default.
@@ -111,6 +112,18 @@ Returns `(env; reset_env=true, kwargs...) -> Vector{DataSample}`, a full traject
111112"""
112113function generate_anticipative_solver end
113114
115+ """
116+ objective_value(::ExogenousStochasticBenchmark, sample::DataSample, y, scenario) -> Real
117+
118+ Compute the objective value of solution `y` for a given `scenario`.
119+ Must be implemented by each concrete [`ExogenousStochasticBenchmark`](@ref).
120+
121+ This is the primary evaluation hook for stochastic benchmarks. The 2-arg fallback
122+ `objective_value(bench, sample, y)` dispatches here using the scenario stored in
123+ `sample.extra.scenario` (or averages over `sample.extra.scenarios`).
124+ """
125+ function objective_value end
126+
114127"""
115128 generate_parametric_anticipative_solver(::ExogenousStochasticBenchmark) -> callable
116129
@@ -216,6 +229,7 @@ function generate_dataset(
216229 rng= MersenneTwister (seed),
217230 kwargs... ,
218231)
232+ nb_instances == 0 && return DataSample[]
219233 return reduce (
220234 vcat,
221235 (
@@ -275,7 +289,7 @@ function generate_sample(
275289 generate_scenario (inner, rng; ctx. context... ) for _ in 1 : (saa. nb_scenarios)
276290 ]
277291 if isnothing (target_policy)
278- return [DataSample (; x= ctx. x, ctx. context... , extra= (; ctx. extra... , scenarios))]
292+ return [DataSample (; x= ctx. x, θ = ctx . θ, ctx. context... , extra= (; ctx. extra... , scenarios))]
279293 else
280294 return target_policy (ctx, scenarios)
281295 end
@@ -300,8 +314,10 @@ function generate_dataset(
300314 rng= MersenneTwister (seed),
301315 kwargs... ,
302316)
317+ nb_instances == 0 && return DataSample[]
303318 return reduce (
304- vcat, (generate_sample (saa, rng; target_policy, kwargs... ) for _ in 1 : nb_instances)
319+ vcat,
320+ (generate_sample (saa, rng; target_policy, kwargs... ) for _ in 1 : nb_instances),
305321 )
306322end
307323
0 commit comments