@@ -743,6 +743,10 @@ function MOI.add_constraint(
743743 MOI. Interval{Float64},
744744 },
745745)
746+ F, S = typeof(func), typeof(set)
747+ if ! iszero(func. constant)
748+ throw(MOI. ScalarFunctionConstantNotZero{F,S}(func. constant))
749+ end
746750 _throw_if_solved(model, func, set)
747751 _throw_if_not_valid(model, func)
748752 # Add a single constraint in KNITRO.
@@ -752,19 +756,19 @@ function MOI.add_constraint(
752756 # Add bound to constraint.
753757 if isa(set, MOI. LessThan{Float64})
754758 val = _clamp_inf(set. upper)
755- KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, val - func . constant )
759+ KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, val)
756760 elseif isa(set, MOI. GreaterThan{Float64})
757761 val = _clamp_inf(set. lower)
758- KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, val - func . constant )
762+ KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, val)
759763 elseif isa(set, MOI. EqualTo{Float64})
760764 val = _clamp_inf(set. value)
761- KNITRO. @_checked KNITRO. KN_set_con_eqbnd(model. inner, num_cons, val - func . constant )
765+ KNITRO. @_checked KNITRO. KN_set_con_eqbnd(model. inner, num_cons, val)
762766 else
763767 @assert set isa MOI. Interval{Float64}
764768 # Add upper bound.
765769 lb, ub = _clamp_inf(set. lower), _clamp_inf(set. upper)
766- KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, lb - func . constant )
767- KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, ub - func . constant )
770+ KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, lb)
771+ KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, ub)
768772 end
769773 nnz, columns, coefficients = _canonical_linear_reduction(func)
770774 KNITRO. @_checked(
@@ -776,7 +780,7 @@ function MOI.add_constraint(
776780 coefficients,
777781 ),
778782 )
779- ci = MOI. ConstraintIndex{typeof(func),typeof(set) }(num_cons)
783+ ci = MOI. ConstraintIndex{F,S }(num_cons)
780784 model. constraint_mapping[ci] = num_cons
781785 return ci
782786end
@@ -830,6 +834,10 @@ function MOI.add_constraint(
830834 MOI. Interval{Float64},
831835 },
832836)
837+ if ! iszero(func. constant)
838+ F, S = typeof(func), typeof(set)
839+ throw(MOI. ScalarFunctionConstantNotZero{F,S}(func. constant))
840+ end
833841 _throw_if_solved(model, func, set)
834842 _throw_if_not_valid(model, func)
835843 # We add a constraint in KNITRO.
@@ -839,18 +847,18 @@ function MOI.add_constraint(
839847 # Add upper bound.
840848 if isa(set, MOI. LessThan{Float64})
841849 val = _clamp_inf(set. upper)
842- KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, val - func . constant )
850+ KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, val)
843851 elseif isa(set, MOI. GreaterThan{Float64})
844852 val = _clamp_inf(set. lower)
845- KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, val - func . constant )
853+ KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, val)
846854 elseif isa(set, MOI. EqualTo{Float64})
847855 val = _clamp_inf(set. value)
848- KNITRO. @_checked KNITRO. KN_set_con_eqbnd(model. inner, num_cons, val - func . constant )
856+ KNITRO. @_checked KNITRO. KN_set_con_eqbnd(model. inner, num_cons, val)
849857 elseif isa(set, MOI. Interval{Float64})
850858 lb = _clamp_inf(set. lower)
851859 ub = _clamp_inf(set. upper)
852- KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, lb - func . constant )
853- KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, ub - func . constant )
860+ KNITRO. @_checked KNITRO. KN_set_con_lobnd(model. inner, num_cons, lb)
861+ KNITRO. @_checked KNITRO. KN_set_con_upbnd(model. inner, num_cons, ub)
854862 end
855863 nnz, columns, coefficients = _canonical_linear_reduction(func)
856864 KNITRO. @_checked(
@@ -1567,29 +1575,26 @@ function MOI.get(model::Optimizer, attr::MOI.VariablePrimal, x::MOI.VariableInde
15671575 return _get_solution(model, x. value)
15681576end
15691577
1570- # TODO (odow): enabling this causes a flakey failure on Windows and Linux
1571- # machines
1572- #
1573- # function MOI.get(
1574- # model::Optimizer,
1575- # attr::MOI.ConstraintPrimal,
1576- # ci::MOI.ConstraintIndex{S,T},
1577- # ) where {
1578- # S<:Union{MOI.ScalarAffineFunction{Float64},MOI.ScalarQuadraticFunction{Float64}},
1579- # T<:Union{
1580- # MOI.EqualTo{Float64},
1581- # MOI.GreaterThan{Float64},
1582- # MOI.LessThan{Float64},
1583- # MOI.Interval{Float64},
1584- # },
1585- # }
1586- # MOI.check_result_index_bounds(model, attr)
1587- # MOI.throw_if_not_valid(model, ci)
1588- # indexCon = model.constraint_mapping[ci]
1589- # p = Ref{Cdouble}(NaN)
1590- # KNITRO.@_checked KNITRO.KN_get_con_value(model.inner, indexCon, p)
1591- # return p[]
1592- # end
1578+ function MOI. get(
1579+ model:: Optimizer ,
1580+ attr:: MOI.ConstraintPrimal ,
1581+ ci:: MOI.ConstraintIndex{S,T} ,
1582+ ) where {
1583+ S<: Union{MOI.ScalarAffineFunction{Float64},MOI.ScalarQuadraticFunction{Float64}} ,
1584+ T<: Union {
1585+ MOI. EqualTo{Float64},
1586+ MOI. GreaterThan{Float64},
1587+ MOI. LessThan{Float64},
1588+ MOI. Interval{Float64},
1589+ },
1590+ }
1591+ MOI. check_result_index_bounds(model, attr)
1592+ MOI. throw_if_not_valid(model, ci)
1593+ indexCon = model. constraint_mapping[ci]
1594+ p = Ref{Cdouble}(NaN )
1595+ KNITRO. @_checked KNITRO. KN_get_con_value(model. inner, indexCon, p)
1596+ return p[]
1597+ end
15931598
15941599# function MOI.get(
15951600# model::Optimizer,
0 commit comments