@@ -569,17 +569,18 @@ _check_bound_compat(::Optimizer, ::MOI.VariableIndex, ::MOI.Integer) = nothing
569569
570570function MOI. add_constraint (
571571 m:: Optimizer ,
572- xs:: MOI.VariableIndex ,
573- dom:: D ,
574- ) where {D<: Union{ScalarLinearDomain,MOI.Integer} }
575- msk_idx = mosek_index (m, xs)
576- if ! (msk_idx isa ColumnIndex)
577- error (" Cannot add $D constraint on a matrix variable" )
572+ x:: MOI.VariableIndex ,
573+ set:: S ,
574+ ) where {S<: Union{ScalarLinearDomain,MOI.Integer} }
575+ index = mosek_index (m, x)
576+ if index isa MatrixIndex
577+ msg = " Cannot add $S constraint on a matrix variable."
578+ throw (MOI. AddConstraintNotAllowed {MOI.VariableIndex,S} (msg))
578579 end
579- _check_bound_compat (m, xs, dom )
580- set_flag (m, xs, D )
581- _add_variable_constraint (m, msk_idx, dom )
582- return MOI. ConstraintIndex {MOI.VariableIndex,D} (xs . value)
580+ _check_bound_compat (m, x, set )
581+ set_flag (m, x, S )
582+ _add_variable_constraint (m, index, set )
583+ return MOI. ConstraintIndex {MOI.VariableIndex,S} (x . value)
583584end
584585
585586_cone_type (:: Type{MOI.ExponentialCone} ) = Mosek. MSK_CT_PEXP
@@ -746,8 +747,8 @@ function MOI.get(
746747 nnz, cols, vals = Mosek. getarow (m. task, row (m, ci))
747748 @assert nnz == length (cols) == length (vals)
748749 terms = MOI. ScalarAffineTerm{Float64}[
749- MOI. ScalarAffineTerm (vals[i], index_of_column (m, cols[i] )) for
750- i in 1 : nnz
750+ MOI. ScalarAffineTerm (v, _col_to_index (m, c )) for
751+ (v, c) in zip (vals, cols)
751752 ]
752753 return MOI. ScalarAffineFunction (terms, 0.0 )
753754end
@@ -775,10 +776,8 @@ function MOI.get(
775776 :: MOI.ConstraintFunction ,
776777 ci:: MOI.ConstraintIndex{MOI.VectorOfVariables,S} ,
777778) where {S<: VectorCone }
778- return MOI. VectorOfVariables ([
779- index_of_column (m, col) for
780- col in reorder (columns (m, ci). values, S, true )
781- ])
779+ cols = reorder (columns (m, ci). values, S, true )
780+ return MOI. VectorOfVariables (_col_to_index .(m, cols))
782781end
783782
784783function MOI. get (
@@ -791,15 +790,17 @@ function MOI.get(
791790 throw (MOI. GetAttributeNotAllowed (attr))
792791 end
793792 r = rows (m, ci)
794- ( frow, fcol, fval) = Mosek. getaccftrip (m. task)
793+ frow, fcol, fval = Mosek. getaccftrip (m. task)
795794 constants = Mosek. getaccb (m. task, ci. value)
796795 set = MOI. Utilities. set_with_dimension (S, length (r))
797- terms = [
798- MOI. VectorAffineTerm (
799- reorder (frow[i] - first (r) + 1 , set, false ),
800- MOI. ScalarAffineTerm (fval[i], index_of_column (m, fcol[i])),
801- ) for i in eachindex (frow) if frow[i] in r
802- ]
796+ terms = MOI. VectorAffineTerm{Float64}[]
797+ for (frowi, fcoli, fvali) in zip (frow, fcol, fval)
798+ if frowi in r
799+ row = reorder (frowi - first (r) + 1 , set, false )
800+ term = MOI. ScalarAffineTerm (fvali, _col_to_index (m, fcoli))
801+ push! (terms, MOI. VectorAffineTerm (row, term))
802+ end
803+ end
803804 return MOI. VectorAffineFunction (terms, - reorder (constants, S, false ))
804805end
805806
0 commit comments