Implementing a squarewave: Can’t take remainder of InfiniteOpt.GeneralVariableRef #337
Replies: 1 comment 1 reply
-
Hi @codercahol, sorry for the late response (I missed the notification for this post). Like JuMP, InfiniteOpt is a symbolic optimization language where expressions like However, since your In your case we can write: function sqw(t; period::Float64=1, duty::Float64=0.5)
return t % period < duty*period ? 1.0 : 0.0
end
model = InfiniteModel()
@infinite_parameter(model, t in [0 , T], num_supports = n)
# create a parameter function called wrapped_sqw that uses sqw with infinite parameter t as an input
@parameter_function(model, wrapped_sqw == sqw(t))
@constraint(model, ∂(x, t) == wrapped_sqw) An alternative, but equivalent syntax is: function sqw(t; period::Float64=1, duty::Float64=0.5)
return t % period < duty*period ? 1.0 : 0.0
end
model = InfiniteModel()
@infinite_parameter(model, t in [0 , T], num_supports = n)
# use parameter_function to embed sqw(t) within the constraint expression
@constraint(model, ∂(x, t) == parameter_function(sqw, t)) |
Beta Was this translation helpful? Give feedback.
-
I have a squarewave implemented like so:
I am running an InfiniteOpt.jl optimization where I pass in
sqw
as a parameter and call it with an infinite parameter:I get the error
Clearly, the
rem
has not been implemented for InfiniteOptSo I have two options:
rem
for theGeneralVariableRef
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?
P.S. - cross-posted it on the Julia forums
Beta Was this translation helpful? Give feedback.
All reactions