# How do I write @variable(z=x+x)?

Hi,
I am trying to solve a min-max optimisation problem that requires me to add in a constraint

How do I assign a constraint such that a variable equals to another variable?

Hi there,

I’m not entirely sure what you mean by an equality in the objective function, but here’s how I would write your model:

``````model = Model()
@variable(model, x[1:2] >= 0, Int)
@variable(model, z)
@constraint(model, z == x)           # Note sure which one of these you meant
@constraint(model, z == 8x + 5x)  #
@constraint(model, 8x + 1.5x <= z)
@constraint(model, x + x <= 6)
@objective(model, Max, z)
``````

If that isn’t helpful, perhaps you could explain in a bit more detail what you’re trying to achieve?

3 Likes

Here is the equation i was trying to solve:

What I have done so far on Julia-Jump

``````m = Model(Mosek.Optimizer)
@objective(m, Min, Z);
@variable(m, Z);
@variable(m, F[1:14]>=0);
#I have only included a portion of the constriant
@constraint(m,8*F+1.5*F+10*F <= Z);
print(m)
``````

However, I face the error

``````
UndefVarError: Z not defined

Stacktrace:
 macro expansion
 macro expansion
 top-level scope
@ In:2
 eval
@ .\boot.jl:373 [inlined]
 include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
``````

Swapping the order of statements

``````using JuMP

m = Model()
@variable(m, Z);
@variable(m, F[1:14]>=0);
#I have only included a portion of the constriant
@constraint(m,8*F+1.5*F+10*F <= Z);
@objective(m, Min, Z);
print(m)
``````

seems to help.One tip: if you want to know what the macros (`@variable` etc.) are doing you can use `@macroexpand`.

2 Likes

thanks sosososososososo much!!

I don’t really understand the problem. Are these coupled as a bilevel program? Or do you want to solve two separate problems? First to find an upper bound on `Z`, and then to find a lower bound?