コード例 #1
0
ファイル: dreal_jl_01.c プロジェクト: 4lex4nder/dreal3
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);

    // numbers -- 2, 7, 10
    opensmt_expr num2  = opensmt_mk_num_from_string(ctx, "2");
    opensmt_expr num7  = opensmt_mk_num_from_string(ctx, "7");
    opensmt_expr num10 = opensmt_mk_num_from_string(ctx, "10");

    // t1 = x > 2
    opensmt_expr t1 = opensmt_mk_gt(ctx, x, num2);
    
    // t2 = y < 10
    opensmt_expr t2 = opensmt_mk_lt(ctx, y, num10);


    // t3 = 2 * y
    opensmt_expr subarray1[2] = {num2, y};
    opensmt_expr t3 = opensmt_mk_times(ctx, subarray1, 2);

    // t4 = x + t3 == 7
    opensmt_expr subarray2[2] = {x, t3};
    opensmt_expr t4 = opensmt_mk_eq(ctx, opensmt_mk_plus(ctx, subarray2, 2), num7);

    // t5 = t1 /\ t2 /\ t4
    opensmt_expr subarray3[3] = {t1, t2, t4};
    opensmt_expr t5 = opensmt_mk_and(ctx, subarray3, 3);

    opensmt_assert(ctx, t5);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
コード例 #2
0
ファイル: example_01.c プロジェクト: dpsanders/dreal3-1
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating boolean variables
    fprintf(stderr, "Creating some boolean variables\n");
    opensmt_expr a = opensmt_mk_bool_var(ctx, "a");
    opensmt_expr b = opensmt_mk_bool_var(ctx, "b");
    opensmt_expr c = opensmt_mk_bool_var(ctx, "c");
    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);
    opensmt_expr z = opensmt_mk_int_var(ctx, "z" , -10, 10);
    // Creating inequality
    fprintf(stderr, "Creating x - y <= 0\n");

    fprintf(stderr, "  Creating x - y\n");
    opensmt_expr minus = opensmt_mk_minus(ctx, x, y);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(minus);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating 0\n");
    opensmt_expr zero = opensmt_mk_num_from_string(ctx, "0");
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(zero);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating x - y <= 0\n");
    opensmt_expr leq = opensmt_mk_leq(ctx, minus, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");

    // Creating inequality 2
    fprintf(stderr, "Creating y - z <= 0\n");
    opensmt_expr minus2 = opensmt_mk_minus(ctx, y, z);
    opensmt_expr leq2 = opensmt_mk_leq(ctx, minus2, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");

    // Creating inequality 3
    fprintf(stderr, "Creating z - x <= -1\n");
    opensmt_expr minus3 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr mone = opensmt_mk_num_from_string(ctx, "-1");
    opensmt_expr leq3 = opensmt_mk_leq(ctx, minus3, mone);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");

    // Creating inequality 4
    fprintf(stderr, "Creating z - x <= 0\n");
    opensmt_expr minus4 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr leq4 = opensmt_mk_leq(ctx, minus4, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");

    // Asserting first inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting second inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq2);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting third inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq3);
    opensmt_push(ctx);

    // Checking for consistency - it is UNSAT
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Backtracking one step - so the state is SAT again
    opensmt_pop(ctx);
    fprintf(stderr, "Backtracking one step\n\n");

    // Asserting fourth inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq4);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
コード例 #3
0
ファイル: zenna_04.c プロジェクト: jadecastro/dreal3
// Related PR : https://github.com/dreal/DReal.jl/pull/23
int main(int argc, char * argv[]) {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    opensmt_expr a = opensmt_mk_bool_var( ctx, "a" );
    opensmt_expr b = opensmt_mk_bool_var( ctx, "b" );
    opensmt_expr c = opensmt_mk_bool_var( ctx, "c" );

     /*  # Creating integer variables */
    opensmt_expr x = opensmt_mk_int_var( ctx, "x" , -100, 100);
    opensmt_expr y = opensmt_mk_int_var( ctx, "y" , -100, 100);
    opensmt_expr z = opensmt_mk_int_var( ctx, "z" , -100, 100);
    /*  # Creating inequality */
    opensmt_expr minus = opensmt_mk_minus( ctx, x, y );
    opensmt_expr zero = opensmt_mk_num_from_string( ctx, "0" );
    opensmt_expr leq = opensmt_mk_leq( ctx, minus, zero );

    /*  # Creating inequality 2 */
    opensmt_expr minus2 = opensmt_mk_minus( ctx, y, z );
    opensmt_expr leq2 = opensmt_mk_leq( ctx, minus2, zero );

    /*  # Creating inequality 3 */
    opensmt_expr minus3 = opensmt_mk_minus( ctx, z, x );
    opensmt_expr mone = opensmt_mk_num_from_string( ctx, "-1" );
    opensmt_expr leq3 = opensmt_mk_leq( ctx, minus3, mone );

    /*  # Creating inequality 4 */
    opensmt_expr minus4 = opensmt_mk_minus( ctx, z, x );
    opensmt_expr leq4 = opensmt_mk_leq( ctx, minus4, zero );

    /*  # Asserting first inequality */
    opensmt_assert( ctx, leq );                 /* ASSERT (e1) */
    opensmt_push( ctx );                        /* PUSH */

    /* # Checking for consistency */
    opensmt_result res = opensmt_check( ctx );  /* CHECK */
    assert(res == l_true);

    // # Asserting second inequality
    opensmt_assert( ctx, leq2 );               /* ASSERT (e2) */
    opensmt_push( ctx );                       /* PUSH */

    // # Checking for consistency
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_true);

    // # Asserting third inequality
    opensmt_assert( ctx, leq3 );               /* ASSERT (e3)*/
    opensmt_push( ctx );                       /* PUSH */

    // # Checking for consistency - it is UNSAT
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);

    /*  # Backtracking one step - so the state is SAT again */
    opensmt_pop( ctx );                        /* POP */

    /* # Asserting fourth inequality */
    opensmt_assert( ctx, leq4 );               /* ASSERT (e4) */

    /*  # Checking for consistency */
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);

    opensmt_del_context(ctx);
    return 0;
}