4

enter image description here

Hello fellows, i am learning Julia and integer programing but i am stuck at one point

How to model "then" in julia-jump for integer programing leanring.

Stuck here here

#Define the variables of the model
@variable(mo, x[1:N,1:S], Bin)
@variable(mo, a[1:S]>=0) 
  

#Assignment constraint
@constraint(mo, [i=1:N], sum(x[i,j] for j=1:S) == 1)

#@constraint (mo, PLEASE HELP )
sana ullah
  • 43
  • 3
  • 1
    How about: `x[i,j] <= a[j]/s[i]^2` (not sure what the `s[i]`s are from the question) – Dan Getz Nov 02 '22 at 19:18
  • https://jump.dev/JuMP.jl/stable/manual/constraints/#Complementarity-constraints may be what you are looking for – Bill Nov 02 '22 at 19:29
  • 1
    The condition `x[i,j] <= a[j]/s[i]^2` above can also be written as `x[i,j] - (1/s[i]^2)*a[j] <= 0` in a more standard form. – Dan Getz Nov 02 '22 at 23:05

1 Answers1

3

In cases like this you usually need to use Big-M constraints So this will be:

a_ij >= s_i^2 - M*(1-x_ij)

where M is a "big enough" number. This means that if x_ij == 0 the inequality will always be true (and hence kind of turned-off). On the other hand when x_ij == 1 the M-part will be zeroed and the equation will hold.

In JuMP terms the code will look like this:

const M = 10_000
@constraint(mo, [i=1:N, j=1:S], a[i, j] >= s[i]^2 - M*(1 - x[i, j]))

However, if s[i] is an external parameter rather than model variable you could simply use x[i,j] <= a[j]/s[i]^2 proposed by @DanGetz. However when s[i] is @variable you really want to avoid dividing or multiplying variables by each other. So this big M approach is more general across use cases.

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Thanks a lot fo detailed explanation :) it helped. – sana ullah Nov 03 '22 at 20:19
  • in additon: what if i want to Introduce the variable y[i,j] defined by y[i,j] = a[j]*x[i,j] ... how would i rewrite its objective function with linear objective and linear constraints.? i am tring to solve an excercies problem for learning. thanks already fro your support. – sana ullah Nov 03 '22 at 20:23