Exemplo n.º 1
0
Arquivo: driver.c Projeto: CNMAT/gsl
int
gsl_odeiv2_driver_reset (gsl_odeiv2_driver * d)
{
  /* Reset the driver. Resets evolve and step objects. */

  {
    int s = gsl_odeiv2_evolve_reset (d->e);

    if (s != GSL_SUCCESS)
      {
        return s;
      }
  }

  {
    int s = gsl_odeiv2_step_reset (d->s);

    if (s != GSL_SUCCESS)
      {
        return s;
      }
  }

  return GSL_SUCCESS;
}
Exemplo n.º 2
0
void IzhikevichBranch::subthreshold_regimeRegime_::init_solver() {
    

    IntegrationStep_ = cell->B_.step_;

    static const gsl_odeiv2_step_type* T1 = gsl_odeiv2_step_rk2;
    //FIXME: Could be reduced to include only the states which have a time
    //       derivative
    N = 2;

    if ( s_ == 0 )
        s_ = gsl_odeiv2_step_alloc (T1, N);
    else
        gsl_odeiv2_step_reset(s_);

    if ( c_ == 0 )
        c_ = gsl_odeiv2_control_standard_new (0.001, 0.0, 1.0, 0.0);
    else
        gsl_odeiv2_control_init(c_, 0.001, 0.0, 1.0, 0.0);

    if ( e_ == 0 )
        e_ = gsl_odeiv2_evolve_alloc(N);
    else
        gsl_odeiv2_evolve_reset(e_);

    sys_.function  = IzhikevichBranch_subthreshold_regime_dynamics;
    sys_.jacobian  = IzhikevichBranch_subthreshold_regime_jacobian;
    sys_.dimension = N;
    sys_.params    = reinterpret_cast<void*>(this->cell);

    if (u == 0)
        u = (double *)malloc(sizeof(double) * N);
        assert (u);
    if (jac == 0)
        jac = (double *)malloc(sizeof(double) * N);
        assert (jac);    
}
Exemplo n.º 3
0
void contractor_gsl::prune(box & b, SMTConfig & config) {
    // TODO(soonhok): add timeout
    fesetround(FE_TONEAREST);  // Without this, GSL might cause a segmentation fault due to problems in floating point lib
    gsl_odeiv2_step_reset(m_step);
    gsl_odeiv2_evolve_reset(m_evolve);

    double const T_lb = b[m_time_t].lb();
    double const T_ub = b[m_time_t].ub();
    double t = 0.0, old_t = 0.0;                  /* initialize t */
    double T_next = 0.0;
    double h = 1e-10;              /* starting step size for ode solver */
    DREAL_LOG_INFO << "GSL: prune begin "
                   << m_time_t << " = ["
                   << T_lb << ", " << T_ub << "]"
                   << "\t" << b.max_diam();
    DREAL_LOG_INFO << m_ctr->get_ic();

    if (b.max_diam() < config.nra_precision) {
        return;
    }
    bool need_to_run = false;
    for (Enode * e : m_vars_0) {
        if (b[e].diam() > config.nra_precision) {
            need_to_run = true;
            break;
        }
    }
    if (b[m_time_t].diam() > config.nra_precision) {
        need_to_run = true;
    }
    if (!need_to_run) { return; }

    extract_sample_point(b, m_vars_0, m_values);
    extract_sample_point(b, m_pars_0, m_params);
    for (unsigned i = 0; i < m_vars_0.size(); i++) {
        b[m_vars_0[i]] = m_values[i];
    }
    for (unsigned i = 0; i < m_pars_0.size(); i++) {
        b[m_pars_0[i]] = m_params[i];
    }

    // First move to T_lb without checking m_values
    while (t < T_lb) {
        interruption_point();
        T_next = T_lb;
        // T_next = min(t + config.nra_precision, T_lb);
        int status = gsl_odeiv2_evolve_apply(m_evolve, m_control, m_step,
                                             &m_system,
                                             &t, T_next,
                                             &h, m_values);
        if (status != GSL_SUCCESS) {
            DREAL_LOG_INFO << "GSL: error, return value " << status;
            throw contractor_exception("GSL FAILED");
        }
    }

    // Now we're in the range in [T_lb, T_ub], need to check m_values.
    while (t < T_ub) {
        interruption_point();
        T_next = min(t + config.nra_precision, T_ub);
        // T_next = T_ub;

        // Copy m_values to m_old_values, and t to old_t
        for (unsigned i = 0; i < m_dim; i++) {
            m_old_values[i] = m_values[i];
        }
        old_t = t;
        int status = gsl_odeiv2_evolve_apply(m_evolve, m_control, m_step,
                                             &m_system,
                                             &t, T_next,
                                             &h, m_values);
        if (status != GSL_SUCCESS) {
            DREAL_LOG_INFO << "GSL: error, return value " << status;
            throw contractor_exception("GSL FAILED");
        }

        // print_values(t, m_values, m_dim);         /* print at t */
        bool values_good = true;
        unsigned i = 0;
        for (Enode * e : m_vars_t) {
            double const old_v_i = m_old_values[i];
            double const v_i = m_values[i];
            auto iv = (old_v_i < v_i) ? ibex::Interval(old_v_i, v_i) : ibex::Interval(v_i, old_v_i);
            auto const & iv_X_t = b[e];
            iv &= iv_X_t;
            if (iv.is_empty()) {
                values_good = false;
                DREAL_LOG_INFO << "GSL Not in Range: " << e
                                << " : " << m_values[i] << " not in " << b[e] << " at t = " << t;
                break;
            }
            i++;
        }
        if (values_good) {
            thread_local static box old_box(b);
            old_box = b;
            // Update X_t with m_values
            i = 0;
            for (Enode * e : m_vars_t) {
                double const old_v_i = m_old_values[i];
                double const v_i = m_values[i];
                auto iv = (old_v_i < v_i) ? ibex::Interval(old_v_i, v_i) : ibex::Interval(v_i, old_v_i);
                auto const & iv_X_t = b[e];
                iv &= iv_X_t;
                DREAL_LOG_INFO << "GSL Update: " << e
                                << " : " << b[e] << " ==> " << iv;
                b[e] = iv;
                i++;
            }
            // Update Time with T
            double const new_t = t/2.0 + old_t/2.0;
            DREAL_LOG_INFO << "GSL Update: time: " << b[m_time_t] << " ==> " << new_t;
            b[m_time_t] = new_t;
            m_eval_ctc.prune(b, config);
            if (!b.is_empty()) {
                DREAL_LOG_INFO << "This box satisfies other non-linear constraints";
                return;
            } else {
                DREAL_LOG_INFO << "This box failed to satisfy other non-linear constraints";
                b = old_box;
            }
        }
    }
    DREAL_LOG_INFO << "GSL failed in the end";
    throw contractor_exception("GSL failed");
}