Hello everyone, I’m currently focused on minimizing the specific consumption of a desalination unit. I’ve formulated an equation that incorporates the various hydraulic and pressure parameters of the system under investigation. I’m in the process of developing a simple code to determine the minimum points for each parameter. I’ve recently tried using the JuMP and Ipopt packages, but unfortunately, they are not working as expected. Could you suggest any other packages that might be helpful for this task?
You need to be much more specific about what did not work to get any useful responses.
this is my code, When I execute it, it gives me errors.
using JuMP, Ipopt
Cs = Model(Ipopt.Optimizer)
#Declaring variables
@variable(Cs, 3500.000277778<= Q_e <= 4500.000277778)
@variable(Cs, 2e5<= PT401 <= 5e5)
@variable(Cs, 45e5<= PT501 <= 70e5)
@variable(Cs, 25e5<= P <= 42.1e5)
@variable(Cs, 1250.000277778<= Qp <= 2200.000277778)
@variable(Cs, 0.8<= R_m <= 0.96)
@variable(Cs, 0.7<= R_p <= 0.9)
@variable(Cs, 45e5<= PT502 <= 56e5)
#setting the objecj=tive
@objective(Cs, Min, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_mR_p))(1/Qp))
#Adding constraints
@constraint(Cs, constraint1, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_mR_p))(1/Qp) <= 3.5)
@constraint(Cs, constraint2, PT502-PT501 <= 4e5)
#Printing the prepared optimization model
print(Cs)
#Solving the optimization problem
JuMP.optimize!(Cs)
what does the error say?
This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.
Number of nonzeros in equality constraint Jacobian…: 0
Number of nonzeros in inequality constraint Jacobian.: 9
Number of nonzeros in Lagrangian Hessian…: 56
Total number of variables…: 8
variables with only lower bounds: 0
variables with lower and upper bounds: 8
variables with only upper bounds: 0
Total number of equality constraints…: 0
Total number of inequality constraints…: 2
inequality constraints with only lower bounds: 0
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 2
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.1465262e+07 1.15e+07 2.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 9.3630406e+06 9.36e+06 1.28e+01 -1.0 1.28e-01 - 2.80e-02 2.49e-01f 1
2 6.4277601e+06 6.43e+06 1.13e+01 -1.0 1.63e-01 - 4.25e-01 3.28e-01f 1
3 5.7652555e+06 5.77e+06 2.18e+01 -1.0 6.40e-01 - 1.90e-01 8.24e-02f 1
4 4.6708055e+06 4.67e+06 5.01e+01 -1.0 5.08e-01 - 9.90e-01 2.44e-01f 1
5 4.5255243e+06 4.53e+06 3.14e+02 -1.0 2.58e+01 - 9.88e-01 8.09e-02h 1
6 4.2647595e+06 4.26e+06 1.25e+03 -1.0 3.98e+04 - 2.28e-01 5.98e-02h 1
7 3.9559026e+06 3.96e+06 3.30e+02 -1.0 2.14e+06 - 1.30e-03 7.28e-02h 1
8 3.6923996e+06 3.69e+06 1.66e+04 -1.0 2.11e+06 - 9.64e-01 6.65e-02f 1
9 3.6829293e+06 3.68e+06 3.43e+06 -1.0 1.21e+06 - 4.64e-01 2.64e-03h 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
10 3.6826617e+06 3.68e+06 3.64e+10 -1.0 1.29e+06 - 8.01e-01 7.52e-05h 1
11r 3.6826617e+06 3.68e+06 1.00e+03 0.0 0.00e+00 - 0.00e+00 3.87e-07R 2
12r 3.6908606e+06 3.69e+06 2.59e+03 0.0 8.06e+06 - 1.66e-01 6.94e-02f 1
13r 3.6937542e+06 3.69e+06 3.32e+03 0.0 1.48e+06 - 5.95e-01 4.61e-01f 1
14r 3.6977536e+06 3.70e+06 7.26e+01 0.0 4.19e+05 - 9.90e-01 1.00e+00f 1
15r 3.6856485e+06 3.69e+06 2.51e-01 -0.7 4.34e+03 - 9.90e-01 1.00e+00f 1
16r 3.6826775e+06 3.68e+06 2.56e-01 -3.1 7.65e+03 - 9.82e-01 1.00e+00f 1
17r 3.6826742e+06 3.68e+06 9.76e-09 -3.1 2.24e+04 - 1.00e+00 1.00e+00h 1
18r 3.6826589e+06 3.68e+06 1.42e-02 -6.9 9.01e+04 - 8.12e-01 1.00e+00f 1
19r 3.6826589e+06 3.68e+06 7.64e-05 -6.9 4.68e+03 - 9.95e-01 1.00e+00h 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
20r 3.6826589e+06 3.68e+06 2.24e-12 -6.9 3.85e+05 - 1.00e+00 1.00e+00h 1
21r 3.6826589e+06 3.68e+06 1.16e-06 -9.0 1.19e+05 - 9.01e-01 1.00e+00h 1
Number of Iterations…: 21
(scaled) (unscaled)
Objective…: 1.1119148000463026e+00 3.6826588716262570e+06
Dual infeasibility…: 1.8194951921996108e+01 6.0261632556345068e+07
Constraint violation…: 1.1119137432821691e+00 3.6826553716262467e+06
Variable bound violation: 9.8364835139364004e-05 9.8364835139364004e-05
Complementarity…: 2.0231348240894247e-08 6.7006171768904332e-02
Overall NLP error…: 1.1119137432821691e+00 6.0261632556345068e+07
Number of objective function evaluations = 25
Number of objective gradient evaluations = 13
Number of equality constraint evaluations = 0
Number of inequality constraint evaluations = 25
Number of equality constraint Jacobian evaluations = 0
Number of inequality constraint Jacobian evaluations = 24
Number of Lagrangian Hessian evaluations = 22
Total seconds in IPOPT = 0.027
EXIT: Converged to a point of local infeasibility. Problem may be infeasible.
termination_status(Cs) = MathOptInterface.LOCALLY_INFEASIBLE
LOCALLY_INFEASIBLE::TerminationStatusCode = 5
And are you sure that that’s not the case, i.e. that the problem is feasible? Have you solved it analytically, or using some other numerical solver?
I used this equation to calculate the actual values for eight train scenarios, and it provided me with correct results. However, I haven’t tested analytical optimization (I haven’t found a suitable method for this problem).
The solver does not support an objective function of type MathOptInterface.ScalarNonlinearFunction.
The left-hand side of the constraint constraint1
is the same as the objective, is this intended? When I removed constraint1
, I got Ipopt to find a solution. Is this constraint expected to be feasible with 3.5 on the right-hand side?
On a technical note, putting the code between three backticks ``` helps with formatting
using JuMP, Ipopt
Cs = Model(Ipopt.Optimizer)
#Declaring variables
@variable(Cs, 3500.000277778<= Q_e <= 4500.000277778)
@variable(Cs, 2e5<= PT401 <= 5e5)
@variable(Cs, 45e5<= PT501 <= 70e5)
@variable(Cs, 25e5<= P <= 42.1e5)
@variable(Cs, 1250.000277778<= Qp <= 2200.000277778)
@variable(Cs, 0.8<= R_m <= 0.96)
@variable(Cs, 0.7<= R_p <= 0.9)
@variable(Cs, 45e5<= PT502 <= 56e5)
#setting the objecj=tive
@objective(Cs, Min, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m*R_p))*(1/Qp))
#Adding constraints
# @constraint(Cs, constraint1, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m*R_p))*(1/Qp) <= 3.5)
@constraint(Cs, constraint2, PT502-PT501 <= 4e5)
# #Printing the prepared optimization model
print(Cs)
#Solving the optimization problem
JuMP.optimize!(Cs)
Normally, constraint1 should be feasible. Anyway, thank you so much, really appreciate it.
Hi @nouha941, welcome to the forum.
You should take a deeper look at your problem. You must have some typos somewhere, because the problem as written is infeasible.
Unless I’ve made a typo, I can simplify your constraint to:
(((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m * R_p)) * (1/Qp)
= ((Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p)) / Qp
= (Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p) / Qp
= (Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p * Qp)
= Q_e * ((PT501 - PT401) - (PT501 - P)) / (R_m * R_p * Qp)
= Q_e * (PT501 - PT401 - PT501 + P) / (R_m * R_p * Qp)
= Q_e * (P - PT401) / (R_m * R_p * Qp)
This has a lower bound of
julia> 3500.000277778 * (25e5 - 5e5) / (0.96 * 0.9 * 2200.000277778)
3.6826597599520995e6
which is much greater than 3.5
Many thanks sir, I really appreciate your help