# Sigmoid function in optimization problem

Hi! I’m using Ipopt to solve a NL optimization problem.
I need binary variables but I’m using a sigmoid to avoid transforming my problem into a MINLP.
I made a MWE in which there are two variables (x1 and x2).
The sigmoid function is inserted in NLconstraint and it is used to activate x1 only if it is bigger than a threshold value.
In the example if the sigmoid function is excluded from the code:

• x1 is bigger than the threshold value
• the objective value is 17.9
If the sigmoid function is used
• x1 assumes a value near zero.
• the objective value is 36

Since in the first configuration the value of x1 is bigger than 200 (so the term sigm(x1) should assume value 1), why is the solution not confirmed also in the second test?

Thanks

``````using JuMP
using Ipopt

#INPUT DATA
Nvar=2
smin=200 #threshold value
v=180
C1=0.029 #cost1
C2=0.2 #cost2
c1=1e-5 #coefficient 1
c2=0.4  #coefficient 2

#JUMP MODEL
model = Model(with_optimizer(Ipopt.Optimizer))
@variable(model, x1,lower_bound=0, upper_bound=350)
@variable(model, x2,lower_bound=0, upper_bound=Inf)

#OBJECTIVE FUNCTION
@NLobjective(model, Min, C1*x1 + C2*x2)

#SIGMOID FUNCTION
sigm(z) = 1.0 / (1.0 + exp(-1*(z-smin)))
register(model, :sigm, 1, sigm; autodiff = true)

#CONSTRAINT
@NLconstraint(model, con1 ,
sigm(x1)* #comment to exclude sigmoid function
(c1*x1^2+ c2*x1)+ x2- v==0)

optimize!(model)

println("objective value= ",objective_value(model))
println("x1= ",value(x1))
println("x2= ",value(x2))
``````

You’re model is non-convex. Therefore, Ipopt is not guaranteed to find the global optimal solution.

If you keep the sigmoid, but use `set_start_value(x1, 350.0)`, Ipopt will converge to the other local optima.

1 Like

Thank you so much!