Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ndits.jl into master
  • Loading branch information
dourouc05 committed Dec 16, 2020
2 parents 025efd2 + cf6db8d commit d46ad4e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DataStructures = "^0.16, ^0.17, 0.18"
Distributions = "^0.16, ^0.17, ^0.18, ^0.19, ^0.20, ^0.21, ^0.22, 0.23, 0.24"
Hungarian = "^0.6"
IterTools = "^1.0"
JuMP = "^0.21"
JuMP = "^0.21, ^0.22"
LightGraphs = "^1.0"
Munkres = "^0.2"
julia = "^1"
43 changes: 43 additions & 0 deletions src/policies/ossb.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# OSSB (optimal sampling for structured bandits).
# Based on https://arxiv.org/abs/1711.00400.

abstract type OSSBOptimisationAlgorithm end
function optimise_ossb(instance::CombinatorialInstance{T}, ::OSSBOptimisationAlgorithm,
weights::Dict{T, Float64}) where T end

mutable struct OSSB <: Policy
algo::OSSBOptimisationAlgorithm
end

mutable struct OSSBDetails <: PolicyDetails
n_iterations::Int
solver_time::Float64

function OSSBDetails()
return new(0, 0.0)
end
end

function choose_action(instance::CombinatorialInstance{T}, policy::ESCB2, state::State{T}; with_trace::Bool=false) where T
# For initialisation, if some arms have never been tried, force them to be tried.
# This should not be required for OSSB, but it improves running times for the first few iterations.
if any(v == 0 for v in values(state.arm_counts))
weights = Dict(arm => iszero(state.arm_counts[arm]) ? 1.0 : 0.0 for arm in keys(state.arm_counts))

t0 = time_ns()
sol = solve_linear(instance, weights)
t1 = time_ns()

if with_trace
run_details = OSSBDetails()
run_details.n_iterations = 1
run_details.solver_time = (t1 - t0) / 1_000_000_000
return sol, run_details
else
return sol
end
end

# Solve OSSB's problem.
return optimise_ossb(instance, policy.algo, state.arm_average_reward, with_trace=with_trace)
end

2 comments on commit d46ad4e

@dourouc05
Copy link
Owner Author

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.

Error while trying to register: "Tag with name v0.1.3 already exists and points to a different commit"

Please sign in to comment.