How Define a Complex JuMP Variable

How can this be done? I remember there was a Complex128 syntax or something, but i couldn’t find how to use it in a JuMP variable.

Here’s my problem, assume i already have the values of Rf, Xlf and Xcf:

Nt = 2;
hmax = 5;
@variable(m, y5[i = 1:Nt,h = 3:2:hmax])
@NLconstraint(m , con8[i = 1:Nt, h = 3:2:hmax], y5[i,h] == 1/(Rf[i]+im*(h*Xlf[i]-Xcf[i]/h)))

I got this error:

ERROR: LoadError: InexactError()
Stacktrace:
 [1] convert at .\complex.jl:31 [inlined]
 [2] push!(::Array{Float64,1}, ::Complex{Bool}) at .\array.jl:646
 [3] parseNLExpr_runtime(::JuMP.Model, ::Complex{Bool}, ::Array{ReverseDiffSparse.NodeData,1}, ::Int64, ::Array{Float64,1}) at C:\Users\Muril\.julia\v0.6\JuMP\src\parsenlp.jl:196
 [4] macro expansion at C:\Users\Muril\.julia\v0.6\JuMP\src\parsenlp.jl:226 [inlined]
 [5] macro expansion at C:\Users\Muril\.julia\v0.6\JuMP\src\macros.jl:1201 [inlined]
 [6] anonymous at .\<missing>:?
 [7] include_string(::String, ::String) at .\loading.jl:522
 [8] include_string(::Module, ::String, ::String) at C:\Users\Muril\.julia\v0.6\Compat\src\Compat.jl:88
 [9] (::Atom.##112#116{String,String})() at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:109
 [10] withpath(::Atom.##112#116{String,String}, ::String) at C:\Users\Muril\.julia\v0.6\CodeTools\src\utils.jl:30
 [11] withpath(::Function, ::String) at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:38
 [12] hideprompt(::Atom.##111#115{String,String}) at C:\Users\Muril\.julia\v0.6\Atom\src\repl.jl:67
 [13] macro expansion at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:106 [inlined]
 [14] (::Atom.##110#114{Dict{String,Any}})() at .\task.jl:80
while loading C:\Users\Muril\Desktop\Murilo\UFPE\Dissertação\Julia\Arquivos Feitos\teste_otimização_matriz_3_dimensões.jl, in expression starting on line 69

Is this related to y5 not being defined as a complex variable?

JuMP can only solve problems with real variables. You should reformulate the problem in polar form, or add two JuMP variables, one for the real part and one for the imaginary part.

1 Like

There are any plans to make complex variables work on JuMP?

I don’t know if i understood correctly what you said, but i guess my problem can’t be solved?

I have a restriction in the form of:

A*x = b

Where A and b are a matrix and a vector, respectively, full of complex numbers inside of them (for example, that variable y5 is inside the matrix A).

There are any plans to make complex variables work on JuMP?

There are no plans from the main JuMP developers to add support complex variables AFAIK.

I don’t know if i understood correctly what you said, but i guess my problem can’t be solved?

What Oscar said is that you can still model your problem, but you will need to decompose the complex variables in some combination of real numbers with something like a polar or rectangular decomposition. This is not only doable but it has already been done in some packages like PowerModels.jl

Going back to:

There are any plans to make complex variables work on JuMP?

In this work [slides/video] presented at JuMP-dev workshop, the author did something along thoses lines. It is not officially supported by JuMP though.

Creating JuMP extensions to support complex variables would certainly be appreciated.