Skip to content

Commit fe9482f

Browse files
committed
update docstrings
1 parent 5a2e852 commit fe9482f

File tree

9 files changed

+44
-34
lines changed

9 files changed

+44
-34
lines changed

src/Argmax/Argmax.jl

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ end
6262

6363
"""
6464
$TYPEDSIGNATURES
65+
66+
Generate a data sample for the argmax benchmark.
67+
This function generates a random feature matrix, computes the costs using the encoder,
68+
and adds noise to the costs before computing a target solution.
6569
"""
6670
function Utils.generate_sample(
6771
bench::ArgmaxBenchmark, rng::AbstractRNG; noise_std::Float32=0.0f0
@@ -73,28 +77,6 @@ function Utils.generate_sample(
7377
return DataSample(; x=features, θ_true=costs, y_true=noisy_solution)
7478
end
7579

76-
# """
77-
# $TYPEDSIGNATURES
78-
79-
# Generate a dataset of labeled instances for the argmax problem.
80-
# """
81-
# function Utils.generate_dataset(
82-
# bench::ArgmaxBenchmark, dataset_size::Int; noise_std=0.0, kwargs...
83-
# )
84-
# return Utils.generate_dataset(bench, dataset_size; noise_std=noise_std, kwargs...)
85-
# # (; instance_dim, nb_features, encoder) = bench
86-
# # rng = MersenneTwister(seed)
87-
# # features = [randn(rng, Float32, nb_features, instance_dim) for _ in 1:dataset_size]
88-
# # costs = encoder.(features)
89-
# # noisy_solutions = [
90-
# # one_hot_argmax(θ + noise_std * randn(rng, Float32, instance_dim)) for θ in costs
91-
# # ]
92-
# # return [
93-
# # DataSample(; x, θ_true, y_true) for
94-
# # (x, θ_true, y_true) in zip(features, costs, noisy_solutions)
95-
# # ]
96-
# end
97-
9880
"""
9981
$TYPEDSIGNATURES
10082

src/FixedSizeShortestPath/FixedSizeShortestPath.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ function Utils.generate_maximizer(bench::FixedSizeShortestPathBenchmark; use_dij
103103
return shortest_path_maximizer
104104
end
105105

106+
"""
107+
$TYPEDSIGNATURES
108+
109+
Generate a labeled sample for the fixed size shortest path benchmark.
110+
"""
106111
function Utils.generate_sample(
107112
bench::FixedSizeShortestPathBenchmark, rng::AbstractRNG; type::Type=Float32
108113
)

src/PortfolioOptimization/PortfolioOptimization.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ function Utils.generate_maximizer(bench::PortfolioOptimizationBenchmark)
8282
return portfolio_maximizer
8383
end
8484

85+
"""
86+
$TYPEDSIGNATURES
87+
88+
Generate a labeled sample for the portfolio optimization problem.
89+
"""
8590
function Utils.generate_sample(
8691
bench::PortfolioOptimizationBenchmark, rng::AbstractRNG; type::Type=Float32
8792
)

src/StochasticVehicleScheduling/StochasticVehicleScheduling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function Utils.generate_sample(
9494
instance = Instance(; nb_tasks, nb_scenarios, rng, store_city)
9595
x = get_features(instance)
9696
y_true = if compute_solutions
97-
algorithm(instance; kwargs...).value # TODO: modify algorithms to directly return the solution
97+
algorithm(instance; kwargs...)
9898
else
9999
nothing
100100
end

src/StochasticVehicleScheduling/solution/algorithms/column_generation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,5 @@ function column_generation_algorithm(
189189
end
190190

191191
col_solution = solution_from_paths(sol, instance)
192-
return col_solution
192+
return col_solution.value
193193
end

src/StochasticVehicleScheduling/solution/algorithms/deterministic_mip.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ function deterministic_mip(instance::Instance; model_builder=highs_model, silent
4141
solution = value.(y)
4242

4343
sol = solution_from_JuMP_array(solution, graph)
44-
return sol
44+
return sol.value
4545
end

src/StochasticVehicleScheduling/solution/algorithms/local_search.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,5 @@ Very simple heuristic, using [`local_search`](@ref)
153153
function local_search(instance::Instance; num_iterations=1000)
154154
_, initial_solution = solve_deterministic_VSP(instance)
155155
sol, _, _, _ = _local_search(initial_solution, instance; nb_it=num_iterations)
156-
return sol
156+
return sol.value
157157
end

src/StochasticVehicleScheduling/solution/algorithms/mip.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function compact_linearized_mip(
7878
solution = value.(y)
7979

8080
sol = solution_from_JuMP_array(solution, graph)
81-
return sol
81+
return sol.value
8282
end
8383

8484
"""
@@ -149,5 +149,5 @@ function compact_mip(
149149
solution = value.(y)
150150

151151
sol = solution_from_JuMP_array(solution, graph)
152-
return sol
152+
return sol.value
153153
end

src/Utils/interface.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
$TYPEDEF
33
4-
Abstract type interface for a benchmark problem.
4+
Abstract type interface for benchmark problems.
55
66
The following methods are mandatory for benchmarks:
7-
- [`generate_dataset`](@ref)
7+
- [`generate_dataset`](@ref) or [`generate_sample`](@ref)
88
- [`generate_statistical_model`](@ref)
99
- [`generate_maximizer`](@ref)
1010
@@ -17,27 +17,45 @@ abstract type AbstractBenchmark end
1717

1818
"""
1919
$TYPEDEF
20+
21+
Abstract type interface for stochastic benchmark problems.
22+
This type should be used for benchmarks that involve single stage stochastic optimization problems.
23+
24+
It follows the same interface as [`AbstractBenchmark`](@ref), with the addition of the following methods:
25+
TODO
2026
"""
2127
abstract type AbstractStochasticBenchmark <: AbstractBenchmark end
2228

2329
"""
2430
$TYPEDEF
31+
32+
Abstract type interface for dynamic benchmark problems.
33+
This type should be used for benchmarks that involve multi-stage stochastic optimization problems.
34+
35+
It follows the same interface as [`AbstractStochasticBenchmark`](@ref), with the addition of the following methods:
36+
TODO
2537
"""
2638
abstract type AbstractDynamicBenchmark <: AbstractStochasticBenchmark end
2739

2840
"""
29-
generate_sample(::AbstractBenchmark, rng::AbstractRNG; kwargs...)
41+
generate_sample(::AbstractBenchmark, rng::AbstractRNG; kwargs...) -> DataSample
3042
31-
Do not always exist, interface to make [`generate_dataset`](@ref) work.
32-
Either implement this or generate_dataset.
43+
Generate a single [`DataSample`](@ref) for given benchmark.
44+
This is a low-level function that is used by [`generate_dataset`](@ref) to create
45+
a dataset of samples. It is not mandatory to implement this method, but it is
46+
recommended for benchmarks that have a well-defined way to generate individual samples.
47+
An alternative is to directly implement [`generate_dataset`](@ref) to create a dataset
48+
without generating individual samples.
3349
"""
3450
function generate_sample end
3551

3652
"""
3753
generate_dataset(::AbstractBenchmark, dataset_size::Int; kwargs...) -> Vector{<:DataSample}
3854
39-
Generate a `Vector` of [`DataSample`](@ref) of length `dataset_size` for given benchmark.
55+
Generate a `Vector` of [`DataSample`](@ref) of length `dataset_size` for given benchmark.
4056
Content of the dataset can be visualized using [`plot_data`](@ref), when it applies.
57+
58+
By default, it uses [`generate_sample`](@ref) to create each sample in the dataset, and passes any keyword arguments to it.
4159
"""
4260
function generate_dataset(
4361
bench::AbstractBenchmark,

0 commit comments

Comments
 (0)