Exemplo n.º 1
0
void print_formula(){
    
    int clause = 0;
    int literal;
    
    literal = 0;
    clause = 0;
    while (clause < sat_st.num_clauses){
        
        int satisfied = FALSE;
        
        {
            int k;
            for (k=0; k<sat_st.formula[clause].size && !satisfied; k++){
                satisfied = is_satisfied(sat_st.formula[clause].literals[k]);
            }
        }
        
        printf("    (%d)", clause);
        
        if ( !satisfied ){
            
            literal = 0;
            int empty = TRUE;
            
            while (literal < sat_st.formula[clause].size){
                
                int variable = sat_st.formula[clause].literals[literal];
                int abs_variable = abs(variable);
                
                if ( sat_st.model[abs_variable] == UNKNOWN )
                {
                    printf(" %d", sat_st.formula[clause].literals[literal]);
                    empty = FALSE;
                }
                literal++;
            }
            if ( empty ){
                printf("CONFLICT\n");
            }
        } else {
            printf(" SATISFIED");
        }
        printf("\n");
        
        clause++;
    }
}
Exemplo n.º 2
0
void
satisfy_directive(Parser& p)
{
  p.require("satisfy");
  Expr& e = p.primary_expression();
  p.match(semicolon_tok);

  if (!has_bool_type(e)) {
    error("'{}' does not have type bool");
    return;
  }

  // TODO: Can I realistically make any assumptions about
  // what e can and cannot be? It must be a logical
  // proposition.

  // Test for satisfaction.
  bool result = is_satisfied(p.cxt, e);
  if (result)
    std::cout << "yes\n";
  else
    std::cout << "no\n";
}
Exemplo n.º 3
0
#include "catch.hpp"
#include <constraint_parser.hpp>

TEST_CASE("Test the syntax tree for an atomic constraint", 
	  "[TestAtomicConstraintTree]")
{
  string input = "3+x-(2+4)==4";
  auto at_tree = build_an_at_tree(input);
  REQUIRE (at_tree->is_satisfied() == false);

  string input2 = "3+x-(2+4)==3-(2+4)";
  auto at_tree2 = build_an_at_tree(input2);
  REQUIRE (at_tree2->is_satisfied() == true);
}