2 ***********************************************************
4 $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/trm6.cpp $
5 $LastChangedRevision: 122 $
6 $Date: 2014-07-09 18:18:59 -0400 (Wed, 09 Jul 2014) $
8 ***********************************************************
10 Residual based stopping criterion
18 #include "TerminationCriterion.h"
22 TerminationCriterion::TerminationCriterion(DistanceMeasure* distanceMeasureIn,
23 char* reportingFilenameIn) {
24 this->terminationValue = 0;
25 this->distanceMeasure = distanceMeasureIn;
27 this->reportingEnabled = FALSE;
28 this->reportingSkipFactor = 0;
29 this->reportingFilename = reportingFilenameIn;
32 TerminationCriterion::~TerminationCriterion() {
35 void TerminationCriterion::Init() {
36 // read desired epsilon from command
38 this->terminationValue = InFile.getnum(FALSE, &eol);
40 if (this->terminationValue < Consts_class::zero) {
41 printf("\n **** epsilon must be specified and >= ZERO");
42 printf("\n **** program aborted\n");
46 // read reporting command (disabled by default)
47 INTEGER rprt = CHAR2INT('r', 'p', 'r', 't');
48 if (InFile.getwrd(FALSE, &eol, &rprt, 1) == rprt) {
49 this->reportingEnabled = true;
50 printf("\n reporting is enabled");
51 printf("\n reporting file: %s", this->reportingFilename);
53 this->reportingSkipFactor = InFile.getnum(FALSE, &eol);
54 if (this->reportingSkipFactor > 0) {
55 printf("\n report skip factor %d",
56 this->reportingSkipFactor);
58 printf("\n reporting on every iteration");
61 this->reportingEnabled = false;
62 printf("\n reporting is disabled");
65 printf("\n epsilon = %12.4f", this->terminationValue);
68 void TerminationCriterion::reportCurrentValue(REAL currentDistance,
71 if (this->reportingEnabled) {
73 printf("\n current epsilon (%s) = %20.4f",
74 this->distanceMeasure->getName(), currentDistance);
79 RPRTfile = fopen(this->reportingFilename, "w");
80 fprintf(RPRTfile, "%s stopping criterion reporting output\n",
81 this->reportingFilename);
82 fprintf(RPRTfile, " iter %s\n", this->reportingFilename);
84 RPRTfile = fopen(this->reportingFilename, "a");
87 fprintf(RPRTfile, " %5i %20.9f\n", iter, currentDistance);
93 BOOLEAN TerminationCriterion::Run(REAL* recon, INTEGER* list,
94 REAL* weight, INTEGER iter) {
97 REAL currentDistance = this->distanceMeasure->calculateDistance(recon, list,
100 if (currentDistance <= this->terminationValue) {
101 this->reportCurrentValue(currentDistance, iter);
105 if (iter == 1 || this->reportingSkipFactor == 0
106 || (iter % this->reportingSkipFactor) == 0) {
107 this->reportCurrentValue(currentDistance, iter);