Search code examples
constraintsjuliajulia-jump

add a constraint in JuMP


I'm trying to add a constraint to a JuMP model in Julia as follows:

@constraint(m, sum{z[i,j]>=2, i in N, j in K})

where N and K are two sets.

But, when I debug it, I get the following error message.

LoadError: In @constraint(m,sum{z[i,j] >= 2,i in N,j in K}): Constraints must be in one of the following forms:
   expr1 <= expr2
   expr1 >= expr2
   expr1 == expr2
   lb <= expr <= ub
while loading /Users/user/Dropbox/Model/ip.jl, in expression starting on line 51
 in include_string(::String, ::String) at loading.jl:441
 in include_string(::String, ::String) at sys.dylib:?
 in include_string(::Module, ::String, ::String) at eval.jl:34
 in (::Atom.##59#62{String,String})() at eval.jl:73
 in withpath(::Atom.##59#62{String,String}, ::String) at utils.jl:30
 in withpath(::Function, ::String) at eval.jl:38
 in macro expansion at eval.jl:71 [inlined]
 in (::Atom.##58#61{Dict{String,Any}})() at task.jl:60

Can someone please help me to resolve this error?


Solution

  • I believe you meant to write: @constraint(m, sum{z[i,j], i in N, j in K}>=2)

    The inequality should be outside the sum. Because you want the sum of all values, to be at least 2.