Skip to content

Commit

Permalink
envelopes
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jan 18, 2024
1 parent f731a61 commit 3c225a0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
36 changes: 32 additions & 4 deletions src/analysis/envelope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions src/analysis/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/variability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}

Expand All @@ -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

0 comments on commit 3c225a0

Please sign in to comment.