58 ClassImp(TGondzioSolver);
63 TGondzioSolver::TGondzioSolver()
67 fMaximum_correctors = 0;
68 fNumberGondzioCorrections = 0;
86 TGondzioSolver::TGondzioSolver(TQpProbBase *of,TQpDataBase *prob,Int_t verbose)
89 fStep = fFactory->MakeVariables(prob);
90 fCorrector_step = fFactory->MakeVariables(prob);
91 fCorrector_resid = fFactory->MakeResiduals(prob);
93 fPrintlevel = verbose;
96 fMaximum_correctors = 3;
98 fNumberGondzioCorrections = 0;
118 TGondzioSolver::TGondzioSolver(
const TGondzioSolver &another) : TQpSolverBase(another)
129 Int_t TGondzioSolver::Solve(TQpDataBase *prob,TQpVar *iterate,TQpResidual *resid)
135 fDnorm = prob->DataNorm();
138 fSys = fFactory->MakeLinSys(prob);
139 this->Start(fFactory,iterate,prob,resid,fStep);
142 fNumberGondzioCorrections = 0;
143 Double_t mu = iterate->GetMu();
149 resid->CalcResids(prob,iterate);
152 status_code = this->DoStatus(prob,iterate,resid,fIter,mu,0);
153 if (status_code != kNOT_FINISHED )
break;
154 if (fPrintlevel >= 10)
155 this->DoMonitor(prob,iterate,resid,alpha,sigma,fIter,mu,status_code,0);
159 resid->Set_r3_xz_alpha(iterate,0.0);
161 fSys->Factor(prob,iterate);
162 fSys->Solve(prob,iterate,resid,fStep);
165 alpha = iterate->StepBound(fStep);
168 Double_t muaff = iterate->MuStep(fStep,alpha);
169 sigma = TMath::Power(muaff/mu,fTsig);
171 if (fPrintlevel >= 10)
172 this->DoMonitor(prob,iterate,resid,alpha,sigma,fIter,mu,status_code,2);
177 resid->Add_r3_xz_alpha(fStep,-sigma*mu);
179 fSys->Solve(prob,iterate,resid,fStep);
184 alpha = iterate->StepBound(fStep);
188 fCorrector_resid->Clear_r1r2();
191 Double_t rmin = sigma*mu*fBeta_min;
192 Double_t rmax = sigma*mu*fBeta_max;
194 Int_t stopCorrections = 0;
195 fNumberGondzioCorrections = 0;
198 if (fPrintlevel >= 10)
199 std::cout <<
"**** Entering the correction loop ****" << std::endl;
201 while (fNumberGondzioCorrections < fMaximum_correctors &&
202 alpha < 1.0 && !stopCorrections) {
205 *fCorrector_step = *iterate;
208 Double_t alpha_target = fStepFactor1*alpha+fStepFactor0;
209 if (alpha_target > 1.0) alpha_target = 1.0;
212 fCorrector_step->Saxpy(fStep,alpha_target);
215 fCorrector_resid->Set_r3_xz_alpha(fCorrector_step,0.0);
218 fCorrector_resid->Project_r3(rmin,rmax);
221 fSys->Solve(prob,iterate,fCorrector_resid,fCorrector_step);
225 fCorrector_step->Saxpy(fStep,1.0);
226 Double_t alpha_enhanced = iterate->StepBound(fCorrector_step);
230 if (alpha_enhanced == 1.0) {
231 *fStep = *fCorrector_step;
232 alpha = alpha_enhanced;
233 fNumberGondzioCorrections++;
236 else if(alpha_enhanced >= (1.0+fAcceptTol)*alpha) {
240 *fStep = *fCorrector_step;
241 alpha = alpha_enhanced;
242 fNumberGondzioCorrections++;
253 alpha = this->FinalStepLength(iterate,fStep);
260 iterate->Saxpy(fStep,alpha);
261 mu = iterate->GetMu();
264 resid->CalcResids(prob,iterate);
265 if (fPrintlevel >= 10)
266 this->DoMonitor(prob,iterate,resid,alpha,sigma,fIter,mu,status_code,1);
276 void TGondzioSolver::DefMonitor(TQpDataBase* ,TQpVar* ,
278 Double_t alpha,Double_t sigma,Int_t i,Double_t mu,
279 Int_t status_code,Int_t level)
284 std::cout << std::endl <<
"Duality Gap: " << resid->GetDualityGap() << std::endl;
286 std::cout <<
" Number of Corrections = " << fNumberGondzioCorrections
287 <<
" alpha = " << alpha << std::endl;
289 std::cout <<
" *** Iteration " << i <<
" *** " << std::endl;
290 std::cout <<
" mu = " << mu <<
" relative residual norm = "
291 << resid->GetResidualNorm()/fDnorm << std::endl;
296 if (status_code == kSUCCESSFUL_TERMINATION) {
297 std::cout << std::endl
298 <<
" *** SUCCESSFUL TERMINATION ***"
301 else if (status_code == kMAX_ITS_EXCEEDED) {
302 std::cout << std::endl
303 <<
" *** MAXIMUM ITERATIONS REACHED *** " << std::endl;
305 else if (status_code == kINFEASIBLE) {
306 std::cout << std::endl
307 <<
" *** TERMINATION: PROBABLY INFEASIBLE *** "
310 else if (status_code == kUNKNOWN) {
311 std::cout << std::endl
312 <<
" *** TERMINATION: STATUS UNKNOWN *** " << std::endl;
317 std::cout <<
" *** sigma = " << sigma << std::endl;
326 TGondzioSolver::~TGondzioSolver()
328 if (fCorrector_step) {
delete fCorrector_step; fCorrector_step = 0; }
329 if (fStep) {
delete fStep; fStep = 0; }
330 if (fCorrector_resid) {
delete fCorrector_resid; fCorrector_resid = 0; }
337 TGondzioSolver &TGondzioSolver::operator=(
const TGondzioSolver &source)
339 if (
this != &source) {
340 TQpSolverBase::operator=(source);
342 fPrintlevel = source.fPrintlevel;
343 fTsig = source.fTsig ;
344 fMaximum_correctors = source.fMaximum_correctors;
345 fNumberGondzioCorrections = source.fNumberGondzioCorrections;
347 fStepFactor0 = source.fStepFactor0;
348 fStepFactor1 = source.fStepFactor1;
349 fAcceptTol = source.fAcceptTol;
350 fBeta_min = source.fBeta_min;
351 fBeta_max = source.fBeta_max;
353 if (fCorrector_step)
delete fCorrector_step;
354 if (fStep)
delete fStep;
355 if (fCorrector_resid)
delete fCorrector_resid;
357 fCorrector_step =
new TQpVar(*source.fCorrector_step);
358 fStep =
new TQpVar(*source.fStep);
359 fCorrector_resid =
new TQpResidual(*source.fCorrector_resid);
360 fFactory = source.fFactory;