diff --git a/src/analysis/envelope.jl b/src/analysis/envelope.jl index 919e7c639..cad9b1705 100644 --- a/src/analysis/envelope.jl +++ b/src/analysis/envelope.jl @@ -14,11 +14,39 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +$(TYPEDSIGNATURES) + +TODO +""" function constraints_objective_envelope( - constraints::C.ConstraintTree, - grid::Array{C.ConstraintTreeElem}, - objective::C.Value; + constraints::C.ConstraintTree; + dims...; + objective::C.Value, + optimizer, + settings = [], workers = D.workers(), ) - #TODO + values = first.(dims) + ranges = last.(dims) + + screen_optimization_model( + constraints, + Iterators.product(ranges...); + objective, + optimizer, + settings, + workers, + ) do om, coords + con_refs = [ + begin + J.@constraint(om, con_ref, C.substitute(v, om[:x]) == x) + con_ref + end for (v, x) in zip(values, coords) + ] + J.optimize!(om) + res = is_solved(om) ? J.objective_value(om) : nothing + J.delete.(con_refs) + res + end end diff --git a/src/analysis/screen.jl b/src/analysis/screen.jl index bd6e4d2b8..5f99b6934 100644 --- a/src/analysis/screen.jl +++ b/src/analysis/screen.jl @@ -33,11 +33,15 @@ function screen_optimization_model( args...; objective::Union{Nothing,C.Value} = nothing, optimizer, + settings = [], workers = D.workers(), ) - # TODO maybe settings? worker_cache = worker_local_data(constraints) do c - (c, COBREXA.optimization_model(c; objective, optimizer)) + om = COBREXA.optimization_model(c; objective, optimizer) + for s in settings + s(om) + end + om end D.pmap( diff --git a/src/analysis/variability.jl b/src/analysis/variability.jl index 9221ed8ef..8c7c42d5a 100644 --- a/src/analysis/variability.jl +++ b/src/analysis/variability.jl @@ -23,6 +23,7 @@ function constraints_variability( constraints::C.ConstraintTree, targets::C.ConstraintTree; optimizer, + settings = [], workers = D.workers(), )::C.Tree{Tuple{Maybe{Float64},Maybe{Float64}}} @@ -33,12 +34,13 @@ function constraints_variability( constraints, target_array; optimizer, + settings, workers, ) do om, target J.@objective(om, Maximal, C.substitute(target, om[:x])) J.optimize!(om) - if_solved(om) ? J.objective_value(om) : nothing + is_solved(om) ? J.objective_value(om) : nothing end - constraint_tree_reinflate(targets, [(row[1], row[2]) for row in eachrow(result_array)]) + constraint_tree_reinflate(targets, [tuple(a, b) for (a, b) in eachrow(result_array)]) end