From 7fc045ba4fcdd8df0893075514c303627904e3fe Mon Sep 17 00:00:00 2001 From: Hector Perez Date: Wed, 18 Oct 2023 12:14:20 -0400 Subject: [PATCH] use @constraint --- src/hull.jl | 10 ++-------- src/logic.jl | 11 +++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/hull.jl b/src/hull.jl index c26e61d..7229b4e 100644 --- a/src/hull.jl +++ b/src/hull.jl @@ -36,14 +36,8 @@ function _disaggregate_variable(model::Model, lvref::LogicalVariableRef, vref::V dvname = name(dvref) lbname = isempty(dvname) ? "" : "$(dvname)_lower_bound" ubname = isempty(dvname) ? "" : "$(dvname)_upper_bound" - new_con_lb_ref = add_constraint(model, - build_constraint(error, lb*bvref - dvref, _MOI.LessThan(0)), - lbname - ) - new_con_ub_ref = add_constraint(model, - build_constraint(error, dvref - ub*bvref, _MOI.LessThan(0)), - ubname - ) + new_con_lb_ref = @constraint(model, lb*bvref - dvref <= 0, base_name = lbname) + new_con_ub_ref = @constraint(model, dvref - ub*bvref <= 0, base_name = ubname) push!(_reformulation_constraints(model), new_con_lb_ref, new_con_ub_ref) return dvref end diff --git a/src/logic.jl b/src/logic.jl index dca44c7..a902351 100644 --- a/src/logic.jl +++ b/src/logic.jl @@ -222,18 +222,14 @@ function _reformulate_selector(model::Model, func, set::Union{_MOIAtLeast, _MOIA dict = _indicator_to_binary(model) bvrefs = [dict[lvref] for lvref in func[2:end]] new_set = _vec_to_scalar_set(set)(func[1].constant) - cref = add_constraint(model, - build_constraint(error, @expression(model, sum(bvrefs)), new_set) - ) + cref = @constraint(model, sum(bvrefs) in new_set) push!(_reformulation_constraints(model), cref) end function _reformulate_selector(model::Model, func::Vector{LogicalVariableRef}, set::Union{_MOIAtLeast, _MOIAtMost, _MOIExactly}) dict = _indicator_to_binary(model) bvref, bvrefs... = [dict[lvref] for lvref in func] new_set = _vec_to_scalar_set(set)(0) - cref = add_constraint(model, - build_constraint(error, @expression(model, sum(bvrefs) - bvref), new_set) - ) + cref = @constraint(model, sum(bvrefs) - bvref in new_set) push!(_reformulation_constraints(model), cref) end @@ -261,8 +257,7 @@ _isa_literal(v) = false function _add_reformulated_proposition(model::Model, arg::Union{LogicalVariableRef,_LogicalExpr}) func = _reformulate_clause(model, arg) if !isempty(func.terms) && !all(iszero.(values(func.terms))) - con = build_constraint(error, func, _MOI.GreaterThan(1)) - cref = add_constraint(model, con) + cref = @constraint(model, func >= 1) push!(_reformulation_constraints(model), cref) end return