当前位置: 首页>>代码示例>>C++>>正文


C++ Alphabet::getMasses方法代码示例

本文整理汇总了C++中Alphabet::getMasses方法的典型用法代码示例。如果您正苦于以下问题:C++ Alphabet::getMasses方法的具体用法?C++ Alphabet::getMasses怎么用?C++ Alphabet::getMasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Alphabet的用法示例。


在下文中一共展示了Alphabet::getMasses方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {
	Options options;
	try {
		options.parse(argc, argv);
	} catch (TCLAP::ArgException &e) {
		throw ims::Exception("Error while parsing command line: " + e.error() + " for argument " + e.argId());
	}
	Alphabet alphabet;
	try {
		alphabet.load(options.getAlphabetFileName());
	} catch (IOException& ioe) {
		cerr << "can not read alphabet: " << ioe.what() << endl;
		return 1;
	}
	Weights weights(alphabet.getMasses(), 1 /*precision*/);

	// optimize alphabet by dividing by gcd
	weights.divideByGCD();

	// get masses from -m options and/or from a file
	vector<double> masses = options.getMasses();
	if (options.hasMassFile()) {
		MassesTextParser parser;
		try {
			parser.load(options.getMassFile());
		} catch (IOException& ioe) {
			cerr << "can not read masses file: " << ioe.what() << endl;
			return 1;
		}
		vector<double> filemasses = parser.getElements();
		// append to masses
		copy(filemasses.begin(), filemasses.end(), back_inserter(masses));
	}
	if (masses.empty()) {
		cerr << "No input masses given to decompose (use -m or -f option)!\n";
		return 1;
	}

	// maximal number of decompositions to show
	unsigned int maxNumber = options.getMaxNumberDecompositions();

	printHeader(alphabet, weights, options.getMode());

	if (options.getMode() == Options::GETNUMBER) {
		ClassicalDPMassDecomposer<> decomposer(weights);

		// loop through masses
		for (vector<double>::const_iterator it = masses.begin(); it != masses.end(); ++it) {
			value_type mass = static_cast<value_type>(*it);

			decomposition_value_t number = decomposer.getNumberOfDecompositions(mass);
			cout << "# mass " << mass << " has " << number << " decompositions" << endl;
		}
	} else { // if any other tasks defined
		// use decomposer with residues
		IntegerMassDecomposer<> decomposer(weights);

		if (options.getMode() == Options::FINDALL) {
			// loop through masses
			for (vector<double>::const_iterator it = masses.begin(); it != masses.end(); ++it) {
				value_type mass = static_cast<value_type>(*it);
				outputDecompositions(decomposer.getAllDecompositions(mass), alphabet, mass, maxNumber);
				cout << '\n';
			}
		}
		else if (options.getMode() == Options::FINDONE) {
			// loop through masses
			for (vector<double>::const_iterator it = masses.begin(); it != masses.end(); ++it) {
				value_type mass = static_cast<value_type>(*it);
				decomposition_t decomposition = decomposer.getDecomposition(mass);
				if (decomposition.size() == 0) {
					cout << "# mass " << mass << " has 0 decompositions\n\n";
				} else {
					cout << "# mass " << mass << " has at least this decomposition:\n";
					printDecomposition(alphabet, decomposition);
					cout << "\n\n";
				}
			}
		}
		else if (options.getMode() == Options::ISDECOMPOSABLE) {
			// loop through masses
			for (vector<double>::const_iterator it = masses.begin(); it != masses.end(); ++it) {
				value_type mass = static_cast<value_type>(*it);
				if (decomposer.exist(mass)) {
					cout << "# mass " << mass << " has at least one decomposition\n";
				} else {
					cout << "# mass " << mass << " has no decompositions\n";
				}
			}
		}
	}
	cout << "# done\n";

	return 0;
}
开发者ID:nathaniel-mahieu,项目名称:Rdisop,代码行数:95,代码来源:imsintdecomp.cpp


注:本文中的Alphabet::getMasses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。