1

How can I write a constraint that indicates that my variable can only take values ​​that are multiples of 35?

6
  • Not sure if it makes sense, but you could try optimizing f(35 * x) instead of f(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. the x design variable which is now unconstrained. This can be implemented by multiplying the variable in question by 35 in your objective function. Commented Oct 26, 2022 at 19:43
  • Great idea, sadly it doesn't work for the problem i'm trying to solve :( Commented Oct 26, 2022 at 19:46
  • Does this answer your question? I need feasible solutions to be multiples of a number Julia Commented Oct 26, 2022 at 19:49
  • @SundarR, no i doesn't! Commented Oct 26, 2022 at 19:54
  • 1
    @jvm.97, posting the same question twice is frowned upon. You could also try asking on Julia's Discourse in the "Optimization" section: discourse.julialang.org/c/domain/opt/13 Commented Oct 26, 2022 at 20:10

1 Answer 1

1
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)
Sign up to request clarification or add additional context in comments.

2 Comments

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
Having N the size of your variable you could just do @variable(m, x[1:N]>=0, Int); y=35 .* x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.