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


C++ Formula::set_number_variables方法代码示例

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


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

示例1: DIMACS_Input

  void DIMACS_Input(std::istream& in, Formula& F) {

    // NOCH ZU TUN:
    // Verbesserte Fehlermeldungen:
    //  - mehrsprachig
    //  - Position im Eingabe-Strom (Zeilennummer, absolute Position)
    // Klaerung der DIMACS-Syntax

    // Formula : Concept Formula-Constructor
    // Assumption: Formula::Lit::Var can be constructed via strings as names

    // Syntax:
    // First lines with comments, starting with "c";
    // then a line "p cnf n c";
    // then the clauses, where variables are denoted by names, literals are separated by spaces, completed by "0";
    // names: non-empty sequence of characters without space symbols and not starting with "-" and not equal to "0"
    // literals: either a name or "-" immediately followed by a name

    typedef typename Formula::size_type size_type;
    typedef typename Formula::Lit Lit;
    typedef typename Lit::Var Var;

    using namespace std;

    streamsize nr_lines = 1;

    {
      vector<string> comment_lines;
      string token;
      // reading comments, until the parameter line is found
      for (;; ++nr_lines) {
	in >> token;
	if (not in)
	  throw ReadError("DIMACS_Input(std::istream& in, Formula& F) : line " + StringHandling::toString(nr_lines));
	if (token == "p") {
	  in >> token;
	  if (token == "cnf")
	    break;
	  else
	    throw MissingCnfError("DIMACS_Input(std::istream& in, Formula& F) : line " + StringHandling::toString(nr_lines) + ", parameter line has token \"" + token + "\" instead of \"cnf\"");
	}
	if (token[0] != 'c')
	  throw SyntaxError("DIMACS_Input(std::istream& in, Formula& F) : Non-comment line before parameter line; line " + StringHandling::toString(nr_lines) + ", first token \"" + token + "\"");
	string rest_of_line;
	getline(in, rest_of_line);
	comment_lines.push_back(token + rest_of_line);
      }
      
      {
	size_type n, c;
	in >> n >> c;
	if (not in)
	  throw ParameterError("DIMACS_Input(std::istream& in, Formula& F) : invalid parameter values; line " + StringHandling::toString(nr_lines));
	{
	  string rest_of_line;
	  getline(in, rest_of_line);
	  if (not rest_of_line.empty())
	    throw AfterParameterError("DIMACS_Input(std::istream& in, Formula& F) : line " + StringHandling::toString(nr_lines) + ", rest of line after parameter values is not empty, but is \"" + rest_of_line + "\"");
	}
	
	F.set_number_variables(n);
	F.set_number_clauses(c);
	F.begin_construction();
      }
      
      for (vector<string>::const_iterator i = comment_lines.begin(); i != comment_lines.end(); ++i)
	F.comment_line(*i);
    }
开发者ID:MGwynne,项目名称:oklibrary,代码行数:68,代码来源:InputCls.hpp


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