# Silly question regarding vectorized syntax [JUMP]

Hello everyone!

I’m having some trouble with some basic concepts about vectorized syntax.

My data were structured this way (just to show that everything is in matrix form):

`````` U  = [  ATumor    zeros(tr, tr) zeros(tr, gr) zeros(tr, rr);
-ATumor      -I          zeros(tr, gr) zeros(tr, rr);
ACritical zeros(gr, tr)    -I         zeros(gr, rr);
ARegular  zeros(rr, tr) zeros(rr, gr)     -I       ]
u  = [TUB; -TLB; CUB; RUB]
lb = [zeros(tc); zeros(tr); -CUB; zeros(rr)]
ub = [Inf * ones(tc); TLB; Inf * ones(gr); Inf * ones(rr)]
c  = [zeros(tc,1); omega * ones(tr); ones(gr); ones(rr)]
``````

And the commands that I tried with JuMP were:

``````model = Model(CPLEX.Optimizer)
@variable(model, x[1:size_p], lower_bound = lb, upper_bound = ub)
@constraint(model, U * x .<= u)
@objective(model, Min, c' * x)
``````

But I got the following error message `"Cannot `convert` an object of type Array{Float64,1} to an object of type Float64"` at the line with “@variable

As far as I know, this is happening because JuMP is not seeing my variable as a vector. What is the appropriate syntax for that?

The syntax is

``````@variable(model, x[i=1:size_p], lower_bound = lb[i], upper_bound = ub[i])
``````

There is an open issue to improve the error message: Better error messages for vector variable bounds · Issue #2056 · jump-dev/JuMP.jl · GitHub

Your model might be more readable if you wrote it out in blocks, instead of one giant matrix:

``````model = Model(CPLEX.Optimizer)
@variables(model, begin
0 <= x1[i=1:tc]
0 <= x2[i=1:tr] <= -CUB[i]
-CUB[i] <= x3[i=1:gr]
0 <= x4[i=1:rr]
end)
@constraints(model, begin
ATumor * x1 .<= TUB
ATumor * x1 .>= TLB .- x2
ACritical * x1 .<= CUB .+ x3
ARegular * x1 .<= RUB .+ x4
end)
@objective(model, Min, omega * sum(x2) + sum(x3) + sum(x4))
``````
3 Likes