ConicBundle
InteriorPointBlock.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_INTERIORPOINTBLOCK_HXX
4 #define CONICBUNDLE_INTERIORPOINTBLOCK_HXX
5 
13 #include "symmat.hxx"
14 #include "CBout.hxx"
15 
16 namespace ConicBundle {
17 
22 
30 class InteriorPointBlock: public virtual CBout
31 {
32 protected:
40  CH_Matrix_Classes::Real abseps=1e-10) const;
41 
49  CH_Matrix_Classes::Real abseps=1e-10) const;
50 
53  CH_Matrix_Classes::Real& max_nbh,
54  CH_Matrix_Classes::Real nbh_ubnd,
56  CH_Matrix_Classes::Real mu_xdzpdxz,
58  CH_Matrix_Classes::Real nrmsqr_xz,
59  CH_Matrix_Classes::Real nrmsqr_xdzpdxz,
60  CH_Matrix_Classes::Real nrmsqr_dxdz,
61  CH_Matrix_Classes::Real ip_xz_xdzpdxz,
62  CH_Matrix_Classes::Real ip_xz_dxdz,
63  CH_Matrix_Classes::Real ip_dxdz_xdzpdxz) const;
64 
65 public:
67  InteriorPointBlock(CBout* cb=0,int cbinc=-1):CBout(cb,cbinc){}
68 
70  virtual ~InteriorPointBlock();
71 
73  virtual CH_Matrix_Classes::Integer get_vecdim() const =0;
74 
76  virtual int center_x(CH_Matrix_Classes::Real val,bool add=false)=0;
77 
79  virtual int center_z(CH_Matrix_Classes::Real val,bool add=false)=0;
80 
82  virtual int set_x(const CH_Matrix_Classes::Matrix& vec,
83  CH_Matrix_Classes::Integer startindex,
84  CH_Matrix_Classes::Real& add_center_value)=0;
85 
87  virtual int set_z(const CH_Matrix_Classes::Matrix& vec,
88  CH_Matrix_Classes::Integer startindex,
89  CH_Matrix_Classes::Real& add_center_value)=0;
90 
92  virtual int vecgetsax(CH_Matrix_Classes::Matrix& vec,
93  CH_Matrix_Classes::Integer startindex,
95  bool add=false)=0;
96 
98  virtual int vecgetsaz(CH_Matrix_Classes::Matrix& vec,
99  CH_Matrix_Classes::Integer startindex,
101  bool add=false)=0;
102 
104  virtual int get_mu_info(CH_Matrix_Classes::Integer& mudim,
106  CH_Matrix_Classes::Real& tr_xdzpdxz,
107  CH_Matrix_Classes::Real& tr_dxdz,
108  CH_Matrix_Classes::Real& min_xz,
109  CH_Matrix_Classes::Real& max_xz) const=0;
110 
112  virtual int get_nbh_info(CH_Matrix_Classes::Integer mudim,
114  CH_Matrix_Classes::Real tr_xdzpdxz,
115  CH_Matrix_Classes::Real tr_dxdz,
116  CH_Matrix_Classes::Real nbh_ubnd,
118  CH_Matrix_Classes::Real& max_nbh,
119  CH_Matrix_Classes::Real& nrmsqr_xz,
120  CH_Matrix_Classes::Real& nrmsqr_xdzpdxz,
121  CH_Matrix_Classes::Real& nrmsqr_dxdz,
122  CH_Matrix_Classes::Real& ip_xz_xdzpdxz,
123  CH_Matrix_Classes::Real& ip_xz_dxdz,
124  CH_Matrix_Classes::Real& ip_dxdz_xdzpdxz) const=0;
125 
126 
128  virtual int linesearch(CH_Matrix_Classes::Real& alpha) const=0;
129 
131  virtual int add_muxinv(CH_Matrix_Classes::Matrix& rhs,
132  CH_Matrix_Classes::Integer startindex,
134  CH_Matrix_Classes::Real rhscorr,
135  bool minus=false)=0;
136 
138  virtual int set_dx(const CH_Matrix_Classes::Matrix& rhs,CH_Matrix_Classes::Integer startindex)=0;
139 
141  virtual int set_dx_xizsolverhs(const CH_Matrix_Classes::Matrix& rhs,
142  CH_Matrix_Classes::Integer startindex)=0;
143 
145  virtual int apply_xizinv(CH_Matrix_Classes::Matrix& rhs,
146  CH_Matrix_Classes::Integer startindex,
147  bool minus=false)=0;
148 
150  virtual int apply_xiz(CH_Matrix_Classes::Matrix& rhs,
151  CH_Matrix_Classes::Integer startindex,
152  bool minus=false)=0;
153 
155  virtual int do_step(CH_Matrix_Classes::Real alpha)=0;
156 
157 
159  virtual int add_AxizinvAt(const CH_Matrix_Classes::Matrix& A,
160  CH_Matrix_Classes::Symmatrix& globalsys,
161  bool minus=false,
162  bool Atrans=false)=0;
163 
165  virtual int add_xiz(CH_Matrix_Classes::Symmatrix& globalsys,
166  CH_Matrix_Classes::Integer startindex,
167  bool minus=false)=0;
168 
169  //---------------------- mainly for testing
170 
172  virtual int get_vecx(CH_Matrix_Classes::Matrix& vecx,CH_Matrix_Classes::Integer startindex)=0;
173 
175  virtual int get_vecz(CH_Matrix_Classes::Matrix& vecz,CH_Matrix_Classes::Integer startindex)=0;
176 
178  virtual int get_vecdx(CH_Matrix_Classes::Matrix& vecdx,CH_Matrix_Classes::Integer startindex)=0;
179 
181  virtual int get_vecdz(CH_Matrix_Classes::Matrix& vecdz,CH_Matrix_Classes::Integer startindex)=0;
182 
183 
184 };
185 
186  //--------------------------------------------------------
193  CH_Matrix_Classes::Real mu_xdzpdxz,
194  CH_Matrix_Classes::Real mu_dxdz,
195  CH_Matrix_Classes::Real mu_at_one,
196  CH_Matrix_Classes::Real nbh_ubnd,
198  CH_Matrix_Classes::Real& max_nbh,
199  CH_Matrix_Classes::Real& nrmsqr_xz,
200  CH_Matrix_Classes::Real& nrmsqr_xdzpdxz,
201  CH_Matrix_Classes::Real& nrmsqr_dxdz,
202  CH_Matrix_Classes::Real& ip_xz_xdzpdxz,
203  CH_Matrix_Classes::Real& ip_xz_dxdz,
204  CH_Matrix_Classes::Real& ip_dxdz_xdzpdxz)
205  {
206  CH_Matrix_Classes::Real xz=x*z-mu_xz;
207  CH_Matrix_Classes::Real xdzpdxz=x*dz+dx*z-mu_xdzpdxz;
208  CH_Matrix_Classes::Real dxdz=dx*dz-mu_dxdz;
209  nrmsqr_xz+=CH_Matrix_Classes::sqr(xz);
210  nrmsqr_xdzpdxz+=CH_Matrix_Classes::sqr(xdzpdxz);
211  nrmsqr_dxdz+=CH_Matrix_Classes::sqr(dxdz);
212  ip_xz_xdzpdxz+=xz*xdzpdxz;
213  ip_xz_dxdz+=xz*dxdz;
214  ip_dxdz_xdzpdxz+=dxdz*xdzpdxz;
215 
216  if (x+alpha*dx<CH_Matrix_Classes::eps_Real*mu_xz)
218  if (z+alpha*dz<CH_Matrix_Classes::eps_Real*mu_xz)
220  if (alpha>CH_Matrix_Classes::eps_Real){
221  CH_Matrix_Classes::Real otheta=std::fabs(xz)/mu_xz;
222  CH_Matrix_Classes::Real gtheta=nbh_ubnd;
223  CH_Matrix_Classes::Real theta=CH_Matrix_Classes::max(otheta,nbh_ubnd);
224  if (otheta>(1+1e-6)*nbh_ubnd){
225  gtheta=std::sqrt(CH_Matrix_Classes::max(0.,otheta*otheta+2*(xz*xdzpdxz-otheta*otheta*mu_xz*mu_xdzpdxz)/CH_Matrix_Classes::max(mu_at_one,1e-6*mu_xz)));
226  if (gtheta<.1*nbh_ubnd+0.9*otheta){
227  gtheta=CH_Matrix_Classes::max(.1*gtheta+.9*otheta,nbh_ubnd);
228  }
229  else {
230  gtheta=(1-1e-3)*otheta+1e-3*nbh_ubnd;
231  }
232  }
233 
234  //find the longest step for the positive branch of the absolute value
235  CH_Matrix_Classes::Real q0 = CH_Matrix_Classes::min(xz - theta*mu_xz,0.);
236  CH_Matrix_Classes::Real q1 = xdzpdxz - theta*mu_xdzpdxz-(gtheta-theta)*(mu_at_one);
237  CH_Matrix_Classes::Real q2 = dxdz - theta*mu_dxdz;
238 
239  if (q0+1e-8*q1>CH_Matrix_Classes::eps_Real*mu_xz) {
240  alpha=0.;
241  }
242  else if (q2>CH_Matrix_Classes::eps_Real*mu_xz){
243  //strictly convex case with min >= zero, max is upper root
244  CH_Matrix_Classes::Real p=q1/q2/2.;
245  CH_Matrix_Classes::Real q=q0/q2;
246  alpha=CH_Matrix_Classes::min(alpha,-p+std::sqrt(p*p-q));
247  }
248  else if (q2<-CH_Matrix_Classes::eps_Real*mu_xz){
249  //strictly concave case, restrictions only for positive q1
250  if (q1>0.) {
251  CH_Matrix_Classes::Real p=q1/q2/2.;
252  CH_Matrix_Classes::Real q=q0/q2;
253  CH_Matrix_Classes::Real discr=p*p-q;
254  if (discr>0){
255  alpha=CH_Matrix_Classes::min(alpha,-p-std::sqrt(discr));
256  }
257  }
258  }
259  else {
260  //q is affine
261  if (q0+alpha*q1>0.) {
262  alpha=CH_Matrix_Classes::min(alpha,CH_Matrix_Classes::max(0.,-q0/q1));
263  }
264  }
265 
266  //find the longest step for the negative branch of the absolute value
267  q0 = -xz - theta*mu_xz;
268  q1 = -xdzpdxz - theta*mu_xdzpdxz-(gtheta-theta)*(mu_at_one);
269  q2 = -dxdz - theta*mu_dxdz;
270  if (q0+1e-8*q1>CH_Matrix_Classes::eps_Real*mu_xz) {
271  alpha=0;
272  }
273  else if (q2>CH_Matrix_Classes::eps_Real*mu_xz){
274  //strictly convex case with min >= zero, max is upper root
275  CH_Matrix_Classes::Real p=q1/q2/2.;
276  CH_Matrix_Classes::Real q=q0/q2;
277  alpha=CH_Matrix_Classes::min(alpha,-p+std::sqrt(p*p-q));
278  }
279  else if (q2<-CH_Matrix_Classes::eps_Real*mu_xz){
280  //strictly concave case, restrictions only for positive q1
281  if (q1>0.) {
282  CH_Matrix_Classes::Real p=q1/q2/2.;
283  CH_Matrix_Classes::Real q=q0/q2;
284  CH_Matrix_Classes::Real discr=p*p-q;
285  if (discr>0){
286  alpha=CH_Matrix_Classes::min(alpha,-p-std::sqrt(discr));
287  }
288  }
289  }
290  else {
291  //q is affine
292  if (q0+alpha*q1>0.) {
293  alpha=CH_Matrix_Classes::min(alpha,CH_Matrix_Classes::max(0.,-q0/q1));
294  }
295  }
296  }
297 
298  CH_Matrix_Classes::Real step_nbh=std::fabs(xz+alpha*(xdzpdxz+alpha*dxdz))/CH_Matrix_Classes::max(mu_xz+alpha*(mu_xdzpdxz+alpha*(mu_dxdz)),1e-6*mu_xz);
299  max_nbh=CH_Matrix_Classes::max(max_nbh,step_nbh);
300  }
301 
302 
304 
305 }
306 
307 #endif
308 
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
virtual int set_dx(const CH_Matrix_Classes::Matrix &rhs, CH_Matrix_Classes::Integer startindex)=0
extract dx from rhs at startindex and compute at the same time dz (=-sys dx-z +complentarity_rhs); th...
int control_nbh_step(CH_Matrix_Classes::Real &stepsize, CH_Matrix_Classes::Real &max_nbh, CH_Matrix_Classes::Real nbh_ubnd, CH_Matrix_Classes::Real mu_xz, CH_Matrix_Classes::Real mu_xdzpdxz, CH_Matrix_Classes::Real mu_dxdz, CH_Matrix_Classes::Real nrmsqr_xz, CH_Matrix_Classes::Real nrmsqr_xdzpdxz, CH_Matrix_Classes::Real nrmsqr_dxdz, CH_Matrix_Classes::Real ip_xz_xdzpdxz, CH_Matrix_Classes::Real ip_xz_dxdz, CH_Matrix_Classes::Real ip_dxdz_xdzpdxz) const
find a stepsize so that outside the nbh_ubnd some progress is made towards it and inside the upper bo...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
virtual int set_z(const CH_Matrix_Classes::Matrix &vec, CH_Matrix_Classes::Integer startindex, CH_Matrix_Classes::Real &add_center_value)=0
set z to the values of vec[startindex+0,+1 ...,+(vecdim-1)] and return a value>=0 that needs to be ad...
virtual int do_step(CH_Matrix_Classes::Real alpha)=0
move to (x+alpha*dx, z+alpha*dz)
virtual int vecgetsaz(CH_Matrix_Classes::Matrix &vec, CH_Matrix_Classes::Integer startindex, CH_Matrix_Classes::Real a=1., bool add=false)=0
on vec[startindex+0,+1 ...,+(vecdim-1)] put or add a * z into vec for a real number a ...
virtual int add_AxizinvAt(const CH_Matrix_Classes::Matrix &A, CH_Matrix_Classes::Symmatrix &globalsys, bool minus=false, bool Atrans=false)=0
add the Schur complement to a big system matrix
virtual int get_mu_info(CH_Matrix_Classes::Integer &mudim, CH_Matrix_Classes::Real &tr_xz, CH_Matrix_Classes::Real &tr_xdzpdxz, CH_Matrix_Classes::Real &tr_dxdz, CH_Matrix_Classes::Real &min_xz, CH_Matrix_Classes::Real &max_xz) const =0
add dimensions of the primal-dual pairs to mudim and add the "trace" (the inner product with center) ...
const Real eps_Real
machine epsilon for type Real
Definition: matop.hxx:59
InteriorPointBlock(CBout *cb=0, int cbinc=-1)
default constructor
Definition: InteriorPointBlock.hxx:67
abstract interface for interior point vector/matrix variables and routines specific to primal dual co...
Definition: InteriorPointBlock.hxx:30
virtual int apply_xiz(CH_Matrix_Classes::Matrix &rhs, CH_Matrix_Classes::Integer startindex, bool minus=false)=0
compute sys*rhs into rhs, possibly with a negative sign
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
Header declaring the class CH_Matrix_Classes::Symmatrix for symmetric matrices with Real elements...
virtual int get_vecdx(CH_Matrix_Classes::Matrix &vecdx, CH_Matrix_Classes::Integer startindex)=0
return the vector form of dx, 1 if not available
virtual int get_vecz(CH_Matrix_Classes::Matrix &vecz, CH_Matrix_Classes::Integer startindex)=0
return the vector form of z
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
virtual int center_x(CH_Matrix_Classes::Real val, bool add=false)=0
set x to value*"one" to x (spend a total of mu_dim*val), or if add==true, add value*"one" to x ...
virtual int get_nbh_info(CH_Matrix_Classes::Integer mudim, CH_Matrix_Classes::Real tr_xz, CH_Matrix_Classes::Real tr_xdzpdxz, CH_Matrix_Classes::Real tr_dxdz, CH_Matrix_Classes::Real nbh_ubnd, CH_Matrix_Classes::Real &alpha, CH_Matrix_Classes::Real &max_nbh, CH_Matrix_Classes::Real &nrmsqr_xz, CH_Matrix_Classes::Real &nrmsqr_xdzpdxz, CH_Matrix_Classes::Real &nrmsqr_dxdz, CH_Matrix_Classes::Real &ip_xz_xdzpdxz, CH_Matrix_Classes::Real &ip_xz_dxdz, CH_Matrix_Classes::Real &ip_dxdz_xdzpdxz) const =0
for limiting the stepsize with respect to the neighborhood this information about norms and inner pro...
virtual int get_vecx(CH_Matrix_Classes::Matrix &vecx, CH_Matrix_Classes::Integer startindex)=0
return the vector form of x
Header declaring the output class CBout.
virtual CH_Matrix_Classes::Integer get_vecdim() const =0
the dimension of the variable
int pol_le_zero_step(CH_Matrix_Classes::Real &stepsize, CH_Matrix_Classes::Real q0, CH_Matrix_Classes::Real q1, CH_Matrix_Classes::Real q2, CH_Matrix_Classes::Real q3, CH_Matrix_Classes::Real q4, CH_Matrix_Classes::Real abseps=1e-10) const
for a polynomial q0+alpha*(q1+alpha*(q2+alpha*(q3+alpha*q4))) with q0<=0 find the maximum alpha <= st...
virtual int apply_xizinv(CH_Matrix_Classes::Matrix &rhs, CH_Matrix_Classes::Integer startindex, bool minus=false)=0
compute sysinv*rhs into rhs, possibly with a negative sign
virtual int center_z(CH_Matrix_Classes::Real val, bool add=false)=0
set z to value*"one" to z, or if add==true, add value*"one" to z
Matrix class for real values of type Real
Definition: matrix.hxx:74
virtual int set_x(const CH_Matrix_Classes::Matrix &vec, CH_Matrix_Classes::Integer startindex, CH_Matrix_Classes::Real &add_center_value)=0
set x to the values of vec[startindex+0,+1 ...,+(vecdim-1)] and return in add_center_value a value>=0...
virtual int get_vecdz(CH_Matrix_Classes::Matrix &vecdz, CH_Matrix_Classes::Integer startindex)=0
return the vector form of dz, 1 if not available
int sqr(int a)
return a*a for int a
Definition: mymath.hxx:103
double max(double a, double b)
maximum value of two double variables
Definition: mymath.hxx:43
virtual int add_muxinv(CH_Matrix_Classes::Matrix &rhs, CH_Matrix_Classes::Integer startindex, CH_Matrix_Classes::Real rhsmu, CH_Matrix_Classes::Real rhscorr, bool minus=false)=0
compute the complementarity_rhs=rhsmu*xi-rhscorr*xi*dx*dz (wihtout "-z") for mu=rhsmu and for correct...
int minimize_pol_step(CH_Matrix_Classes::Real &stepsize, CH_Matrix_Classes::Real q0, CH_Matrix_Classes::Real q1, CH_Matrix_Classes::Real q2, CH_Matrix_Classes::Real q3, CH_Matrix_Classes::Real q4, CH_Matrix_Classes::Real abseps=1e-10) const
find the minimizing alpha of a polynomial q0+alpha*(q1+alpha*(q2+alpha*(q3+alpha*q4))) within 0<=alph...
virtual int add_xiz(CH_Matrix_Classes::Symmatrix &globalsys, CH_Matrix_Classes::Integer startindex, bool minus=false)=0
add (or subract if minus==true) the system matrix to a big system matrix starting at startindex ...
double min(double a, double b)
minimum value of two double variables
Definition: mymath.hxx:49
virtual int vecgetsax(CH_Matrix_Classes::Matrix &vec, CH_Matrix_Classes::Integer startindex, CH_Matrix_Classes::Real a=1., bool add=false)=0
on vec[startindex+0,+1 ...,+(vecdim-1)] put or add a * x into vec for a real number a ...
virtual int linesearch(CH_Matrix_Classes::Real &alpha) const =0
if necessary, reduce alpha to the biggest value so that feasibility is maintained with this step size...
virtual ~InteriorPointBlock()
virtual destructor (implemented in InteriorPointBundleBlock.cxx)
virtual int set_dx_xizsolverhs(const CH_Matrix_Classes::Matrix &rhs, CH_Matrix_Classes::Integer startindex)=0
compute dx=sysinv*rhs and at the same time dz (=-rhs-z +complentarity_rhs); may only be called after ...
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121
void NNC_nbh_stepsize(CH_Matrix_Classes::Real x, CH_Matrix_Classes::Real z, CH_Matrix_Classes::Real dx, CH_Matrix_Classes::Real dz, CH_Matrix_Classes::Real mu_xz, CH_Matrix_Classes::Real mu_xdzpdxz, CH_Matrix_Classes::Real mu_dxdz, CH_Matrix_Classes::Real mu_at_one, CH_Matrix_Classes::Real nbh_ubnd, CH_Matrix_Classes::Real &alpha, CH_Matrix_Classes::Real &max_nbh, CH_Matrix_Classes::Real &nrmsqr_xz, CH_Matrix_Classes::Real &nrmsqr_xdzpdxz, CH_Matrix_Classes::Real &nrmsqr_dxdz, CH_Matrix_Classes::Real &ip_xz_xdzpdxz, CH_Matrix_Classes::Real &ip_xz_dxdz, CH_Matrix_Classes::Real &ip_dxdz_xdzpdxz)
computes values for a neighborhood line search for a primal nonnegative cone pair ...
Definition: InteriorPointBlock.hxx:188