50 #ifndef ZOLTAN2_METRIC_ANALYZER_HPP 51 #define ZOLTAN2_METRIC_ANALYZER_HPP 55 #include <Teuchos_DefaultComm.hpp> 56 #include <Teuchos_XMLObject.hpp> 57 #include <Teuchos_FileInputSource.hpp> 63 using Teuchos::ParameterList;
66 using Teuchos::ArrayRCP;
70 #define API_STRING_getWeightImbalance "imbalance" 71 #define API_STRING_getTotalEdgeCuts "total edge cuts" 72 #define API_STRING_getMaxEdgeCuts "max edge cuts" 75 #define KEYWORD_PARAMETER_NAME "check" // would usually be the first entry and identify the API call 76 #define WEIGHT_PARAMETER_NAME "weight" 77 #define UPPER_PARAMETER_NAME "upper" 78 #define LOWER_PARAMETER_NAME "lower" 79 #define NORMED_PARAMETER_NAME "normed" 81 #define UNDEFINED_PARAMETER_INT_INDEX -1 // didn't want to duplicate this value - a weight index should be 0 or larger but it's optional to specify it 105 const ParameterList &metricsParameters,
106 std::ostringstream & msg_stream )
108 if (metricsParameters.numParams() == 0) {
112 bool bAllPassed =
true;
114 std::vector<MetricAnalyzerInfo> metricInfoSet;
115 LoadMetricInfo(metricInfoSet, metricObject, 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;
126 if(countFailedMetricChecks == 0) {
127 msg_stream << metricsParameters.numParams() <<
" out of " << metricsParameters.numParams() <<
" metric checks" <<
" PASSED." << std::endl;
130 msg_stream << countFailedMetricChecks <<
" out of " << metricsParameters.numParams() <<
" metric checks " <<
" FAILED." << std::endl;
133 msg_stream << std::endl;
138 std::vector<MetricAnalyzerInfo> & metricInfoSet,
140 const ParameterList &metricsParameters) {
160 int headingIndex = 1;
162 for (
auto iterateArbitraryHeadingNames = metricsParameters.begin();
163 iterateArbitraryHeadingNames != metricsParameters.end();
164 ++iterateArbitraryHeadingNames) {
165 auto headingName = metricsParameters.name(iterateArbitraryHeadingNames);
168 std::string expectedHeadingName =
"metriccheck" + std::to_string(headingIndex);
169 if( expectedHeadingName != headingName) {
170 throw std::logic_error(
"The parameter list expected to find a heading with name '" + expectedHeadingName +
"' but instead found '" + headingName );
174 const ParameterList & metricCheckParameters = metricsParameters.sublist(headingName);
177 metricInfoSet.push_back(metricInfo);
184 static zscalar_t convertParameterChoicesToEvaluatePartitionAPICall(
188 int selectedNormedSetting )
194 throw std::logic_error(
"Both parameters 'normed' and 'weight' were specified. They should never appear together." );
199 throw std::logic_error(
"'normed' was specified but this only has meaning for the 'imbalance' parameter." );
205 if( selectedNormedSetting == 1 ) {
206 theValue = metricObject->getNormedImbalance();
209 theValue = metricObject->getObjectCountImbalance();
213 theValue = metricObject->getWeightImbalance(weightIndex);
218 theValue = metricObject->getTotalEdgeCut();
221 theValue = metricObject->getTotalWeightEdgeCut(weightIndex);
226 theValue = metricObject->getMaxEdgeCut();
229 theValue = metricObject->getMaxWeightEdgeCut(weightIndex);
234 throw std::logic_error(
"The parameter '" + std::string(
KEYWORD_PARAMETER_NAME) +
"' was specified as '" + keyWord +
"' which is not understood." );
240 static bool executeMetricCheck(
242 std::ostringstream &msg_stream)
244 bool bDoesThisTestPass =
true;
249 <<
" value: " << metricInfo.
theValue <<
" is not in range: " << metricInfo.
lowerValue <<
" to " 251 bDoesThisTestPass =
false;
255 <<
" value: " << metricInfo.
theValue <<
" is in range: " 263 <<
" value: " << metricInfo.
theValue <<
" is not below " 265 bDoesThisTestPass =
false;
269 <<
" value: " << metricInfo.
theValue <<
" is below: " 276 <<
" value: " << metricInfo.
theValue <<
" is not above " 278 bDoesThisTestPass =
false;
282 <<
" value: " << metricInfo.
theValue <<
" is above: " 286 return bDoesThisTestPass;
290 const ParameterList & metricCheckParameters,
294 for (
auto iterateAllKeys = metricCheckParameters.begin();
295 iterateAllKeys != metricCheckParameters.end(); ++iterateAllKeys) {
296 auto checkName = metricCheckParameters.name(iterateAllKeys);
302 throw std::logic_error(
"Key name: '" + checkName +
"' is not understood." );
310 if( selectedWeightIndex < 0 ) {
311 throw std::logic_error(
"Optional weight index was specified as: " + std::to_string(selectedWeightIndex) +
" Weight index must be 0 or positive." );
319 selectedNormedSetting = bNormSetting ? 1 : 0;
320 if( selectedNormedSetting != 0 && selectedNormedSetting != 1 ) {
321 throw std::logic_error(
"Optional normed parameter was specified as: " + std::to_string(selectedNormedSetting) +
" Normed parameter must be true or false." );
331 result.
theValue = convertParameterChoicesToEvaluatePartitionAPICall(metricObject, theKeyWord, selectedWeightIndex, selectedNormedSetting );
358 #endif //ZOLTAN2_METRIC_ANALYZER_HPP keep typedefs that commonly appear in many places localized
#define API_STRING_getMaxEdgeCuts
#define UPPER_PARAMETER_NAME
common code used by tests
#define API_STRING_getTotalEdgeCuts
#define LOWER_PARAMETER_NAME
static void LoadMetricInfo(std::vector< MetricAnalyzerInfo > &metricInfoSet, const RCP< const Zoltan2::EvaluatePartition< basic_id_t > > &metricObject, const ParameterList &metricsParameters)
#define UNDEFINED_PARAMETER_INT_INDEX
#define NORMED_PARAMETER_NAME
#define API_STRING_getWeightImbalance
static bool analyzeMetrics(const RCP< const Zoltan2::EvaluatePartition< basic_id_t > > &metricObject, const ParameterList &metricsParameters, std::ostringstream &msg_stream)
Analyze metrics for a problem based on a range of tolerances.
#define KEYWORD_PARAMETER_NAME
A class that computes and returns quality metrics.
#define WEIGHT_PARAMETER_NAME
std::string parameterDescription