Example #1
0
/**
@brief Used when a variable was eliminated, but it replaced some other variables

This function will add to solver2 clauses that represent the relationship of
the variables to their replaced cousins. Then, calling solver2.solve() should
take care of everything
*/
void VarReplacer::extendModelImpossible(Solver& solver2) const
{

    #ifdef VERBOSE_DEBUG
    std::cout << "extendModelImpossible() called" << std::endl;
    #endif //VERBOSE_DEBUG

    vec<Lit> tmpClause;
    uint32_t i = 0;
    for (vector<Lit>::const_iterator it = table.begin(); it != table.end(); it++, i++) {
        if (it->var() == i) continue;
        if (solver.assigns[it->var()] == l_Undef) {
            assert(solver.assigns[it->var()] == l_Undef);
            assert(solver.assigns[i] == l_Undef);

            tmpClause.clear();
            tmpClause.push(Lit(it->var(), true));
            tmpClause.push(Lit(i, it->sign()));
            solver2.addClause(tmpClause);
            assert(solver2.ok);

            tmpClause.clear();
            tmpClause.push(Lit(it->var(), false));
            tmpClause.push(Lit(i, it->sign()^true));
            solver2.addClause(tmpClause);
            assert(solver2.ok);
        }
    }
}
Example #2
0
int getPredecessors(Solver& S, int attr_number, int num_var, int curr_depth) {
    vec<Lit> lits;

    int nBasins = 0;

    int i = num_var;
    
    while (i--){
      lits.push((global_var.Attractors[attr_number].states[0].c_str()[i]=='1')? Lit(i) : ~Lit(i));
      S.addClause(lits);
      lits.clear();
    }

    
    i = num_var;
    while (i--){
        lits.push((global_var.Attractors[attr_number].states[0].c_str()[i]=='1')? ~Lit(i+num_var) : Lit(i+num_var));
    }
    S.addClause(lits);
    lits.clear();
    
    while (1){
      if (!S.solve()) break;

      constrain_state(curr_depth-1, S.model, curr_depth-1, S, num_var);

      nBasins++;
    }

    return nBasins;
}
Example #3
0
/*Make state with index a from the stats_sequance not allowed in future solutions of S in position with index b */
void constrain_state(unsigned a, vec<lbool>& stats_sequance, unsigned b, Solver &S, unsigned number_var ){

  vec<Lit> lits;
  int a_tmp=a*number_var;
  int b_tmp=b*number_var;

  ASSERT( a_tmp+number_var <= stats_sequance.size() );
  ASSERT( b_tmp+number_var <= S.nVars() );

  while(number_var--){
    if (stats_sequance[a_tmp] != l_Undef){

#ifdef PRINT_STATE
	//printf( "%s", (stats_sequance[a_tmp]==l_True)?"1":"0");
#endif 
	
	    lits.push((stats_sequance[a_tmp]==l_True)?~Lit( b_tmp ):Lit( b_tmp ));
    }else{
	//printf("-");
    }
    a_tmp++;
    b_tmp++;
  }
  S.addClause(lits);

#ifdef PRINT_STATE
    //puts(" ");
#endif  
}
Example #4
0
void add_clauses_with_variable_shift( std::vector< std::vector<Lit> > &clauses2add, Solver &S,int shift){

  unsigned i;
  vec<Lit> lits;
  lits.clear();  

  i=clauses2add.size();
  while(i--){//PRINT(i); /*ckhong: no change in orig_clauses*/
    int j=clauses2add[i].size();//PRINT(j);  
    while(j--){//PRINT(toInt(clauses2add[i][j])); PRINT(toInt(clauses2add[i][j]) + (shift+shift));
      lits.push(toLit( toInt(clauses2add[i][j]) + (shift+shift) ));
    }
   
    /*
    j=lits.size();
    while(j--){
      PRINT(toInt(lits[j]));

    }
    */

    S.addClause(lits);
    lits.clear();    
  }
 
}
Example #5
0
int main(int argc, char *argv[])
{
  Solver s = Solver();
  char c;
  std::string in;
  int n_vars, n_clauses, var;
  cin >> c;
  while(c == 'c')
    {
      cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
      cin >> c;
    }
  if(c != 'p')
    {
      cerr << "Incorrect input format" << endl;
      return 1;
    }
  cin >> in;
  if (in != "cnf")
    {
      cerr << "Format not supported: " << in << endl;
      return 1;
    }
  cin >> n_vars >> n_clauses;
  for (int i = 0; i < n_vars; ++i)
    {
      s.newVar ();
    }
  lit_vec cl;
  while(!cin.eof())
    {
      cin >> var;
      if (var != 0)
        {
            p_lit l(new lit(var));
            cl.push_back(l);
        }
      else
        {
          lit_vec add(cl);
          s.addClause(add);
          cl.clear();
        }
    }
  if (s.solve()) {
      cout << "Sat! " << endl
           << "solution : " << s.getModel() << endl;
  } else {
      cout << "Unsat!" << endl;
  }
  return 0;
}
Example #6
0
static void parse_DIMACS_main(B& in, Solver& S) {
    vec<Lit> lits;
    for (;;){
        skipWhitespace(in);
        if (*in == EOF)
            break;
        else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else
            readClause(in, S, lits),
            S.addClause(lits);
    }
}
/*
 * Class:     kodkod_engine_satlab_MiniSat
 * Method:    addClause
 * Signature: (J[I)Z
 */
JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_addClause
  (JNIEnv * env, jobject, jlong solver, jintArray clause) {
    jsize length = env->GetArrayLength(clause);
    jint* buf = env->GetIntArrayElements(clause, JNI_FALSE);
    Solver* solverPtr = ((Solver*)solver);
    vec<Lit> lits;
    for(int i = 0; i < length; ++i) {
        int var = *(buf+i);
        lits.push((var > 0) ? Lit(var-1) : ~Lit(-var-1));
    }
    solverPtr->addClause(lits);
    env->ReleaseIntArrayElements(clause, buf, 0);
    return solverPtr->okay();
 }
Example #8
0
static bool parse_BCNF(cchar* filename, Solver& S)
{
    FILE*   in = fopen(filename, "rb");
    if (in == NULL) fprintf(stderr, "ERROR! Could not open file: %s\n", filename), exit(1);

    char    header[16];
    fread(header, 1, 16, in);
    if (strncmp(header, "BCNF", 4) != 0) fprintf(stderr, "ERROR! Not a BCNF file: %s\n", filename), exit(1);
    if (*(int*)(header+4) != 0x01020304) fprintf(stderr, "ERROR! BCNF file in unsupported byte-order: %s\n", filename), exit(1);

    int      n_vars    = *(int*)(header+ 8);
    //int    n_clauses = *(int*)(header+12);
    int*     buf       = xmalloc<int>(CHUNK_LIMIT);
    int      buf_sz;
    vec<Lit> c;

    for (int i = 0; i < n_vars; i++) S.newVar();

    for(;;){
        int n = fread(&buf_sz, 4, 1, in);
        if (n != 1) break;
        assert(buf_sz <= CHUNK_LIMIT);
        fread(buf, 4, buf_sz, in);

        int* p = buf;
        while (*p != -1){
            int size = *p++;
            c.clear();
            c.growTo(size);
            for (int i = 0; i < size; i++)
                c[i] = toLit(p[i]);
            p += size;

            S.addClause(c);     // Add clause.
            if (!S.okay()){
                xfree(buf); fclose(in);
                return false; }
        }
    }

    xfree(buf);
    fclose(in);

    S.simplifyDB();
    return S.okay();
}
Example #9
0
void read_minterm_file_to_solver(char * fileName, Solver &S,int *input_array,int input_array_size , Lit output_lit){

  char temp[MAX_LENGTH];
  FILE *fp;
  vec<Lit> lits;
  int i;


  //printf("%d ",toInt(output_lit));
  //getchar();
  lits.clear();

  if ((fp = fopen(fileName, "r")) == NULL) {
    fprintf(stderr, "Couldn't open file: %s\n", fileName);
    exit (1);
  }

  while(!feof(fp)) {
    fgets(temp,MAX_LENGTH, fp);
    if( temp[0]=='0' || temp[0]=='1' || temp[0]=='-'){
      break;
    }
  }

  for(i=0;i<input_array_size;i++){
    //PRINT(input_array[i]);
  }
  while(temp[0]!='.'){
    //puts(temp);
    for(i=0;i<input_array_size;i++){
      if(temp[i]=='-')
	    continue;
      lits.push( (temp[i]=='1') ? ~Lit( input_array[i] - INDEX_OF_FIRST_VARIABLE ) : Lit(input_array[i] - INDEX_OF_FIRST_VARIABLE ) );
      //printf("%d:%d ",i,toInt(lits[lits.size()-1]));
    }
    //puts(" ");
    lits.push( output_lit );
    S.addClause(lits);
    lits.clear();
    
    fgets(temp,MAX_LENGTH, fp);
  }

  fclose(fp);
}
Example #10
0
static bool parse_DIMACS_main(char* in, Solver& S) {
    vec<Lit>    lits;
    for (;;){
        skipWhitespace(in);
        if (*in == 0)
            break;
        else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else{
            readClause(in, S, lits);
            S.addClause(lits);
            if (!S.okay())
                return false;
        }
    }
    S.simplifyDB();
    return S.okay();
}
Example #11
0
static void parse_DIMACS_main(B& in, Solver& S) {
    vec<Lit> lits;
    for (;;){
        skipWhitespace(in);
        if (*in == EOF)
            break;
        else if (*in == 'p'){
            if (match(in, "p cnf")){
                int vars    = parseInt(in);
                int clauses = parseInt(in);
                reportf("|  Number of variables:  %-12d                                         |\n", vars);
                reportf("|  Number of clauses:    %-12d                                         |\n", clauses);
            }else{
                reportf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
            }
        } else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else
            readClause(in, S, lits),
            S.addClause(lits);
    }
}
Example #12
0
void PartHandler::moveClauses(vec<Clause*>& cs, Solver& newSolver, const uint32_t part, PartFinder& partFinder)
{
    Clause **i, **j, **end;
    for (i = j = cs.getData(), j = i , end = i + cs.size(); i != end; i++) {
        if ((**i).learnt() || partFinder.getVarPart((**i)[0].var()) != part) {
            *j++ = *i;
            continue;
        }
        solver.detachClause(**i);
        #ifdef VERBOSE_DEBUG
        std::cout << "clause in this part:"; (**i).plainPrint();
        #endif

        Clause& c = **i;
        vec<Lit> tmp(c.size());
        std::copy(c.getData(), c.getDataEnd(), tmp.getData());
        newSolver.addClause(tmp, c.getGroup());
        //NOTE: we need the CS because otherwise, the addClause could have changed **i, which we need to re-add later!
        clausesRemoved.push(*i);
    }
    cs.shrink(i-j);
}
Example #13
0
/* Read in NET file and returns 2^n transition function*/
void
ReadNET(char *fileName, Solver& S)
{

  char temp[MAX_LENGTH];
  char slask[MAX_LENGTH];
  int i , k , tmp_1;

  int input_array[MAX_NUMBER_OF_INPUTS];
  int number_of_inputs,current_number_of_inputs=0;
  int current_var;
  FILE *fp,*fp_temp;      
  vec<Lit> lits;
  std::vector<Lit> lits_std;

  unsigned line_count=0;

//the following allows counting of line
#define fgets(X,Y,Z);  fgets((X),(Y),(Z));line_count++;  

  /* Open NET file for reading */
  if ((fp = fopen(fileName, "r")) == NULL) {
    fprintf(stderr, "Couldn't open NET file: %s\n", fileName);
    exit (1);
  }

  /* Reading number of non-redundent var*/
  while(!feof(fp)) {
    fgets(temp,MAX_LENGTH, fp);
    if (strncmp(temp,".v",2)==0) {
      /* Find size of the cubes */
      sscanf(temp, "%s %i", slask, &number_of_var);
      break;
    }
  }
  var2red_var=(int*) calloc(number_of_var+1, sizeof(int));

  size_nonred_array=number_of_var;

  redunt_number_of_var=number_of_var;
  redunt_var2var=(int*) calloc(redunt_number_of_var+1, sizeof(int));

  number_print_var=number_of_var;

  int count_nodes;
  for(count_nodes=1; count_nodes<=number_of_var; count_nodes++ ){
    redunt_var2var[count_nodes]=count_nodes;
    var2red_var[count_nodes]=count_nodes;
  }

 
  if(feof(fp)) {
    fprintf(stderr, "Wrong format of input file. End of file is reached but no node function is red" );
    exit(1);
  }
  
  k=number_of_var;
  while(k--){
    S.newVar();S.newVar();
  }
  
  //RBN_init_global_var(bdd_manager);

  /*-------------------- Filling information about nodes  -------------------*/
  while(!feof(fp)){
    fgets(temp,MAX_LENGTH, fp);
  next_vertex:
    if (strncmp(temp,".n",2)==0) {
      /* Find size of the cubes */

      i=3;
      sscanf(&temp[i],"%d",&current_var);

      if( current_var < 0 || current_var >redunt_number_of_var){
	    fprintf(stderr, "Wrong format of input file in line %d.The varible %d in string:\n %s exceeds number of declared variables.\n",line_count, current_var,temp);
	    exit (1);
      }
      
      i++;
      /* go to first space */
      while(temp[i]!=' '){
	    if(temp[i]=='\n'){
	      fprintf(stderr, "Wrong format of input file in line %d. Wrong format of the string: %s\n",line_count, temp );
	      exit (1);
	    }
	    i++;
      }
      i++;
      /* go to the end of sequense of spaces */
      while(temp[i]==' '){
	    i++;
      }
      if(temp[i]=='\n'){
	    fprintf(stderr, "Wrong format of input file in line %d. Wrong format of the string: %s\n",line_count, temp );
	    exit (1);
      }
      sscanf(&temp[i],"%d",&number_of_inputs);

      if(number_of_inputs > MAX_NUMBER_OF_INPUTS){
	    fprintf(stderr, "Wrong format of input file in line %d . Number of inputs exceeds allowed number of inputs %s\n",line_count, temp  );
	    exit (1);
      }
      
      while(1){
	    i++;
	    while(temp[i]!=' '){
	      if(temp[i]=='\n'){
	        goto end_loops;
	      }
	      i++;
	    }
	    i++;
	/* go to the end of sequense of spaces */
	    while(temp[i]==' '){
	      i++;
	    }
	    if(temp[i]=='\n'){
	      goto end_loops;
	    }
	    sscanf(&temp[i],"%d",&tmp_1);

	    if( tmp_1 < 0 || tmp_1 >redunt_number_of_var){
	      fprintf(stderr,"Wrong format of input file in line %d. The varible %d in string:\n %s exceeds number of declared variables.\n",line_count, tmp_1,temp);
	      exit (1);
	    }
	
	    if( redunt_var2var[tmp_1] == 0){
	      fprintf(stderr, "Wrong format of input file in line %d. One of the input was not declared in list of inputs %s\n",line_count, temp  );
	      exit (1);
	    }

	    input_array[current_number_of_inputs++]= redunt_var2var[tmp_1];
      }
    
    end_loops:
      if(current_number_of_inputs!=number_of_inputs){
	    fprintf(stderr, "Wrong format of input file in line %d. Declared number of inputs is not equal to actual number of input %s\n",line_count, temp  );
	    exit (1);
      }

      if(number_of_inputs==0){
	    fgets(temp,MAX_LENGTH, fp);
	  
	    if( temp[0]=='1'){
	      lits.push( Lit( current_var - INDEX_OF_FIRST_VARIABLE ) );
	      S.addClause(lits);
	      lits.clear();
	    }else{
	      if( temp[0]!='0'){
	        printf("Node %d assumed to be constant 0\n",current_var);
	      }
	      lits.push( ~Lit( current_var - INDEX_OF_FIRST_VARIABLE ) );
	      S.addClause(lits);
	      lits.clear();
	    }
	    goto next_vertex;
      }

      /*---------------  Reading in the function of the node ---------------*/

      current_number_of_inputs=0;

      while(!feof(fp)){
	    fgets(temp,MAX_LENGTH, fp);
	    if( temp[0]=='0' || temp[0]=='1' || temp[0]=='-'){

	      for(i=0;i<number_of_inputs;i++){
	        if(temp[i]=='-')
	          continue;
            //PRINT(input_array[i]);
	        lits.push( (temp[i]=='1') ? ~Lit( number_of_var + input_array[i] - INDEX_OF_FIRST_VARIABLE) : Lit(number_of_var + input_array[i] - INDEX_OF_FIRST_VARIABLE) );

	        if(temp[i]!='1' && temp[i]!='0'){
	          fprintf(stderr, "Wrong format of input file in line %d. Wrong line:%s\n",line_count, temp  );
	          exit (1);	
	        }      
	      }

	      ASSERT((number_of_var + current_var - INDEX_OF_FIRST_VARIABLE) < S.nVars());

	      i++;
	      if(temp[i]=='1'){
	        lits.push( Lit(  current_var - INDEX_OF_FIRST_VARIABLE ) );
	      }else{
	        if(temp[i]=='0'){
	          lits.push( ~Lit( current_var - INDEX_OF_FIRST_VARIABLE ) );
	        }else{
	          fprintf(stderr, "Wrong format of input file in line %d. Unexpected charecter in output of minterm in line:%s\n",line_count, temp  );
	          exit (1);	
	        }
	      }
	      S.addClause(lits);
          
          //PRINT(current_var);
          for (int x=0; x<lits.size();x++) {
            //PRINT(toInt(lits[x]));  
          }

	      if(lits.size()==2){
	     //PRINT(lits.size());
            for(int j=0; j<lits.size();j++){
           	//PRINT(toInt(lits[j]));
              lits_std.push_back(lits[j]);
        	}
            (*global_var.orig_clauses).push_back( lits_std );
            lits_std.clear();
	      }
	      lits.clear();	 
	    }else{

	      if( redunt_var2var[current_var] == 0){
	        fprintf(stderr, "Wrong format of input file.The node:%d was not declared \n", current_var  );
	        exit (1);
	      }
	  
	      break; 
	    }	
      }
	  
      if(!feof(fp)){
	    goto next_vertex;
      }

      /*We are here after we reach the end of the file*/
      if( redunt_var2var[current_var] == 0){
	    fprintf(stderr, "Wrong format of input file.The node:%d was not declared \n", current_var  );
	    exit (1);
      }
    }/* -------- end processing input informaition of a vertex ------------*/
  }
/*end processing the file*/
  
  fclose(fp);
  
#undef fgets(X,Y,Z);

}
Example #14
0
File: test.c Project: marcu/ATC4QBF
int main(int argc, char** argv)
{
    Solver      S;
    Solver      T;
    vec<Lit> lits;
    vec<Lit> lits2;
    vec<Lit> lits3;
    vec<Lit> lits4;
    vec<Lit> lits5;
    vec<Lit> lits6;
    vec<Lit> lits0;
    lits.clear();
    lits2.clear();
    T.newVar();
    T.newVar();
    T.newVar();
    T.newVar();
    T.newVar();
    T.newVar();
    T.newVar();
    T.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    S.newVar();
    lits0.clear();
    lits0.push(Lit(0));
    unsigned int i;
    int parsed_lit = -1;
    lits.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 1;
    lits.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    S.addClause(lits);
    T.addClause(lits);
    parsed_lit = 2;
    printf("lalla1\n");
    lits3.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 3;
    lits3.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -4;
    lits3.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -2;
    lits4.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 5;
    lits4.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -6;
    lits4.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 3;
    lits5.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -5;
    lits5.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 10;
    lits5.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -3;
    lits6.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -7;
    lits6.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -10;
    lits6.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    lits6.push( (parsed_lit > 0) 
               ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = -100;
    lits2.push( (parsed_lit > 0) ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    parsed_lit = 100;
    lits2.push( (parsed_lit > 0) ? Lit(abs(parsed_lit)-1) : ~Lit(abs(parsed_lit)-1) );
    S.addClause(lits2);
    T.addClause(lits2);
    printf("lalla2\n");
    S.addClause(lits3);
    T.addClause(lits3);
    printf("lalla3\n");
    printf("Snvas %i \n", S.nVars());
    S.addClause(lits4);
    T.addClause(lits4);
    printf("lalla4\n");
    S.addClause(lits5);
    T.addClause(lits5);
    printf("lalla5\n");
    S.addClause(lits6);
    T.addClause(lits6);
    printf("lallala\n");
    bool ret = S.solve();
    printf(ret ? "SATISFIABLE\n" : "UNSATISFIABLE\n");
    ret = T.solve();
    printf(ret ? "SATISFIABLE\n" : "UNSATISFIABLE\n");
}
Example #15
0
//int getPredecessors(Solver& S, const char *state, int num_var, int curr_depth) {
int getPredecessors( std::vector< std::vector<Lit> > &orig_clauses, const char *state, int num_var, int curr_depth) {
    vec<Lit> lits;
    //global_var.basins.push_back(state);

    int number_of_predecessors = 1;

    /*
    if (curr_depth == 12){ 
        //printf("\n");
        return number_of_predecessors;
    }*/

    Solver S;
    int i = num_var;
    while (i--){
        S.newVar(); S.newVar();
    }
    add_clauses_with_variable_shift(orig_clauses, S, 0);
    
    //char state_[] = "000001000000";

    i = num_var;
    while (i--){
      lits.push((state[i]=='1')? Lit(i) : ~Lit(i));
      S.addClause(lits);
      lits.clear();
    }

    i = num_var;
    while (i--){
        lits.push((state[i]=='1')? ~Lit(i+num_var) : Lit(i+num_var));
    }
    S.addClause(lits);
    lits.clear();

    int nDirectPredecessors = 0;

    while (1){
      if (!S.solve()) break;

      int a_tmp=num_var;
      int b_tmp=0;
      int counter=num_var;

      char tState[num_var];

      while(counter--){
        if(S.model[a_tmp] != l_Undef){
          //printf("%s", (S.model[a_tmp]==l_True)? "1":"0");
          sprintf(tState+b_tmp, "%s", (S.model[a_tmp]==l_True)? "1":"0"); 
        } else{
          //printf("-");
          sprintf(tState+b_tmp, "-");
        }
        a_tmp++;
        b_tmp++;
      }
      //printf("%s <- %s, ", state, tState);
      //PRINT(curr_depth);
      number_of_predecessors = number_of_predecessors + getPredecessors(orig_clauses, tState, num_var, curr_depth + 1);
      
      //constrain_state(curr_depth, S.model, curr_depth, S, num_var);
      
      i = num_var;
      while (i--){
          if (strcmp(tState, "-")) {
            lits.push((tState[i]=='1')? ~Lit(i+num_var) : Lit(i+num_var));
          }
          else {
          }
      }
      S.addClause(lits);
      lits.clear();
      nDirectPredecessors++;
    }

    

    /*
    if (nDirectPredecessors > MAX_NUMBER_OF_HUBS) {
        global_var.hubs.push_back(state);    
    }*/

    return number_of_predecessors;
}
Example #16
0
   void formulate(int p, int n, Solver& s) {
      _p = p; _n = n;
      for (int i = 0; i < N*(p+n); ++i)
         s.newVar();
      for (int i = 0; i < N; ++i)
         for (int j = 0; j < i; ++j) {
            if (intersect(i, j)) {
               for (int r = 1; r <= p; ++r) {
                  Lit a = vn(i, r);
                  Lit b = vn(j, r);
                  s.addBinary(~a, ~b);
               }
               for (int r = -1; r >= -n; --r) {
                  Lit a = vn(i, r);
                  Lit b = vn(j, r);
                  s.addBinary(~a, ~b);
               }
            }
         }
      for (int i = 0; i < N; ++i) {
         for (int j = 0; j < N; ++j) {
            if (i == j) continue;
            if (!contain(i, j)) continue;
            for (int pj = 1; pj <= p-1; ++pj) {
               for (int pi = pj+1; pi <= p; ++pi) {
                  Lit a = vn(i, pi);
                  Lit b = vn(j, pj);
                  s.addBinary(~a, ~b);
               }
            }
            for (int pj = -1; pj >= -n+1; --pj) {
               for (int pi = pj-1; pi >= -n; --pi) {
                  Lit a = vn(i, pi);
                  Lit b = vn(j, pj);
                  s.addBinary(~a, ~b);
               }
            }
         }
      }

      // Exact one for each color
      /*vec<Lit>* c;
      for (int i = 0; i < N; ++i) {
         c = new vec<Lit>;
         c->growTo(n+p);
         for (int pi = 1; pi <= p; ++pi)
            (*c)[i-1] = vn(i, pi);
         for (int pi = -1; pi >= -n; --pi)
            (*c)[p-pi-1] = vn(i, pi);
         s.addClause(*c);
         for (int j = 0; j < n+p; ++j)
            for (int k = 0; k < j; ++k) {
               s.addBinary(~vnalt(i, j), ~vnalt(i, k));
            }
      }*/
      for (int i = 0; i < N; ++i) {
         vec<Lit> c;
         c.growTo(n+p);
         for (int j = 0; j < n+p; ++j)
            c[j] = vnalt(i, j);
         s.addClause(c);
      }
      for (int i = 0; i < N; ++i) {
         for (int j = 0; j < n+p; ++j)
            for (int k = 0; k < j; ++k) {
               s.addBinary(~vnalt(i, j), ~vnalt(i, k));
            }
      }
   }