Пример #1
0
int ssp_rtdp_execute_cpu(const MDP *mdp, SSPRTDPCPU *rtdp, MDPValueFunction *policy)
{
    // First, ensure data is valid.
    if (mdp == nullptr || mdp->n == 0 || mdp->ns == 0 || mdp->m == 0 ||
            mdp->S == nullptr || mdp->T == nullptr || mdp->R == nullptr ||
            mdp->horizon < 1 ||
            mdp->ng < 1 || mdp->goals == nullptr ||
            rtdp == nullptr || rtdp->trials < 1 || policy == nullptr) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Invalid arguments.");
        return NOVA_ERROR_INVALID_DATA;
    }

    int result = ssp_rtdp_initialize_cpu(mdp, rtdp);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to initialize the CPU variables.");
        return result;
    }

    // Iterate until you have done the desired number of trials.
    for (rtdp->currentTrial = 0; rtdp->currentTrial < rtdp->trials; rtdp->currentTrial++) {
        result = ssp_rtdp_update_cpu(mdp, rtdp);
        if (result != NOVA_SUCCESS) {
            fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to perform trial of RTDP on the CPU.");

            unsigned int resultPrime = ssp_rtdp_uninitialize_cpu(mdp, rtdp);
            if (resultPrime != NOVA_SUCCESS) {
                fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n",
                                "Failed to uninitialize the CPU variables.");
            }

            return result;
        }
    }

    result = ssp_rtdp_get_policy_cpu(mdp, rtdp, policy);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to get the policy.");

        unsigned int resultPrime = ssp_rtdp_uninitialize_cpu(mdp, rtdp);
        if (resultPrime != NOVA_SUCCESS) {
            fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n",
                            "Failed to uninitialize the CPU variables.");
        }

        return result;
    }

    result = ssp_rtdp_uninitialize_cpu(mdp, rtdp);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to uninitialize the CPU variables.");
        return result;
    }

    return NOVA_SUCCESS;
}
Пример #2
0
int ssp_rtdp_execute_cpu(MDP *mdp, const float *Vinitial, MDPValueFunction *&policy)
{
    int result;

    // First, ensure data is valid.
    if (mdp->n == 0 || mdp->ns == 0 || mdp->m == 0 ||
            mdp->S == nullptr || mdp->T == nullptr || mdp->R == nullptr ||
            mdp->horizon < 1 || mdp->epsilon < 0.0f ||
            mdp->ne != 0 || mdp->expanded != nullptr ||
            Vinitial == nullptr || policy != nullptr) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Invalid arguments.");
        return NOVA_ERROR_INVALID_DATA;
    }

    result = ssp_rtdp_initialize_cpu(mdp, Vinitial);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to initialize the CPU variables.");
        return result;
    }

    // Iterate until you have done 'horizon' trials of RTDP.
    while (mdp->currentHorizon < mdp->horizon) {
        result = ssp_rtdp_update_cpu(mdp);
        if (result != NOVA_SUCCESS) {
            fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to perform trial of RTDP on the CPU.");
            return result;
        }
    }

    result = ssp_rtdp_get_policy_cpu(mdp, policy);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to get the policy.");
        return result;
    }

    result = ssp_rtdp_uninitialize_cpu(mdp);
    if (result != NOVA_SUCCESS) {
        fprintf(stderr, "Error[ssp_rtdp_execute_cpu]: %s\n", "Failed to uninitialize the CPU variables.");
        return result;
    }

    return NOVA_SUCCESS;
}