From e2303384f696f2f80f5ccf8580145f158736302e Mon Sep 17 00:00:00 2001 From: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk> Date: Thu, 1 Feb 2024 14:00:51 +0000 Subject: [PATCH] Fix variable conversion --- src/building_blocks.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/building_blocks.jl b/src/building_blocks.jl index 08343c3..ab01541 100644 --- a/src/building_blocks.jl +++ b/src/building_blocks.jl @@ -258,14 +258,18 @@ function set_simple_constraints!(model::Model, block::BuildingBlock, kwargs) invert_value(value) = value for (key, value) in kwargs - if key == :qval - apply_simple_constraint!(model, qval_square(block), value isa VariableType ? value^2 : value) - elseif key == :slice_thickness && :inverse_slice_thickness in keys(to_funcs) - apply_simple_constraint!(model, inverse_slice_thickness(block), invert_value(value)) - elseif key == :bandwidth && :inverse_bandwidth in keys(to_funcs) - apply_simple_constraint!(model, inverse_bandwidth(block), invert_value(value)) - else + if key in keys(to_funcs) apply_simple_constraint!(model, to_funcs[key](block), value) + else + if key == :qval + apply_simple_constraint!(model, to_funcs[:qval_square](block), value isa VariableType ? value^2 : value) + elseif key == :slice_thickness && :inverse_slice_thickness in keys(to_funcs) + apply_simple_constraint!(model, to_funcs[:inverse_slice_thickness](block), invert_value(value)) + elseif key == :bandwidth && :inverse_bandwidth in keys(to_funcs) + apply_simple_constraint!(model, to_funcs[:inverse_bandwidth](block), invert_value(value)) + else + error("Trying to set an unrecognised variable $key.") + end end end nothing -- GitLab