Esempio n. 1
0
void ComputationManager::initializeDepqbf() {
    depqbf = qdpll_create();
    std::string depMan = "--dep-man=qdag";
    std::vector<char> depManC(depMan.begin(), depMan.end());
    depManC.push_back('\0');
    qdpll_configure(depqbf, &depManC[0]);

    for (unsigned int level = 1; level <= app.getInputInstance()->getQuantifierSequence().size(); level++) {
        NTYPE quantifier = app.getInputInstance()->quantifier(level);
        switch (quantifier) {
            case NTYPE::EXISTS:
                qdpll_new_scope(depqbf, QDPLL_QTYPE_EXISTS);
                break;
            case NTYPE::FORALL:
                qdpll_new_scope(depqbf, QDPLL_QTYPE_FORALL);
                break;
            default:
                ; //error
        }

        for (htd::vertex_t vertex : app.getInputInstance()->hypergraph->internalGraph().vertices()) {
            unsigned int vertexLevel = htd::accessLabel<int>(app.getInputInstance()->hypergraph->internalGraph().vertexLabel("level", vertex));
            if (level == vertexLevel) {
                qdpll_add(depqbf, vertex);
            }
        }
        qdpll_add(depqbf, 0); // end scope
    }

    for (htd::Hyperedge edge : app.getInputInstance()->hypergraph->internalGraph().hyperedges()) {
        htd::id_t edgeId = edge.id();
        const std::vector<bool> &edgeSigns = htd::accessLabel < std::vector<bool>>(app.getInputInstance()->hypergraph->edgeLabel("signs", edgeId));

        std::vector<bool>::const_iterator index = edgeSigns.begin();
        for (const auto& vertex : edge) {
            if (*index) {
                qdpll_add(depqbf, vertex);
            } else {
                qdpll_add(depqbf, -vertex);
            }
            index++;
        }
        qdpll_add(depqbf, 0); // end clause
    }

    qdpll_init_deps(depqbf);
}
Esempio n. 2
0
JNIEXPORT jint JNICALL Java_depqbf4j_DepQBF4J_newScope (JNIEnv * env, jclass cls, jbyte qType) {
	return qdpll_new_scope(solver,qType);
}
Esempio n. 3
0
static void
parse (QDPLLApp * app, QDPLL * qdpll, FILE * in, int trace)
{
  int col = 0, line = 0, neg = 0, preamble_found = 0;
  LitID num = 0;
  QDPLLQuantifierType scope_type = QDPLL_QTYPE_UNDEF;

  assert (in);

  int c;
  while ((c = getc (in)) != EOF)
    {
      PARSER_SKIP_SPACE_WHILE (c);

      while (c == 'c')
        {
          while ((c = getc (in)) != '\n' && c != EOF)
            ;
          c = getc (in);
        }

      PARSER_SKIP_SPACE_WHILE (c);

      if (c == 'p')
        {
          /* parse preamble */
          PARSER_SKIP_SPACE_DO_WHILE (c);
          if (c != 'c')
            goto MALFORMED_PREAMBLE;
          PARSER_SKIP_SPACE_DO_WHILE (c);
          if (c != 'n')
            goto MALFORMED_PREAMBLE;
          PARSER_SKIP_SPACE_DO_WHILE (c);
          if (c != 'f')
            goto MALFORMED_PREAMBLE;
          PARSER_SKIP_SPACE_DO_WHILE (c);
          if (!isdigit (c))
            goto MALFORMED_PREAMBLE;

          /* read number of variables */
          PARSER_READ_NUM (num, c);
          if (trace == TRACE_QRP)
            fprintf (stdout, "p qrp %u", num);  
          else if (trace == TRACE_BQRP)
            fprintf (stdout, "p bqrp %u", num); 

          PARSER_SKIP_SPACE_WHILE (c);
          if (!isdigit (c))
            goto MALFORMED_PREAMBLE;

          /* read number of clauses */
          PARSER_READ_NUM (num, c);

          /* NOTE: number of steps is number of orig. clauses, as we can't tell
             the actual, future number of steps when tracing on-the-fly! */
          if (trace)
            fprintf (stdout, " %u%c", num, trace == TRACE_QRP ? '\n' : 0);

          preamble_found = 1;
          goto PARSE_SCOPE_OR_CLAUSE;

        MALFORMED_PREAMBLE:
          QDPLL_ABORT_APP (1, "malformed preamble!\n");
          return;
        }
      else
        {
          QDPLL_ABORT_APP (1, "expecting preamble!\n");
          return;
        }

    PARSE_SCOPE_OR_CLAUSE:

      PARSER_SKIP_SPACE_WHILE (c);

      if (c == 'a' || c == 'e')
        {
          /* open a new scope */
          if (c == 'a')
            scope_type = QDPLL_QTYPE_FORALL;
          else
            scope_type = QDPLL_QTYPE_EXISTS;

          qdpll_new_scope (qdpll, scope_type);

          PARSER_SKIP_SPACE_DO_WHILE (c);
        }

      if (!isdigit (c) && c != '-')
        {
          if (c == EOF)
            return;
          QDPLL_ABORT_APP (1, "expecting digit or '-'!\n");
          return;
        }
      else
        {
          if (c == '-')
            {
              neg = 1;
              if (!isdigit ((c = getc (in))))
                {
                  QDPLL_ABORT_APP (1, "expecting digit!\n");
                  return;
                }
            }

          /* parse a literal or variable ID */
          PARSER_READ_NUM (num, c);
          num = neg ? -num : num;

          qdpll_add (qdpll, num);

          neg = 0;

          goto PARSE_SCOPE_OR_CLAUSE;
        }
    }

  if (!preamble_found)
    QDPLL_ABORT_APP (1, "preamble missing!\n");
}