Matrix Constraints in JuMP

Can I write matrix constraints in JUMP using @constraints macro?
While writing this flow constraint Bd*A*δ .== f as one of the constraints in the @constraints macro, I am getting the following error.

ERROR: MethodError: Cannot convert an object of type
Vector{Int64} to an object of type
Closest candidates are:
convert(::Type{T}, ::AbstractRange) where T<:AbstractRange at range.jl:256
convert(::Type{T}, ::HDF5.BlockRange) where T<:AbstractRange at C:\Users\GAGAN MEENA.julia\packages\HDF5\Z859u\src\dataspaces.jl:204
convert(::Type{SL}, ::FillArrays.AbstractFill{T, 1} where T) where SL<:AbstractRange at C:\Users\GAGAN MEENA.julia\packages\FillArrays\eOEVm\src\FillArrays.jl:544

[1] _broadcast_getindex_evalf
@ .\broadcast.jl:670 [inlined]
[2] _broadcast_getindex
@ .\broadcast.jl:653 [inlined]
[3] (::Base.Broadcast.var"#29#30"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(convert), Tuple{Base.RefValue{Type{Base.OneTo}}, Tuple{Base.OneTo{Int64}, Vector{Int64}}}}})(k::Int64)
@ Base.Broadcast .\broadcast.jl:1075
[4] ntuple
@ .\ntuple.jl:49 [inlined]
[5] copy
@ .\broadcast.jl:1075 [inlined]
[6] materialize
@ .\broadcast.jl:860 [inlined]
[7] undef_array(::Type{Matrix{AffExpr}}, ::Base.OneTo{Int64}, ::Vector{Int64})
@ MutableArithmetics C:\Users\GAGAN MEENA.julia\packages\MutableArithmetics\iovKe\src\implementations\LinearAlgebra.jl:387
[8] operate(#unused#::typeof(*), A::Matrix{Float64}, B::JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}})
@ MutableArithmetics C:\Users\GAGAN MEENA.julia\packages\MutableArithmetics\iovKe\src\implementations\LinearAlgebra.jl:419
[9] macro expansion
@ C:\Users\GAGAN MEENA.julia\packages\MutableArithmetics\iovKe\src\rewrite.jl:325 [inlined]
[10] macro expansion
@ C:\Users\GAGAN MEENA.julia\packages\JuMP\Gwn88\src\macros.jl:257 [inlined]
[11] macro expansion
@ C:\Users\GAGAN MEENA.julia\packages\JuMP\Gwn88\src\macros@constraint.jl:119 [inlined]
[12] macro expansion
@ C:\Users\GAGAN MEENA.julia\packages\JuMP\Gwn88\src\macros.jl:393 [inlined]
[13] Scenario_Reconciliation(orig::result_DACCPO, Prob::Chance_Probability, scen::Int64, fmax::Float64)
@ Main e:\IITB\Sem7\Research\Code\DACCPO\Reconciliation.jl:178
[14] top-level scope
@ e:\IITB\Sem7\Research\Code\DACCPO\Main.jl:13

Look in your \DACCPO\Main.jl file in 13th line. You are getting error type conversion.

and learn quoted code posting method to post your code. Please read: make it easier to help you

It seems that you are multiplying a matrix with a JuMP DenseAxisArray.
A DenseAxisArray is created in the @variable macro when the indices are not 1:n. This also means that multiplying a matrix with a DenseAxisArray is not well defined since they don’t have the same indices. Note that the field .data of the DenseAxisArray is a matrix so you could use that to access the container of variables as a Matrix.

Thank you

1 Like