71 if( arg.
A == 0 )
A = 0;
74 for( run1 = 0; run1 <
nDense; run1++ )
75 A[run1] = arg.
A[run1];
78 if( arg.
x == 0 )
x = 0;
81 for( run1 = 0; run1 <
dim; run1++ )
82 x[run1] = arg.
x[run1];
91 for( run1 = 0; run1 < 2*
dim+1; run1++ )
96 if( arg.
p == 0 )
p = 0;
98 p =
new double*[2*
dim+1];
99 for( run1 = 0; run1 < 2*
dim+1; run1++ ){
100 p[run1] =
new double[
dim];
101 for( run2 = 0; run2 <
dim; run2++ ){
102 p[run1][run2] = arg.
p[run1][run2];
107 if( arg.
r == 0 )
r = 0;
110 for( run1 = 0; run1 <
dim; run1++ )
111 r[run1] = arg.
r[run1];
120 for( run1 = 0; run1 <
dim; run1++ )
130 if(
A != 0 )
delete[]
A;
131 if(
x != 0 )
delete[]
x;
136 for( run1 = 0; run1 < 2*
dim+1; run1++ )
141 if(
r != 0 )
delete[]
r;
160 double *aux =
new double[
dim];
161 double auxR, auxR2, norm1;
167 for( run1 = 0; run1 <
dim; run1++ )
186 for( run1 = 0; run1 <
pCounter; run1++ ){
188 for( run2 = 0; run2 <
dim; run2++ ){
189 x[run2] += alpha*
p[run1][run2];
198 for( run1 = 0; run1 <
dim; run1++ )
199 r[run1] -= aux[run1];
202 for( run1 = 0; run1 <
dim; run1++ )
203 p[pCounter][run1] =
r[run1];
206 while( pCounter <= 2*dim-1 ){
210 for( run1 = 0; run1 <
dim; run1++ ){
211 if(
r[run1] >= 0 && norm1 <
r[run1] ) norm1 =
r[run1];
212 if(
r[run1] <= 0 && norm1 < -
r[run1] ) norm1 = -
r[run1];
216 std::cout <<
"STEP NUMBER " << pCounter <<
", WEIGHTED NORM = " 217 << std::scientific << norm1 << std::endl;
219 if( norm1 <
TOL )
break;
226 for( run1 = 0; run1 <
dim; run1++ ){
228 r [run1] -= alpha*aux[run1];
234 for( run1 = 0; run1 <
dim; run1++ )
235 p[pCounter+1][run1] =
r[run1] + beta*
p[pCounter][run1];
242 if( pCounter >= 2*dim ){
271 for( run1 = 0; run1 < 2*
dim+1; run1++ )
275 p =
new double*[2*
dim+1];
276 for( run1 = 0; run1 < 2*
dim+1; run1++ ){
277 p[run1] =
new double[
dim];
360 for( run1 = 0; run1 <
dim; run1++ )
361 aux += aa[run1]*bb[run1];
virtual returnValue setNumberOfEntries(const int &nDense_)
virtual returnValue getX(double *x_)
virtual ~ConjugateGradientMethod()
Allows to pass back messages to the calling function.
ConjugateGradientMethod()
virtual returnValue setMatrix(double *A_)
double scalarProduct(double *aa, double *bb)
#define CLOSE_NAMESPACE_ACADO
virtual void multiply(double *xx, double *result)=0
virtual returnValue setDimension(const int &n)
virtual returnValue applyPreconditioner(double *b)=0
virtual returnValue solve(double *b)
virtual returnValue setPrintLevel(PrintLevel printLevel_)
Implements a conjugate gradient method as sparse linear algebra solver.
#define ACADOWARNING(retval)
#define BEGIN_NAMESPACE_ACADO
virtual returnValue setTolerance(double TOL_)
virtual returnValue applyInversePreconditioner(double *x_)=0
virtual returnValue computePreconditioner(double *A_)=0
#define ACADOERROR(retval)