1

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

jvm.97
  • 247
  • 1
  • 7
  • 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. – ForceBru Oct 26 '22 at 19:43
  • Great idea, sadly it doesn't work for the problem i'm trying to solve :( – jvm.97 Oct 26 '22 at 19:46
  • Does this answer your question? [I need feasible solutions to be multiples of a number Julia](https://stackoverflow.com/questions/74212873/i-need-feasible-solutions-to-be-multiples-of-a-number-julia) – Sundar R Oct 26 '22 at 19:49
  • @SundarR, no i doesn't! – jvm.97 Oct 26 '22 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: https://discourse.julialang.org/c/domain/opt/13 – ForceBru Oct 26 '22 at 20:10
  • @jvm.97 The previous one was an auto-generated comment that StackOverflow posted when I marked this question as a duplicate of your other post. (It's a pretty annoying feature and rarely useful.) – Sundar R Oct 27 '22 at 05:10

1 Answers1

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)
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62