1 
2 #ifdef HAVE_CONFIG_H
3 #include "OPT++_config.h"
4 #endif
5 
6 #ifdef HAVE_STD
7 #include <cmath>
8 #include <cerrno>
9 #include <cstring>
10 #else
11 #include <math.h>
12 #include <errno.h>
13 #include <string.h>
14 #endif
15 
16 #include "OptPDS.h"
17 #include "pds.h"
18 #include "newmat.h"
19 #include "common.h"
20 #include "cblas.h"
21 
22 using NEWMAT::ColumnVector;
23 
24 /* Structures for constraints and parallel configuration. */
25 
26 extern struct pdscon pdscon;
27 extern struct conbcmni conbcmni;
28 
29 namespace OPTPP {
30 
pdschk(NLP0 * nlp,int ndim,double * xc,double * xt,double tr_size,double * dist,int trpds,double feas_tol)31 int pdschk(NLP0* nlp, int ndim, double *xc, double *xt, double tr_size,
32 	   double *dist, int trpds, double feas_tol)
33 {
34   /* Check trust region constraint for TRPDS. */
35 
36   int i ;
37 
38   *dist = 0.0;
39 
40 // PJW
41   if(nlp->hasConstraints()){
42     CompoundConstraint* constraints = nlp->getConstraints();
43 
44     ColumnVector xtrial(ndim);
45     for (i = 0; i < ndim; i++) {
46       xtrial(i+1) = xt[i];
47     }
48 
49     bool feasible = constraints->amIFeasible(xtrial, feas_tol);
50     if(!feasible){
51       //       printf("pdschk: Current point violates the constraints. \n");
52        return feasible;
53     }
54   }
55   if(trpds){
56     ColumnVector diff(ndim);
57 
58 // PJW
59 
60     for (i = 0; i < ndim; i++)
61       diff(i+1) = xc[i] - xt[i];
62 
63     *dist = Norm2(diff);
64 
65     if(*dist < 0.0) {
66       printf("pdschk: Distance is negative: %e\n", *dist);
67     }
68 
69     if (*dist <= tr_size)
70       return 1;
71     else{
72       return 0;
73     }
74   }
75   /* The problem is unconstrained AND the solution method is not TRPDS */
76   else
77     return 1;
78 }
79 
80 } // namespace OPTPP
81