14 #ifndef ZOLTAN2_METRIC_ANALYZER_HPP 
   15 #define ZOLTAN2_METRIC_ANALYZER_HPP 
   21 #include <Teuchos_DefaultComm.hpp> 
   22 #include <Teuchos_XMLObject.hpp> 
   23 #include <Teuchos_FileInputSource.hpp> 
   29 using Teuchos::ParameterList;
 
   32 using Teuchos::ArrayRCP;
 
   33 using namespace Zoltan2_TestingFramework;
 
   45 template<
class Adapter>
 
   52   #define KEYWORD_PARAMETER_NAME "check" // should be the first entry 
   53   #define UPPER_PARAMETER_NAME "upper" 
   54   #define LOWER_PARAMETER_NAME "lower" 
   60     : evaluate_(evaluate) {
 
   69     std::ostringstream & msg_stream )
 
   71     if (metricsParameters.numParams() == 0) {
 
   76     bool bAllPassed = 
true;
 
   78     std::vector<MetricAnalyzerInfo> metricInfoSet;
 
   79     LoadMetricInfo(metricInfoSet, metricsParameters);
 
   81     int countFailedMetricChecks = 0;
 
   82     for (
auto metricInfo = metricInfoSet.begin();
 
   83          metricInfo != metricInfoSet.end(); ++metricInfo) {
 
   84       if (!MetricAnalyzer::executeMetricCheck(*metricInfo, msg_stream)) {
 
   85         ++countFailedMetricChecks;
 
   91     if(countFailedMetricChecks == 0) {
 
   92       msg_stream << metricsParameters.numParams() << 
" out of " <<
 
   93         metricsParameters.numParams() << 
" metric checks"  << 
" PASSED." 
   97       msg_stream << countFailedMetricChecks << 
" out of " <<
 
   98         metricsParameters.numParams() << 
" metric checks " << 
" FAILED." 
  102     msg_stream << std::endl; 
 
  111     const ParameterList & metricCheckParameters, std::string keyWord) 
const = 0;
 
  114     const ParameterList &metricsParameters) {
 
  116     int headingIndex = 1;
 
  118     for (
auto iterateArbitraryHeadingNames = metricsParameters.begin(); 
 
  119          iterateArbitraryHeadingNames != metricsParameters.end();
 
  120          ++iterateArbitraryHeadingNames) {
 
  121       auto headingName = metricsParameters.name(iterateArbitraryHeadingNames);
 
  125       std::string expectedHeadingName = 
"metriccheck" + std::to_string(headingIndex);
 
  126       if( expectedHeadingName != headingName) {
 
  127         throw std::logic_error(
 
  128           "The parameter list expected to find a heading with name '" 
  129           + expectedHeadingName + 
"' but instead found '" + headingName );
 
  134         metricsParameters.sublist(headingName));
 
  135       metricInfoSet.push_back(metricInfo);
 
  145     const ParameterList & metricCheckParameters)
 const {
 
  148     for (
auto iterateAllKeys = metricCheckParameters.begin();
 
  149          iterateAllKeys != metricCheckParameters.end(); ++iterateAllKeys) {
 
  150       auto checkName = metricCheckParameters.name(iterateAllKeys);
 
  156       if (!bIsGeneralName && !isMetricCheckNameValid(checkName)) {
 
  157         throw std::logic_error(
 
  158           "Key name: '" + checkName + 
"' is not understood" );
 
  163      throw std::logic_error( 
"Matric check must specify a key name using " 
  167     std::string keyWord =
 
  173       = getMetricResult(metricCheckParameters, keyWord);
 
  176     result.bFoundUpperBound =
 
  178     result.bFoundLowerBound =
 
  181     if (result.bFoundUpperBound) {
 
  185     if (result.bFoundLowerBound) {
 
  202     std::ostringstream &msg_stream)
 
  204     bool bDoesThisTestPass = 
true; 
 
  209                    << 
" value: " << metricInfo.
theValue << 
" is not in range: " 
  212         bDoesThisTestPass = 
false;
 
  216                    << 
" value: " << metricInfo.
theValue << 
" is in range: " 
  224                    << 
" value: " << metricInfo.
theValue << 
" is not below " 
  226         bDoesThisTestPass = 
false;
 
  230                    << 
" value: " << metricInfo.
theValue << 
" is below: " 
  237                    << 
" value: " << metricInfo.
theValue << 
" is not above " 
  239         bDoesThisTestPass = 
false;
 
  243                    << 
" value: " << metricInfo.
theValue << 
" is above: " 
  247     return bDoesThisTestPass;
 
  251 template<
class Adapter>
 
  255   #define WEIGHT_PARAMETER_NAME "weight" 
  256   #define NORMED_PARAMETER_NAME "normed" 
  269     const ParameterList & metricCheckParameters, std::string keyWord)
 const {
 
  271     RCP<Zoltan2::EvaluatePartition<Adapter>> pEvaluatePartition =
 
  278     #define UNDEFINED_PARAMETER_INT_INDEX -1 
  285       if( weightIndex < 0 ) {
 
  286         throw std::logic_error( 
"Optional weight index was specified as: " +
 
  287           std::to_string(weightIndex) +
 
  288           "   Weight index must be 0 or positive." );
 
  297       normedSetting = bNormSetting ? 1 : 0;
 
  298       if( normedSetting != 0 && normedSetting != 1 ) {
 
  299         throw std::logic_error( 
"Optional normed parameter was specified as: " 
  300           + std::to_string(normedSetting) +
 
  301           "   Normed parameter must be true or false." );
 
  307       throw std::logic_error( 
"Both parameters 'normed' and 'weight' were " 
  308         " specified. They should never appear together." );
 
  312     #define API_STRING_getWeightImbalance "imbalance" 
  313     #define API_STRING_getTotalEdgeCuts "total edge cuts" 
  314     #define API_STRING_getMaxEdgeCuts "max edge cuts" 
  319       throw std::logic_error( 
"'normed' was specified but this only has meaning" 
  320        " for the 'imbalance' parameter." );
 
  326         if( normedSetting == 1 ) {
 
  327           result.theValue = pEvaluatePartition->getNormedImbalance();
 
  330           result.theValue = pEvaluatePartition->getObjectCountImbalance();
 
  335         result.theValue = pEvaluatePartition->getWeightImbalance(weightIndex);
 
  340         result.theValue = pEvaluatePartition->getTotalEdgeCut();
 
  343         result.theValue = pEvaluatePartition->getTotalWeightEdgeCut(weightIndex);
 
  348         result.theValue = pEvaluatePartition->getMaxEdgeCut();
 
  351         result.theValue = pEvaluatePartition->getMaxWeightEdgeCut(weightIndex);
 
  356       throw std::logic_error( 
"The parameter '" +
 
  358         keyWord + 
"' which is not understood." );
 
  361     result.parameterDescription = keyWord;
 
  363       result.parameterDescription = result.parameterDescription +
 
  364         " (weight: " + std::to_string(weightIndex) + 
")";
 
  368       result.parameterDescription = result.parameterDescription + 
" (normed: " 
  369         + ( ( normedSetting == 0 ) ? 
"false" : 
"true" ) + 
")";
 
  383 template<
class Adapter>
 
  388   #define API_STRING_getBandwidth "bandwidth" 
  389   #define API_STRING_getEnvelope "envelope" 
  390   #define API_STRING_getSeparatorSize "separator size" 
  403     const ParameterList & metricCheckParameters, std::string keyWord)
 const {
 
  405     RCP<Zoltan2::EvaluateOrdering<Adapter>> pEvaluateOrdering =
 
  411       result.
theValue = pEvaluateOrdering->getBandwidth();
 
  414       result.theValue = pEvaluateOrdering->getEnvelope();
 
  417       result.theValue = pEvaluateOrdering->getSeparatorSize();
 
  421       throw std::logic_error( 
"The parameter '" +
 
  423         keyWord + 
"' which is not understood." );
 
  426     result.parameterDescription = keyWord; 
 
  432 #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_