Esempio n. 1
0
expr::term_ref transition_system::get_initial_states() const {
  expr::term_ref I = d_initial_states->get_formula();
  if (has_assumptions()) {
    I = d_state_type->tm().mk_term(expr::TERM_AND, I, get_assumption());
  }
  return I;
}
Esempio n. 2
0
expr::term_ref transition_system::get_transition_relation() const {
  std::vector<expr::term_ref> transitions;
  transitions.push_back(d_transition_relation->get_formula());
  expr::term_ref transition = d_state_type->tm().mk_or(transitions);
  if (has_assumptions()) {
    expr::term_ref A = get_assumption();
    expr::term_ref A_next = d_state_type->change_formula_vars(state_type::STATE_CURRENT, state_type::STATE_NEXT, A);
    transition = d_state_type->tm().mk_term(expr::TERM_AND, transition, A, A_next);
  }
  return transition;
}
Esempio n. 3
0
static foreign_t pl_clingo_solve(term_t ccontrol, term_t assumptions,
                                 term_t Show, term_t Model, control_t h) {
    int rc = TRUE;
    solve_state *state = NULL;
    clingo_symbolic_literal_t *assump_vec = NULL;
    int control = PL_foreign_control(h);
    if (control == PL_FIRST_CALL) {
        size_t alen = 0;

        if (!(state = malloc(sizeof(*state)))) {
            rc = PL_resource_error("memory");
            goto out;
        }
        memset(state, 0, sizeof(*state));

        if (!(rc = get_clingo(ccontrol, &state->ctl))) {
            goto out;
        }

        if (PL_skip_list(assumptions, 0, &alen) != PL_LIST) {
            rc = PL_type_error("list", assumptions);
            goto out;
        }

        term_t tail = PL_copy_term_ref(assumptions);
        term_t head = PL_new_term_ref();

        if (!(assump_vec = malloc(sizeof(*assump_vec) * alen))) {
            rc = PL_resource_error("memory");
            goto out;
        }
        memset(assump_vec, 0, sizeof(*assump_vec) * alen);
        for (size_t i = 0; PL_get_list(tail, head, tail); i++) {
            if (!(rc = clingo_status(get_assumption(head, &assump_vec[i])))) {
                goto out;
            }
        }

        if (!(rc = clingo_status(clingo_control_solve_iteratively(
                  state->ctl->control, assump_vec, alen, &state->it)))) {
            goto out;
        }
    } else {
        state = PL_foreign_context_address(h);
    }

    while (control != PL_PRUNED) {
        clingo_model_t *model;

        if (!(rc = clingo_status(
                  clingo_solve_iteratively_next(state->it, &model)))) {
            goto out;
        }
        if (model) {
            int show;

            if (!(rc = get_show_map(Show, &show))) {
                goto out;
            }

            if (!(rc = unify_model(Model, show, model))) {
                if (PL_exception(0)) {
                    goto out;
                }
            } else {
                PL_retry_address(state);
                state = NULL;
                break;
            }

        } else {
            rc = FALSE;
            break;
        }
    }

out:
    if (assump_vec) {
        free(assump_vec);
    }
    if (state) {
        if (state->it) {
            clingo_solve_iteratively_close(state->it);
        }
        free(state);
    }
    return rc;
}