Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The final g is all 0 #814

Open
yueshinian opened this issue Jan 21, 2025 · 3 comments
Open

The final g is all 0 #814

yueshinian opened this issue Jan 21, 2025 · 3 comments

Comments

@yueshinian
Copy link

Hello, I want to know which constraint was violated when the solution failed. So I obtained g from the interface finalize_solution(). But I found that the values of g are all 0. May I ask why this is happening, and is there any way to avoid this situation?
Any help would be greatly appreciated.

@svigerske
Copy link
Member

Doesn't happen for me.

What does "solution failed" mean? How did it fail, which status code, etc? Is the final solution indeed not feasible? Do the constraints in the final iterate, if any, have values different from zero? ....

@yueshinian
Copy link
Author

Doesn't happen for me.

What does "solution failed" mean? How did it fail, which status code, etc? Is the final solution indeed not feasible? Do the constraints in the final iterate, if any, have values different from zero? ....

I'm so sorry for replying so late. The status code is Ipopt::Maximum_CpuTime_Exceeded. The final solution is not feasible. In fact, the first point violates the constraint.
x_init_[0] = 0.0;
x_l[0] = x_init_[0];
x_u[0] = x_init_[0];
g_l[0] = 0.2;
g[0] = x[0] + 0.1;
And the final values of g are all 0. Thanks.

@svigerske
Copy link
Member

svigerske commented Jan 26, 2025

Doesn't happen for me. If I run test hs071_cpp with max_cpu_time 1e-9 in an ipopt.opt, I get

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

This is Ipopt version 3.14.17, running with linear solver MUMPS 5.7.3.

Number of nonzeros in equality constraint Jacobian...:        4
Number of nonzeros in inequality constraint Jacobian.:        4
Number of nonzeros in Lagrangian Hessian.............:       10

Total number of variables............................:        4
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        4
                     variables with only upper bounds:        0
Total number of equality constraints.................:        1
Total number of inequality constraints...............:        1
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.6109693e+01 1.12e+01 5.28e-01   0.0 0.00e+00    -  0.00e+00 0.00e+00   0

Number of Iterations....: 0

                                   (scaled)                 (unscaled)
Objective...............:   1.6109692919198878e+01    1.6109692919198878e+01
Dual infeasibility......:   5.2759794502408663e-01    5.2759794502408663e-01
Constraint violation....:   1.1243400939696002e+01    1.1243400939696002e+01
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   3.9900000599999998e+00    3.9900000599999998e+00
Overall NLP error.......:   1.1243400939696002e+01    1.1243400939696002e+01


Number of objective function evaluations             = 1
Number of objective gradient evaluations             = 1
Number of equality constraint evaluations            = 1
Number of inequality constraint evaluations          = 1
Number of equality constraint Jacobian evaluations   = 1
Number of inequality constraint Jacobian evaluations = 1
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 0.005

EXIT: Maximum CPU time exceeded.


Solution of the primal variables, x
x[0] = 1.01
x[1] = 4.96
x[2] = 4.96
x[3] = 1.01


Solution of the bound multipliers, z_L and z_U
z_L[0] = 1
z_L[1] = 1
z_L[2] = 1
z_L[3] = 1
z_U[0] = 1
z_U[1] = 1
z_U[2] = 1
z_U[3] = 1


Objective value
f(x*) = 16.1097

Final value of the constraints:
g(0) = 25.0961
g(1) = 51.2434


*** The problem FAILED!

The printed values of g are not all zero.
The code that prints these is

void HS071_NLP::finalize_solution(
SolverReturn status,
Index n,
const Number* x,
const Number* z_L,
const Number* z_U,
Index m,
const Number* g,
const Number* lambda,
Number obj_value,
const IpoptData* ip_data,
IpoptCalculatedQuantities* ip_cq
)
{
// here is where we would store the solution to variables, or write to a file, etc
// so we could use the solution.
// For this example, we write the solution to the console
std::cout << std::endl << std::endl << "Solution of the primal variables, x" << std::endl;
for( Index i = 0; i < n; i++ )
{
std::cout << "x[" << i << "] = " << x[i] << std::endl;
}
std::cout << std::endl << std::endl << "Solution of the bound multipliers, z_L and z_U" << std::endl;
for( Index i = 0; i < n; i++ )
{
std::cout << "z_L[" << i << "] = " << z_L[i] << std::endl;
}
for( Index i = 0; i < n; i++ )
{
std::cout << "z_U[" << i << "] = " << z_U[i] << std::endl;
}
std::cout << std::endl << std::endl << "Objective value" << std::endl;
std::cout << "f(x*) = " << obj_value << std::endl;
std::cout << std::endl << "Final value of the constraints:" << std::endl;
for( Index i = 0; i < m; i++ )
{
std::cout << "g(" << i << ") = " << g[i] << std::endl;
}
}
// [TNLP_finalize_solution]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants