⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gzloader.cpp

📁 多核环境下运行了可满足性分析的工具软件
💻 CPP
字号:
/********************************************************************************************MiraXT -- Copyright (c) 2007, Tobias Schubert, Matthew Lewis, Natalia Kalinnik, Bernd Becker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies orsubstantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.********************************************************************************************/namespace minisat {#define CHUNK_LIMIT 1048576  bool transferClauses(mira::clauseDB * theClauseDB, minisat::SimpSolver& simp)  {    numClauses  = simp.clauses.size();    numLiterals = simp.nVars();    theClauseDB->clauseDBGrow(numClauses);    mira::vec<int> actual_clause;    actual_clause.growTo(maxClauseLength);    theClauseDB->clauseDBGrow(numClauses);    for(int i=0; i<numClauses; i++)      {	minisat::Clause& c = *simp.clauses[i];	actual_clause.clearFast();	for (int i = 0; i < c.size(); i++)	  {	    actual_clause.push(toInt(c[i])+2);	  }	actual_clause.push(0);	assert(actual_clause.size() != 1);	theClauseDB->addNewClauseInit(actual_clause, actual_clause.size(),0);      }    int max = simp.trail.size();    int newClause[2];    newClause[1]=0;    for(int i=0; i<max; i++)      {	newClause[0]=toInt(simp.trail[i])+2;	assert(newClause[0] > 1);	theClauseDB->addNewClauseInit(newClause, 2, 0);      }    return true;  }  int clausesize(minisat::SimpSolver& simp)  {    numClauses = simp.clauses.size();    return numClauses;  }    class StreamBuffer   {    gzFile  in;    char    buf[CHUNK_LIMIT];    int     pos;    int     size;    void assureLookahead()     {      if (pos >= size) 	{	  pos  = 0;	  size = gzread(in, buf, sizeof(buf)); 	}     }    public:        StreamBuffer(gzFile i) : in(i), pos(0), size(0)     {      assureLookahead();     }    int  operator *  () { return (pos >= size) ? EOF : buf[pos]; }    void operator ++ () { pos++; assureLookahead(); }  };  template<class B>  static void skipWhitespace(B& in)   {    while ((*in >= 9 && *in <= 13) || *in == 32) { ++in; }  }  template<class B>  static void skipLine(B& in)   {    for (;;)      {        if (*in == EOF || *in == '\0') { return; }        if (*in == '\n') { ++in; return; }        ++in;       }   }  template<class B>  static int parseInt(B& in)   {    int  val = 0;    bool neg = false;    skipWhitespace(in);    if (*in == '-') { neg = true, ++in; }    else { if (*in == '+') ++in; }    if (*in < '0' || *in > '9')       { 	// Something went wrong.	fprintf(stdout,"c CNF file error\n"); 	fprintf(stdout,"s UNKNOWN\n");	// Exit code 0: UNKNOWN.	exit(0);      }    while (*in >= '0' && *in <= '9') { val = val*10 + (*in - '0'); ++in; }    return neg ? -val : val;   }  template<class B>  static void readClause(B& in, SimpSolver& S, vec<Lit>& lits)   {    int parsed_lit, var;    lits.clear();    for (;;)      {	parsed_lit = parseInt(in);	if (parsed_lit == 0) { break; }	var = abs(parsed_lit)-1;	while (var >= S.nVars()) { S.newVar(); }        lits.push( (parsed_lit > 0) ? Lit(var) : ~Lit(var) );      }  }  template<class B>  static bool match(B& in, char* str)   {    for (; *str != 0; ++str, ++in) { if (*str != *in) { return false; } }    return true;  }  template<class B>  static void parse_DIMACS_main(B& in, SimpSolver& S)   {    vec<Lit> lits;    for (;;)      {        skipWhitespace(in);        if (*in == EOF) 	  { break; }        else	  { 	    if (*in == 'p')	      {		if (match(in, "p cnf"))		  {		    numClausesOrig = parseInt(in);		    numClausesOrig = parseInt(in);		    if (numClausesOrig > 4000000) { S.eliminate(true); }		  }		else		  {		    // Something went wrong.		    fprintf(stdout,"c CNF file error\n"); 		    fprintf(stdout,"s UNKNOWN\n");		    // Exit code 0: UNKNOWN.		    exit(0);		  }			      } 	    else 	      {		if (*in == 'c' || *in == 'p')		  { skipLine(in); }		else		  { readClause(in, S, lits); S.addClause(lits); }	      }	  }      }  }  static void parse_DIMACS(gzFile input_stream, SimpSolver& S)   {    StreamBuffer in(input_stream);    parse_DIMACS_main(in, S);   }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -