Implementing a squarewave: Can't take remainder of InfiniteOpt.GeneralVariableRef

I have a squarewave implemented like so:

function sqw(t; period::Float64=1, duty::Float64=0.5)
	return t % period < duty*period ? 1.0 : 0.0
end

I am running an InfiniteOpt.jl optimization where I pass in sqw as a parameter and call it with an infinite parameter:

@infinite_parameter(model, t ∈ [0, T], num_supports = n)
@constraint(model, ∂(x, t) == sqw(t))

I get the error

MethodError: no method matching rem(::InfiniteOpt.GeneralVariableRef, ::Float64)

Clearly, the rem has not been implemented for InfiniteOpt

So I have two options:

  1. find another way to model the signal
  2. implement rem for the GeneralVariableRef

If #1 is do-able in a InfiniteOpt.jl compatible way, I would love to hear suggestions.

Otherwise, how can I get started on #2?

Hi @lpz18,

See my post on the InfiniteOpt forum for the solution: Implementing a squarewave: Can’t take remainder of InfiniteOpt.GeneralVariableRef · infiniteopt/InfiniteOpt.jl · Discussion #337 · GitHub

2 Likes