Complex objective functions #277
-
Hi, I'm trying to implement an # bezier curve
t = 0:.001:1
P0_x = -750
P1_x = -350
P2_x = -350
P3_x = 3000
P0_y = 1
P1_y = 0
P2_y = 0
P3_y = 1
Px(t) = P0_x * (1 - t)^3 + P1_x * 3(1 - t)^2 * t + P2_x * 3(1 - t) * t^2 + P3_x * t^3
Py(t) = P0_y * (1 - t)^3 + P1_y * 3(1 - t)^2 * t + P2_y * 3(1 - t) * t^2 + P3_y * t^3
X = Px.(t)
cost(Fu) = Py(
argmin(abs.(X .- Fu))
)
@objective(model, Min, ∫(SF + α*cost(Fu), s))
optimize!(model) However I then get this error:
I've tried changing it to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The problem is that In this case, we cannot register directly since @register(model, cost(Fu)) And then use it when defining the objective. |
Beta Was this translation helpful? Give feedback.
-
it worked perfectly, thank you! |
Beta Was this translation helpful? Give feedback.
The problem is that
argmin
is not one of the accepted nonlinear functions. You can always check withall_registered_functions
to see what functions can be used to build nonlinear expressions. Like JuMP, we can register new nonlinear functions to use. A current limitation of this interface is that each function must be scalar valued (not vector inputs/outputs). We hope to remove this limitation in the relatively near future (#229).In this case, we cannot register directly since
argmin
is vector valued. However, ifFu
is a scalar (or we can easily enumerate it with scalar components) then we can register the cost function:And then use it when defining the object…