How do I write @variable(z=x[1]+x[2])?

Hi there,

Since this is your first post, please read: Please read: make it easier to help you. It has some advice on how to write a good question.

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[1])           # Note sure which one of these you meant 
@constraint(model, z == 8x[1] + 5x[2])  # 
@constraint(model, 8x[1] + 1.5x[2] <= z)
@constraint(model, x[1] + x[2] <= 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