optimizationjuliaglpkjulia-jumpcost-based-optimizer

how to write "then" as IP constraint in Julia


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 )

Solution

  • 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.