Variables declaration in JuliaPro 1.5.2-1

When compiling @variabel on my model, julia displays the following message

Expected ModeloDeterministico to be a JuMP model, but it has type DataType
error(::String, ::Type{T} where T) at error.jl:42
validmodel(::Type{T} where T, ::Symbol) at macros.jl:279
top-level scope at macros.jl:284

Is there another way to declare variables?
I tried to follow a macro but the message kept showing

The error message is telling you that ModeloDeterministico should be an instance of type JuMP.Model, but you actually have a type. If you can create a reproducible example of the problem, it will be easier for us to figure out what went wrong.

Most likely, you have something like:

# This makes `ModeloDeterministico` just another name for the *type* Model
ModeloDerministico = Model

instead of:

# This actually creates a new *instance* of a `Model`
ModeloDerministico = Model()
3 Likes
using JuMP,Cbc
ModelD = Model()
ModelD = Cbc.Optimizer

a = 1:4
A = a

@variable(ModelD,b[A], lower_bound=0, Bin)

In the first compilation this error appeared: In @variable(ModelD,b[A],lower_bound = 0,Bin): Unrecognized keyword argument lower_bound

And in the second compilation this error appeared again: Expected ModeloD to be a JuMP model, but it has type DataType

Which version of JuMP are you using? The syntax you are using is for JuMP v0.19 and higher

This line is the problem. You are making ModelD just an alias for the type Cbc.Optimizer.

Understand. I put Cbc.Optimizer because it was a suggestion that appeared in Julia for the compilation

@rdeits Was this the correct way?

ModelD = Model(with_optimizer(Cbc.Optimizer))

@blegat I’m using JuliaPro 1.5.2-1

Please read the documentation: https://jump.dev/JuMP.jl/stable/quickstart/

You want ModelD = Model(Cbc.Optimizer).

1 Like

Even though I used ModelD = Model (Cbc.Optimizer) the error message continues: MethodError: no method matches Model (:: Type {Cbc.Optimizer})

I did until the update and the package rm and add again but the error continues.

using JuMP,Cbc
ModeloD = Model()
ModeloD = Model(Cbc.Optimizer)
a = 1:4
A = a
@variable(ModeloD,b[A],lower_bound=0,Bin)

After updating packages, you need to close Julia and re-open for the changes to take effect. You need JuMP 0.21 for Model(Cbc.Optimizer) to work.

Note that discourse has a search function. This question has been asked multiple times recently:

2 Likes