source: branches/devel/Bonmin/src/Interfaces/BonIpoptInteriorWarmStarter.cpp @ 83

Last change on this file since 83 was 67, checked in by pbonami, 13 years ago

Update for including the interface for filter.
Everything compiles but not tested yet.
To compile filter interface has to specify --with-filtersqp-lib and with-filtersqp-incdir to point to correct location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 7.6 KB
Line 
1// (C) Copyright International Business Machines Corporation 2006
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// $Id: BonIpoptInteriorWarmStarter.cpp 67 2006-10-17 03:05:15Z pbonami $
6//
7// Authors:  Andreas Waechter          IBM    2006-03-09
8
9#include "BonIpoptInteriorWarmStarter.hpp"
10#include "IpDenseVector.hpp"
11
12#include "IpIpoptData.hpp"
13#include "IpIpoptCalculatedQuantities.hpp"
14namespace Bonmin {
15IpoptInteriorWarmStarter::
16IpoptInteriorWarmStarter(Index n,
17    const Number* x_l, const Number* x_u,
18    Number nlp_lower_bound_inf,
19    Number nlp_upper_bound_inf,
20    bool store_several_iterates)
21    :
22    nlp_lower_bound_inf_(nlp_lower_bound_inf),
23    nlp_upper_bound_inf_(nlp_upper_bound_inf),
24    store_several_iterates_(store_several_iterates),
25    n_(n),
26    n_stored_iterates_(0)
27{
28  x_l_prev_ = new double[n];
29  x_u_prev_ = new double[n];
30
31  for(Index i=0; i<n; i++) {
32    x_l_prev_[i] = x_l[i];
33    x_u_prev_[i] = x_u[i];
34  }
35}
36
37IpoptInteriorWarmStarter::
38~IpoptInteriorWarmStarter()
39{
40  delete [] x_l_prev_;
41  delete [] x_u_prev_;
42}
43
44bool IpoptInteriorWarmStarter::
45UpdateStoredIterates(AlgorithmMode mode,
46    const IpoptData& ip_data,
47    IpoptCalculatedQuantities& ip_cq)
48{
49  // Don't store anything during the restoration phase
50  if (mode==RestorationPhaseMode) {
51    return true;
52  }
53
54  // Get some useful information out of the Ipopt objects
55  Index iter = ip_data.iter_count();
56  Number mu = ip_data.curr_mu();
57  Number nlp_error = ip_cq.curr_nlp_error();
58  Number primal_inf = ip_cq.curr_primal_infeasibility(NORM_MAX);
59  Number dual_inf = ip_cq.curr_dual_infeasibility(NORM_MAX);
60  Number complementarity = ip_cq.curr_complementarity(0., NORM_MAX);
61  if (store_several_iterates_ || n_stored_iterates_==0) {
62    // For now, we just store everything
63    n_stored_iterates_++;
64    stored_iter_.push_back(iter);
65    stored_iterates_.push_back(ip_data.curr());
66    stored_mu_.push_back(mu);
67    stored_nlp_error_.push_back(nlp_error);
68    stored_primal_inf_.push_back(primal_inf);
69    stored_dual_inf_.push_back(dual_inf);
70    stored_compl_.push_back(complementarity);
71  }
72  else {
73    stored_iter_[0] = iter;
74    stored_iterates_[0] = ip_data.curr();
75    stored_mu_[0] = mu;
76    stored_nlp_error_[0] = nlp_error;
77    stored_primal_inf_[0] = primal_inf;
78    stored_dual_inf_[0] = dual_inf;
79    stored_compl_[0] = complementarity;
80  }
81  return true;
82}
83
84bool IpoptInteriorWarmStarter::
85Finalize()
86{
87  // For now, nothing.  Later we could clean up, reduce storage etc.
88  return true;
89}
90
91bool IpoptInteriorWarmStarter::
92WarmStartIterate(Index n, const Number* x_l_new,
93    const Number* x_u_new,
94    IteratesVector& warm_start_iterate)
95{
96  assert(n==n_);
97
98  if (n_stored_iterates_==0) {
99    return false;
100  }
101
102  // For now let's just assume that we want to restore the 4-th latest
103  // iterate from the previous solve
104
105  Index iter_wanted = Max(0, n_stored_iterates_-5);
106
107  SmartPtr<const Vector> prev_x = stored_iterates_[iter_wanted]->x();
108  SmartPtr<const Vector> prev_s = stored_iterates_[iter_wanted]->s();
109  SmartPtr<const Vector> prev_z_L = stored_iterates_[iter_wanted]->z_L();
110  SmartPtr<const Vector> prev_z_U = stored_iterates_[iter_wanted]->z_U();
111  SmartPtr<const Vector> prev_y_c = stored_iterates_[iter_wanted]->y_c();
112  SmartPtr<const Vector> prev_y_d = stored_iterates_[iter_wanted]->y_d();
113  SmartPtr<const Vector> prev_v_L = stored_iterates_[iter_wanted]->v_L();
114  SmartPtr<const Vector> prev_v_U = stored_iterates_[iter_wanted]->v_U();
115
116  const DenseVector* d_x = dynamic_cast<const DenseVector*> (GetRawPtr(prev_x));
117  const DenseVector* d_s = dynamic_cast<const DenseVector*> (GetRawPtr(prev_s));
118  const DenseVector* d_z_L = dynamic_cast<const DenseVector*> (GetRawPtr(prev_z_L));
119  const DenseVector* d_z_U = dynamic_cast<const DenseVector*> (GetRawPtr(prev_z_U));
120  const DenseVector* d_y_c = dynamic_cast<const DenseVector*> (GetRawPtr(prev_y_c));
121  const DenseVector* d_y_d = dynamic_cast<const DenseVector*> (GetRawPtr(prev_y_d));
122  const DenseVector* d_v_L = dynamic_cast<const DenseVector*> (GetRawPtr(prev_v_L));
123  const DenseVector* d_v_U = dynamic_cast<const DenseVector*> (GetRawPtr(prev_v_U));
124
125  const Number* x_vals_prev = d_x->Values();
126  const Number* s_vals_prev = d_s->Values();
127  const Number* z_L_vals_prev = d_z_L->Values();
128  const Number* z_U_vals_prev = d_z_U->Values();
129  const Number* y_c_vals_prev = d_y_c->Values();
130  const Number* y_d_vals_prev = d_y_d->Values();
131  const Number* v_L_vals_prev = d_v_L->Values();
132  const Number* v_U_vals_prev = d_v_U->Values();
133
134  DenseVector* d_x_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.x_NonConst()));
135  DenseVector* d_s_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.s_NonConst()));
136  DenseVector* d_z_L_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.z_L_NonConst()));
137  DenseVector* d_z_U_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.z_U_NonConst()));
138  DenseVector* d_y_c_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.y_c_NonConst()));
139  DenseVector* d_y_d_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.y_d_NonConst()));
140  DenseVector* d_v_L_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.v_L_NonConst()));
141  DenseVector* d_v_U_new = dynamic_cast<DenseVector*> (GetRawPtr(warm_start_iterate.v_U_NonConst()));
142
143  Number* x_vals_new = d_x_new->Values();
144  Number* s_vals_new = d_s_new->Values();
145  Number* z_L_vals_new = d_z_L_new->Values();
146  Number* z_U_vals_new = d_z_U_new->Values();
147  Number* y_c_vals_new = d_y_c_new->Values();
148  Number* y_d_vals_new = d_y_d_new->Values();
149  Number* v_L_vals_new = d_v_L_new->Values();
150  Number* v_U_vals_new = d_v_U_new->Values();
151
152  // Now copy the primal variables from the old to the new problem;
153  // make sure that we take care of the fixed variables
154  Index ix_prev = 0;
155  Index ix_new = 0;
156  Index izL_prev = 0;
157  Index izL_new = 0;
158  Index izU_prev = 0;
159  Index izU_new = 0;
160  for (Index i=0; i<n_; i++) {
161    if (x_l_new[i]<x_u_new[i]) {
162      DBG_ASSERT(x_l_prev_[i]<x_u_prev_[i]);
163      x_vals_new[ix_new] = x_vals_prev[ix_prev];
164      ix_new++;
165      ix_prev++;
166      if (x_l_new[i]>nlp_lower_bound_inf_) {
167        DBG_ASSERT(x_l_prev_[i]>nlp_lower_bound_inf_);
168        z_L_vals_new[izL_new] = z_L_vals_prev[izL_prev];
169        izL_new++;
170        izL_prev++;
171      }
172      if (x_u_new[i]<nlp_upper_bound_inf_) {
173        DBG_ASSERT(x_u_prev_[i]<nlp_upper_bound_inf_);
174        z_U_vals_new[izU_new] = z_U_vals_prev[izU_prev];
175        izU_new++;
176        izU_prev++;
177      }
178    }
179    else if (x_l_prev_[i]<x_u_prev_[i]) {
180      ix_prev++;
181      izL_prev++;
182      izU_prev++;
183    }
184  }
185  DBG_ASSERT(ix_prev==prev_x->Dim());
186  DBG_ASSERT(izL_prev==prev_z_L->Dim());
187  DBG_ASSERT(izU_prev==prev_z_U->Dim());
188  DBG_ASSERT(ix_new==warm_start_iterate.x()->Dim());
189  DBG_ASSERT(izL_new==warm_start_iterate.z_L()->Dim());
190  DBG_ASSERT(izU_new==warm_start_iterate.z_U()->Dim());
191
192  // Now copy all the values for the iterates that don't change in dimension
193  DBG_ASSERT(prev_s->Dim()==warm_start_iterate.s()->Dim());
194  DBG_ASSERT(prev_y_d->Dim()==warm_start_iterate.s()->Dim());
195  DBG_ASSERT(prev_y_d->Dim()==warm_start_iterate.y_d()->Dim());
196  for (Index i=0; i<prev_s->Dim(); i++) {
197    s_vals_new[i] = s_vals_prev[i];
198    y_d_vals_new[i] = y_d_vals_prev[i];
199  }
200  DBG_ASSERT(prev_y_c->Dim()==warm_start_iterate.y_c()->Dim());
201  for (Index i=0; i<prev_y_c->Dim(); i++) {
202    y_c_vals_new[i] = y_c_vals_prev[i];
203  }
204  DBG_ASSERT(prev_v_L->Dim()==warm_start_iterate.v_L()->Dim());
205  for (Index i=0; i<prev_v_L->Dim(); i++) {
206    v_L_vals_new[i] = v_L_vals_prev[i];
207  }
208  DBG_ASSERT(prev_v_U->Dim()==warm_start_iterate.v_U()->Dim());
209  for (Index i=0; i<prev_v_U->Dim(); i++) {
210    v_U_vals_new[i] = v_U_vals_prev[i];
211  }
212
213  return true;
214}
215}
216
Note: See TracBrowser for help on using the repository browser.