How can I write a constraint that indicates that my variable can only take values that are multiples of 35?
1 Answer
using JuMP, Gurobi
m = Model(Gurobi.Optimizer)
@variable(m, x>=0, Int)
y = 35x
Now you can use y as any other variable in your optimization model.
If you want to have such constraint on the value of the objective (as the link that points to the deleted question) you could do (I reuse x from the previous example):
@variable(m,z1)
@variable(m,z2)
ob = 3z1 + 2z2
@constraint(m, ob == 35x)
@objective(m, Max, ob)
2 Comments
jvm.97
thanks! what if i want that constraint but for each variable? not the sum. I need every number of v[ j ] to be multiple of 35.. The problem i keep having is that v[j] is a Variable Ref
Przemyslaw Szufel
Having
N the size of your variable you could just do @variable(m, x[1:N]>=0, Int); y=35 .* x
f(35 * x)instead off(x) subject to x = 35 * k. In the first case, the value that goes into the function (35 * x) is always a multiple of 35, and you can simply optimize w.r.t. thexdesign variable which is now unconstrained. This can be implemented by multiplying the variable in question by 35 in your objective function.