Skip to content

Commit

Permalink
The specialized solvers now use OptimizerWithAttributes when returnin…
Browse files Browse the repository at this point in the history
…g configured suproblem solvers.
  • Loading branch information
martinbiel committed Dec 23, 2020
1 parent f7c8017 commit f2e9bcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
23 changes: 9 additions & 14 deletions src/solvers/sampled/SAA/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ function load_model!(optimizer::Optimizer,
sampler::AbstractSampler,
x₀::AbstractVector)
instance_optimizer = MOI.get(optimizer, InstanceOptimizer())
# Default log settings
try
MOI.set(instance_optimizer, MOI.RawParameter("log"), optimizer.parameters.log)
MOI.set(instance_optimizer, MOI.RawParameter("keep"), optimizer.parameters.keep)
MOI.set(instance_optimizer, MOI.RawParameter("offset"), optimizer.parameters.offset + 1)
MOI.set(instance_optimizer, MOI.RawParameter("indent"), 2 * optimizer.parameters.indent)
catch
end
# Create new SAA algorithm
optimizer.algorithm = SampleAverageApproximation(model,
sampler,
Expand Down Expand Up @@ -156,20 +164,7 @@ function MOI.get(optimizer::Optimizer, ::InstanceOptimizer)
if optimizer.instance_optimizer === nothing
error("Instance optimizer not set. Consider setting `InstanceOptimizer` attribute.")
end
return () -> begin
instance_opt = optimizer.instance_optimizer()
for (attr, value) in optimizer.optimizer_params
MOI.set(instance_opt, attr, value)
end
try
MOI.set(instance_opt, MOI.RawParameter("log"), optimizer.parameters.log)
MOI.set(instance_opt, MOI.RawParameter("keep"), optimizer.parameters.keep)
MOI.set(instance_opt, MOI.RawParameter("offset"), optimizer.parameters.offset + 1)
MOI.set(instance_opt, MOI.RawParameter("indent"), 2 * optimizer.parameters.indent)
catch
end
return instance_opt
end
return MOI.OptimizerWithAttributes(optimizer.instance_optimizer, collect(optimizer.optimizer_params))
end

function MOI.set(optimizer::Optimizer, ::InstanceOptimizer, optimizer_constructor)
Expand Down
16 changes: 2 additions & 14 deletions src/solvers/structured/lshaped/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,7 @@ function MOI.get(optimizer::Optimizer, ::MasterOptimizer)
if optimizer.master_optimizer === nothing
return nothing
end
return () -> begin
opt = optimizer.master_optimizer()
for (attr, value) in optimizer.master_params
MOI.set(opt, attr, value)
end
return opt
end
return MOI.OptimizerWithAttributes(optimizer.master_optimizer, collect(optimizer.master_params))
end

function MOI.set(optimizer::Optimizer, ::MasterOptimizer, optimizer_constructor)
Expand Down Expand Up @@ -260,13 +254,7 @@ function MOI.get(optimizer::Optimizer, ::SubproblemOptimizer)
if optimizer.subproblem_optimizer === nothing
return MOI.get(optimizer, MasterOptimizer())
end
return () -> begin
opt = optimizer.subproblem_optimizer()
for (attr, value) in optimizer.sub_params
MOI.set(opt, attr, value)
end
return opt
end
return MOI.OptimizerWithAttributes(optimizer.subproblem_optimizer, collect(optimizer.sub_params))
end

function MOI.set(optimizer::Optimizer, ::SubproblemOptimizer, optimizer_constructor)
Expand Down
8 changes: 1 addition & 7 deletions src/solvers/structured/progressivehedging/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,7 @@ function MOI.get(optimizer::Optimizer, ::SubproblemOptimizer)
if optimizer.subproblem_optimizer === nothing
return MOI.get(optimizer, MasterOptimizer())
end
return () -> begin
opt = optimizer.subproblem_optimizer()
for (attr, value) in optimizer.sub_params
MOI.set(opt, attr, value)
end
return opt
end
return MOI.OptimizerWithAttributes(optimizer.subproblem_optimizer, collect(optimizer.sub_params))
end

function MOI.set(optimizer::Optimizer, ::SubproblemOptimizer, optimizer_constructor)
Expand Down

2 comments on commit f2e9bcc

@martinbiel
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 register(branch="release-0.5")

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/27036

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" f2e9bcca7ec3e0c27babbef90621bf6794936f6a
git push origin v0.5.0

Please sign in to comment.