Search code examples
optimizationjuliajulia-jump

How can i use the rem function with a variable?


i want to use the rem function with every element in a string v[j], i tried with rem(v[j],3) but i get the following error MethodError: no method matching rem(::VariableRef, ::Int64). Can i use rem with a string? is there any other function that does the same?


Solution

  • You cannot use rem with JuMP variables. Use a mixed-integer linear reformulation instead:

    model = Model()
    @variable(model, x)
    @variable(model, y, Int)
    @variable(model, rem)
    @constraint(model, x == 3y + rem)
    

    p.s. Since you've posted a few questions in quick succession, come join the JuMP community forum: https://discourse.julialang.org/c/domain/opt/13. It has more JuMP-specific questions than stack overflow