50 #ifndef ZOLTAN2_METRIC_ANALYZER_HPP
51 #define ZOLTAN2_METRIC_ANALYZER_HPP
57 #include <Teuchos_DefaultComm.hpp>
58 #include <Teuchos_XMLObject.hpp>
59 #include <Teuchos_FileInputSource.hpp>
65 using Teuchos::ParameterList;
68 using Teuchos::ArrayRCP;
69 using namespace Zoltan2_TestingFramework;
81 template<
class Adapter>
88 #define KEYWORD_PARAMETER_NAME "check" // should be the first entry
89 #define UPPER_PARAMETER_NAME "upper"
90 #define LOWER_PARAMETER_NAME "lower"
96 : evaluate_(evaluate) {
105 std::ostringstream & msg_stream )
107 if (metricsParameters.numParams() == 0) {
112 bool bAllPassed =
true;
114 std::vector<MetricAnalyzerInfo> metricInfoSet;
115 LoadMetricInfo(metricInfoSet, metricsParameters);
117 int countFailedMetricChecks = 0;
118 for (
auto metricInfo = metricInfoSet.begin();
119 metricInfo != metricInfoSet.end(); ++metricInfo) {
120 if (!MetricAnalyzer::executeMetricCheck(*metricInfo, msg_stream)) {
121 ++countFailedMetricChecks;
127 if(countFailedMetricChecks == 0) {
128 msg_stream << metricsParameters.numParams() <<
" out of " <<
129 metricsParameters.numParams() <<
" metric checks" <<
" PASSED."
133 msg_stream << countFailedMetricChecks <<
" out of " <<
134 metricsParameters.numParams() <<
" metric checks " <<
" FAILED."
138 msg_stream << std::endl;
147 const ParameterList & metricCheckParameters, std::string keyWord)
const = 0;
150 const ParameterList &metricsParameters) {
152 int headingIndex = 1;
154 for (
auto iterateArbitraryHeadingNames = metricsParameters.begin();
155 iterateArbitraryHeadingNames != metricsParameters.end();
156 ++iterateArbitraryHeadingNames) {
157 auto headingName = metricsParameters.name(iterateArbitraryHeadingNames);
161 std::string expectedHeadingName =
"metriccheck" + std::to_string(headingIndex);
162 if( expectedHeadingName != headingName) {
163 throw std::logic_error(
164 "The parameter list expected to find a heading with name '"
165 + expectedHeadingName +
"' but instead found '" + headingName );
170 metricsParameters.sublist(headingName));
171 metricInfoSet.push_back(metricInfo);
181 const ParameterList & metricCheckParameters)
const {
184 for (
auto iterateAllKeys = metricCheckParameters.begin();
185 iterateAllKeys != metricCheckParameters.end(); ++iterateAllKeys) {
186 auto checkName = metricCheckParameters.name(iterateAllKeys);
192 if (!bIsGeneralName && !isMetricCheckNameValid(checkName)) {
193 throw std::logic_error(
194 "Key name: '" + checkName +
"' is not understood" );
199 throw std::logic_error(
"Matric check must specify a key name using "
203 std::string keyWord =
209 = getMetricResult(metricCheckParameters, keyWord);
212 result.bFoundUpperBound =
214 result.bFoundLowerBound =
217 if (result.bFoundUpperBound) {
221 if (result.bFoundLowerBound) {
238 std::ostringstream &msg_stream)
240 bool bDoesThisTestPass =
true;
245 <<
" value: " << metricInfo.
theValue <<
" is not in range: "
248 bDoesThisTestPass =
false;
252 <<
" value: " << metricInfo.
theValue <<
" is in range: "
260 <<
" value: " << metricInfo.
theValue <<
" is not below "
262 bDoesThisTestPass =
false;
266 <<
" value: " << metricInfo.
theValue <<
" is below: "
273 <<
" value: " << metricInfo.
theValue <<
" is not above "
275 bDoesThisTestPass =
false;
279 <<
" value: " << metricInfo.
theValue <<
" is above: "
283 return bDoesThisTestPass;
287 template<
class Adapter>
291 #define WEIGHT_PARAMETER_NAME "weight"
292 #define NORMED_PARAMETER_NAME "normed"
305 const ParameterList & metricCheckParameters, std::string keyWord)
const {
307 RCP<Zoltan2::EvaluatePartition<Adapter>> pEvaluatePartition =
314 #define UNDEFINED_PARAMETER_INT_INDEX -1
321 if( weightIndex < 0 ) {
322 throw std::logic_error(
"Optional weight index was specified as: " +
323 std::to_string(weightIndex) +
324 " Weight index must be 0 or positive." );
333 normedSetting = bNormSetting ? 1 : 0;
334 if( normedSetting != 0 && normedSetting != 1 ) {
335 throw std::logic_error(
"Optional normed parameter was specified as: "
336 + std::to_string(normedSetting) +
337 " Normed parameter must be true or false." );
343 throw std::logic_error(
"Both parameters 'normed' and 'weight' were "
344 " specified. They should never appear together." );
348 #define API_STRING_getWeightImbalance "imbalance"
349 #define API_STRING_getTotalEdgeCuts "total edge cuts"
350 #define API_STRING_getMaxEdgeCuts "max edge cuts"
355 throw std::logic_error(
"'normed' was specified but this only has meaning"
356 " for the 'imbalance' parameter." );
362 if( normedSetting == 1 ) {
363 result.theValue = pEvaluatePartition->getNormedImbalance();
366 result.theValue = pEvaluatePartition->getObjectCountImbalance();
371 result.theValue = pEvaluatePartition->getWeightImbalance(weightIndex);
376 result.theValue = pEvaluatePartition->getTotalEdgeCut();
379 result.theValue = pEvaluatePartition->getTotalWeightEdgeCut(weightIndex);
384 result.theValue = pEvaluatePartition->getMaxEdgeCut();
387 result.theValue = pEvaluatePartition->getMaxWeightEdgeCut(weightIndex);
392 throw std::logic_error(
"The parameter '" +
394 keyWord +
"' which is not understood." );
397 result.parameterDescription = keyWord;
399 result.parameterDescription = result.parameterDescription +
400 " (weight: " + std::to_string(weightIndex) +
")";
404 result.parameterDescription = result.parameterDescription +
" (normed: "
405 + ( ( normedSetting == 0 ) ?
"false" :
"true" ) +
")";
419 template<
class Adapter>
424 #define API_STRING_getBandwidth "bandwidth"
425 #define API_STRING_getEnvelope "envelope"
426 #define API_STRING_getSeparatorSize "separator size"
439 const ParameterList & metricCheckParameters, std::string keyWord)
const {
441 RCP<Zoltan2::EvaluateOrdering<Adapter>> pEvaluateOrdering =
447 result.
theValue = pEvaluateOrdering->getBandwidth();
450 result.theValue = pEvaluateOrdering->getEnvelope();
453 result.theValue = pEvaluateOrdering->getSeparatorSize();
457 throw std::logic_error(
"The parameter '" +
459 keyWord +
"' which is not understood." );
462 result.parameterDescription = keyWord;
468 #endif //ZOLTAN2_METRIC_ANALYZER_HPP
keep typedefs that commonly appear in many places localized
#define API_STRING_getMaxEdgeCuts
virtual bool isMetricCheckNameValid(std::string metricCheckName) const
Return true for any names we accept.
MetricAnalyzerEvaluateOrdering(RCP< Zoltan2::EvaluateBaseClass< Adapter >> evaluate)
MetricAnalyzerEvaluatePartition constructor.
MetricAnalyzerInfo getMetricAnalyzerInfo(const ParameterList &metricCheckParameters) const
getMetricAnalyzerInfo is responsible for reading a metric value and then checking it against upper an...
#define UPPER_PARAMETER_NAME
common code used by tests
virtual bool isMetricCheckNameValid(std::string metricCheckName) const
Return true for any names we accept.
A class that computes and returns quality metrics. base class for the local and global ordering vers...
void LoadMetricInfo(std::vector< MetricAnalyzerInfo > &metricInfoSet, const ParameterList &metricsParameters)
#define API_STRING_getTotalEdgeCuts
#define API_STRING_getEnvelope
#define LOWER_PARAMETER_NAME
Defines the EvaluatePartition class.
#define UNDEFINED_PARAMETER_INT_INDEX
#define NORMED_PARAMETER_NAME
#define API_STRING_getWeightImbalance
Defines the Zoltan2_EvaluateOrdering.hpp class.
bool analyzeMetrics(const ParameterList &metricsParameters, std::ostringstream &msg_stream)
analyzeMetrics for a problem based on a range of tolerances
#define KEYWORD_PARAMETER_NAME
virtual MetricAnalyzerInfo getMetricResult(const ParameterList &metricCheckParameters, std::string keyWord) const
Reads a metric value for bounds checking. Handle any special optional parameters. ...
#define API_STRING_getSeparatorSize
#define API_STRING_getBandwidth
MetricAnalyzer(RCP< Zoltan2::EvaluateBaseClass< Adapter >> evaluate)
MetricAnalyzer constructor takes an EvaluateBaseClass such as EvaluateOrdering or EvaluatePartition...
A class that computes and returns quality metrics.
MetricAnalyzerEvaluatePartition(RCP< Zoltan2::EvaluateBaseClass< Adapter >> evaluate)
MetricAnalyzerEvaluatePartition constructor.
virtual MetricAnalyzerInfo getMetricResult(const ParameterList &metricCheckParameters, std::string keyWord) const
Reads a metric value for bounds checking. Handle any special optional parameters. ...
#define WEIGHT_PARAMETER_NAME
std::string parameterDescription
RCP< Zoltan2::EvaluateBaseClass< Adapter > > evaluate_