Hi,
I’m new to Julia language and I’m trying to replicate an optimization function created in Matlab using fmincom in Julia in order to improve the computation time that is quite huge in Matlab.
I’ve used the JuMP modeling language with the Ipopt solver to specify and optimize my model but i always get the error message: EXIT: Converged to a point of local infeasibility. Problem may be infeasible.
This is my objective function:
function Jfun(k::T...) where {T<:Real}
k0=optimization_data["k0"];
a=optimization_data["a"];
b=optimization_data["b"];
s_sweep=optimization_data["sweep"];
k1=T[k0];
for item in k
push!(k1,item);
end
ds=[s_sweep[i+1]-s_sweep[i] for i in range(start=1,stop=length(s_sweep)-1)];
ah=[0.5*(a[i+1]+a[i]) for i in range(start=1,stop=length(a)-1)];
bh=[0.5*(b[i+1]+b[i]) for i in range(start=1,stop=length(b)-1)];
kh=[0.5*(k1[i+1]+k1[i]) for i in range(start=1,stop=length(k1)-1)];
f_temp=[k1[i+1]-k1[i] for i in range(start=1,stop=length(k1)-1)];
f=[]
for i in range(start=1,stop=length(f_temp))
push!(f,f_temp[i]/ds[i]+ah[i]*kh[i]+bh[i]);
end
Jval=0;
for i in range(start=1,stop=length(f))
Jval+=(f[i]^2)*ds[i];
end
return Jval
end
This is the main of the application:
model = Model((Ipopt.Optimizer));
@variable(model,k[i=1:length(k0guess)],upper_bound=upper_bounds[i+1],lower_bound=lower_bounds[i+1],start=k0guess[i])
register(model,:Jfun,length(k0guess),Jfun;autodiff=true)
# Objective function
@NLobjective(model, Min, Jfun(k...))
register(model,:timeConstrain,length(k0guess),timeConstrain,autodiff=true)
# Equality constraint
@NLconstraint(model,timeConstrain(k...)==0)
# Solve the optimization problem
JuMP.optimize!(model)
After some debugging I found out that in my Julia code, the lower and upper bounds and the initial guess of my objective function can be only numeric values, while in Matlab, those parameters were array of numbers. So, when the optimization is running, I found out that in Matlab the objective function receives the entire array k0guess as k, while in Julia k is an array filled with zeros, because of that the objective function returns a wrong value that is different from the Matlab one.
These are the lines of codes of the objective function that gives me a different result from Matlab:
k1=T[k0];
for item in k
push!(k1,item);
end
Is there a way to emulate the same behavior of Matlab or i have to change my objective function in order to adapt it to compute a single value at a time?
Thank you so much in advance for your help!!