1 | #include "BonTNLPSolver.hpp" |
---|
2 | #include "IpBlas.hpp" |
---|
3 | namespace Bonmin{ |
---|
4 | using namespace Ipopt; |
---|
5 | |
---|
6 | TNLPSolver::TNLPSolver() |
---|
7 | { |
---|
8 | } |
---|
9 | |
---|
10 | TNLPSolver::~TNLPSolver() |
---|
11 | {} |
---|
12 | |
---|
13 | |
---|
14 | bool |
---|
15 | TNLPSolver::zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP>& tnlp, ReturnStatus &optimizationStatus) |
---|
16 | { |
---|
17 | |
---|
18 | int n,m,dum1, dum2; |
---|
19 | Ipopt::TNLP::IndexStyleEnum dum3; |
---|
20 | tnlp->get_nlp_info(n,m,dum1, dum2, dum3); |
---|
21 | double * x_l = new double[n]; |
---|
22 | double * x_u = new double[n]; |
---|
23 | double * g_l = new double[m]; |
---|
24 | double * g_u = new double[m]; |
---|
25 | |
---|
26 | tnlp->get_bounds_info(n, x_l, x_u, m, g_l , g_u); |
---|
27 | |
---|
28 | |
---|
29 | for(int i = 0 ; i < n ; i++) { |
---|
30 | if(x_u[i] - x_l[i] > 1e-5) |
---|
31 | { |
---|
32 | delete [] x_l; |
---|
33 | delete [] x_u; |
---|
34 | delete [] g_l; |
---|
35 | delete [] g_u; |
---|
36 | return 0; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | //Problem has no variables just check if the unique solution given by the bounds is |
---|
41 | // feasible or not. |
---|
42 | double obj_value; |
---|
43 | |
---|
44 | tnlp->eval_f(n, x_l, true, obj_value); |
---|
45 | |
---|
46 | double * x_sol = new double[n]; |
---|
47 | |
---|
48 | |
---|
49 | IpBlasDcopy(n, x_l, 1, x_sol, 1); |
---|
50 | |
---|
51 | delete [] x_l; |
---|
52 | delete [] x_u; |
---|
53 | |
---|
54 | double * g_sol = new double [m]; |
---|
55 | |
---|
56 | tnlp->eval_g(n, x_sol, true, m, g_sol); |
---|
57 | |
---|
58 | optimizationStatus = solvedOptimal; |
---|
59 | for(int i = 0 ; i < m ; i++) { |
---|
60 | if(g_sol[i] - g_l[i] < - 1e-07 || g_sol[i] - g_u[i] > 1e-07) { |
---|
61 | optimizationStatus = provenInfeasible; |
---|
62 | |
---|
63 | delete [] g_l; |
---|
64 | delete [] g_u; |
---|
65 | double * lam = new double[m]; |
---|
66 | CoinFillN(lam,m,0.); |
---|
67 | double * z = new double[n]; |
---|
68 | CoinFillN(z,n,0.); |
---|
69 | tnlp->finalize_solution(Ipopt::LOCAL_INFEASIBILITY, |
---|
70 | n, x_sol, NULL, NULL, |
---|
71 | m, g_sol, NULL, obj_value); |
---|
72 | delete [] lam; |
---|
73 | delete [] z; |
---|
74 | delete [] g_sol; |
---|
75 | delete [] x_sol; |
---|
76 | |
---|
77 | return 1; |
---|
78 | } |
---|
79 | } |
---|
80 | delete [] g_l; |
---|
81 | delete [] g_u; |
---|
82 | |
---|
83 | double * lam = new double[m]; |
---|
84 | CoinFillN(lam,m,0.); |
---|
85 | double * z = new double[n]; |
---|
86 | CoinFillN(z,n,0.); |
---|
87 | tnlp->finalize_solution(Ipopt::SUCCESS, |
---|
88 | n, x_sol, z, z, |
---|
89 | m, g_sol, lam, obj_value); |
---|
90 | delete [] lam; |
---|
91 | delete [] z; |
---|
92 | delete [] g_sol; |
---|
93 | delete [] x_sol; |
---|
94 | return 1; |
---|
95 | } |
---|
96 | |
---|
97 | void |
---|
98 | TNLPSolver::UnsolvedError::printError(std::ostream &os) |
---|
99 | { |
---|
100 | os<<solverName()<<" exited with error code "<<errorNum_<<" "<<errorName()<<std::endl; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | }//end namespace Bonmin |
---|
105 | |
---|