-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddffd72
commit b0c705a
Showing
10 changed files
with
73 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,54 @@ | ||
""" | ||
get_solver(params) | ||
This function returns the JuMP optimizer with its appropriate attributes, based on | ||
user-defined inputs in `params` dictionary. | ||
""" | ||
function get_solver(params::Dict{String,Any}) | ||
optimizers_list = ["cplex", "cbc", "ipopt", "juniper", "alpine", "glpk", "gurobi"] | ||
|
||
# Optimizer | ||
if !("optimizer" in keys(params)) | ||
error("Input a valid MIP optimizer") | ||
end | ||
|
||
if !(params["optimizer"] in optimizers_list) | ||
error("Specified optimizer does not belong in the pre-defined list. Add your optimizer separately with it's attributes") | ||
end | ||
|
||
if "presolve" in keys(params) | ||
presolve = params["presolve"] | ||
else | ||
# default value | ||
presolve = true | ||
end | ||
|
||
if "optimizer_log" in keys(params) | ||
optimizer_log = params["optimizer_log"] | ||
else | ||
# default value | ||
optimizer_log = true | ||
end | ||
#=====================================# | ||
# MIP solvers (commercial, but fast) # | ||
#=====================================# | ||
|
||
function get_gurobi() | ||
return JuMP.optimizer_with_attributes(Gurobi.Optimizer, | ||
MOI.Silent() => false, | ||
# "MIPFocus" => 3, # Focus on optimality over feasibility | ||
"Presolve" => 1) | ||
end | ||
|
||
# Mixed-integer programming optimizers | ||
if params["optimizer"] == "cplex" # commercial | ||
return get_cplex(presolve, optimizer_log) | ||
|
||
elseif params["optimizer"] == "gurobi" # commercial | ||
return get_gurobi(presolve, optimizer_log) | ||
function get_cplex() | ||
return JuMP.optimizer_with_attributes(CPLEX.Optimizer, | ||
MOI.Silent() => false, | ||
# "CPX_PARAM_EPGAP" => 1E-4, | ||
# "CPX_PARAM_MIPEMPHASIS" => 2 # Focus on optimality over feasibility | ||
"CPX_PARAM_PREIND" => 1) | ||
end | ||
|
||
elseif params["optimizer"] == "cbc" # open-source | ||
return get_cbc(presolve, optimizer_log) | ||
#======================================# | ||
# MIP solvers (open-source, but slow) # | ||
#======================================# | ||
|
||
elseif params["optimizer"] == "glpk" # open-source | ||
return get_glpk(presolve, optimizer_log) | ||
|
||
# Local mixed-integer nonlinear programming optimizers | ||
elseif params["optimizer"] == "ipopt" # open-source | ||
return get_ipopt(presolve, optimizer_log) | ||
|
||
elseif params["optimizer"] == "juniper" # open-source | ||
return get_juniper(presolve, optimizer_log) | ||
|
||
# Global NLP/MINLP optimizer | ||
elseif params["optimizer"] == "alpine" # open-source | ||
alpine = JuMP.optimizer_with_attributes(Alpine.Optimizer, | ||
"nlp_solver" => get_ipopt(presolve, optimizer_log), | ||
"minlp_solver" => get_juniper(presolve, optimizer_log), | ||
"mip_solver" => get_cplex(presolve, optimizer_log), | ||
"presolve_bt" => false, | ||
"presolve_max_iter" => 10, | ||
"presolve_bp" => false, | ||
"disc_ratio" => 10) | ||
return alpine | ||
end | ||
function get_cbc() | ||
return JuMP.optimizer_with_attributes(Cbc.Optimizer, | ||
MOI.Silent() => false) | ||
end | ||
|
||
function get_cplex(presolve::Bool, optimizer_log::Bool) | ||
cplex = JuMP.optimizer_with_attributes(CPLEX.Optimizer, | ||
MOI.Silent() => !optimizer_log, | ||
"CPX_PARAM_PREIND" => presolve) | ||
return cplex | ||
function get_glpk() | ||
return JuMP.optimizer_with_attributes(GLPK.Optimizer, | ||
MOI.Silent() => false) | ||
end | ||
|
||
function get_gurobi(presolve::Bool, optimizer_log::Bool) | ||
gurobi = JuMP.optimizer_with_attributes(Gurobi.Optimizer, | ||
MOI.Silent() => !optimizer_log, | ||
"Presolve" => presolve) | ||
return gurobi | ||
end | ||
#========================================================# | ||
# Continuous nonlinear programming solver (open-source) # | ||
#========================================================# | ||
|
||
function get_ipopt(presolve::Bool, optimizer_log::Bool) | ||
ipopt = JuMP.optimizer_with_attributes(Ipopt.Optimizer, | ||
MOI.Silent() => !optimizer_log, | ||
function get_ipopt() | ||
return JuMP.optimizer_with_attributes(Ipopt.Optimizer, | ||
MOI.Silent() => true, | ||
"sb" => "yes", | ||
"max_iter" => 1E4) | ||
return ipopt | ||
"max_iter" => Int(1E4)) | ||
end | ||
|
||
function get_cbc(presolve::Bool, optimizer_log::Bool) | ||
cbc = JuMP.optimizer_with_attributes(Cbc.Optimizer, | ||
MOI.Silent() => !optimizer_log) | ||
return cbc | ||
end | ||
|
||
function get_juniper(presolve::Bool, optimizer_log::Bool) | ||
juniper = JuMP.optimizer_with_attributes(Juniper.Optimizer, | ||
MOI.Silent() => !optimizer_log, | ||
"mip_solver" => get_cplex(presolve, optimizer_log), | ||
"nl_solver" => get_ipopt(presolve, optimizer_log)) | ||
return juniper | ||
end | ||
|
||
function get_glpk(presolve::Bool, optimizer_log::Bool) | ||
glpk = JuMP.optimizer_with_attributes(GLPK.Optimizer, | ||
MOI.Silent() => !optimizer_log) | ||
return glpk | ||
end | ||
#=================================================================# | ||
# Local mixed-integer nonlinear programming solver (open-source) # | ||
#=================================================================# | ||
function get_juniper() | ||
return JuMP.optimizer_with_attributes(Juniper.Optimizer, | ||
MOI.Silent() => false, | ||
"mip_solver" => get_gurobi(), | ||
"nl_solver" => get_ipopt()) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters