Hi
Thanks, yes:
Code is
using Random
using JuMP
using Ipopt
Random.seed!(1234)
n=1000
data = randn(n)
model = Model(Ipopt.Optimizer)
@variable(model, x)
@variable(model, a) #max distance
@NLexpressions(model, begin
y[ii=1:10], sum( sin(x*data[i]) for i = 1+floor(Int,(n/10)*ii-1):floor(Int,(n/10)*ii) ) # 10 segments y[1:10] - just cumsum
yy[ii=1:9], (-y[ii]+y[ii+1] )^2 # just abs(distance) , but ^2
end)
@NLconstraint(model, [i=1:9],yy[i] <= a) #max distance , 10 segments=9 distances
#@NLconstraint(model, [i=1:9],yy[i] >= 2) #next to implement : slope of process, each segment must raise minimum 2)
@NLobjective(
model,
Min,
a # minimize max distance
)
optimize!(model)
print( objective_value(model) )
value.(y) # currently zeros(10), but when slope added
Usage:
Normaly I just min/max objective function, but in graph (y here) I observe sometimes very strange behaviours. So if graph of process looks like line, it would be very good.
Example:
I have other max objective function working with Ipopt. Sometimes value of y[i] jumps above global optimum, then went down.
From time perspective (y[1]…y[10]), I was curious, if there is (simplyfied
) way to ‘model’ graph.
Image:
(1) Current situation, ignoring graph, only min/max obj (newest y[10]
(2) Better graph
*(3) Line graph
*(4) Best line graph with high obj
( * good solutions)