コード例 #1
0
ファイル: rp_parser.c プロジェクト: danbryce/dReal-backup
/* i := evaluation of constant expression */
int rp_rule_constant_expr(rp_parser p, rp_interval i)
{
  rp_erep f;
  int res = 0;
  if (rp_rule_expr(p,&f))
  {
    /* evaluation of f */
    if (rp_erep_is_constant(f))
    {
      rp_box b = NULL;  /* useless */
      if (rp_erep_eval(f,b))
      {
        rp_interval_copy(i,rp_erep_val(f));
        res = 1;
      }
      else
      {
        rp_parser_stop(p,"empty evaluation of constant expression");
      }
    }
    else
    {
      rp_parser_stop(p,"non constant expression");
    }
    rp_erep_destroy(&f);
  }
  return( res );
}
コード例 #2
0
ファイル: rp_parser.c プロジェクト: danbryce/dReal-backup
/* Parse a signed number */
int rp_rule_signed_number(rp_parser p, rp_interval i)
{
  int minus = 0;
  rp_interval j;

  /* sign */
  if (rp_parser_accept(p,RP_TOKEN_MINUS))
  {
    minus = 1;
  }
  else if (rp_parser_accept(p,RP_TOKEN_PLUS))
  {
    minus = 0;
  }

  if (rp_rule_unsigned_number(p,j))
  {
    if (minus)
    {
      rp_interval_neg(i,j);
    }
    else
    {
      rp_interval_copy(i,j);
    }
    return( 1 );
  }
  else
  {
    return( 0 );
  }
}
コード例 #3
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
int rp_operator_newton::reduce(rp_box b)
{
  bool proof = true;

  for (int i=0; i<_arity; ++i)
  {
    int v = _v[i];
    rp_interval aux, save;

    rp_interval_add(aux,rp_ivector_elem(_unknown,i),rp_box_elem(_midpoint,v));
    rp_interval_copy(save,rp_box_elem(b,v));

    if (!(rp_interval_strictly_included(aux,save))) proof = false;

    rp_interval_inter(rp_box_elem(b,v),save,aux);

    if (rp_interval_empty(rp_box_elem(b,v)))
    {
      return( 0 );
    }
  }

  if (proof) rp_box_set_safe(b);

  return( 1 );
}
コード例 #4
0
ファイル: rp_splitter_time.cpp プロジェクト: asadHafiz/dreal
void rp_splitter_time::apply(rp_box_set& bs, int var) {
  rp_interval i1, i2;
  rp_box b1 = bs.remove_insert();
  this->observe(b1, var);
  rp_box b2 = bs.insert(b1);

  if (quick_split_vars[&b1] == NULL){
    quick_split_vars[&b1] = new std::set<int>();
  }
  quick_split_vars[&b2] = new std::set<int>(*quick_split_vars[&b1]);

  if (is_time_variable(var) && !did_quick_split(&b1, var)){
    if (this->real_hole(rp_box_elem(b1, var),
                        rp_variable_domain(rp_problem_var(*_problem, var)),
                        i1, i2)){
      rp_interval_copy(rp_box_elem(b1, var), i1);
      rp_interval_copy(rp_box_elem(b2, var), i2);
    } else {
      // std::cout << "TIME SPLIT" << std::endl;
      rp_interval &vi = rp_box_elem(b1, var);
      double split =  std::min(rp_binf(vi) + precision, rp_split_point(rp_binf(vi), rp_bsup(vi), 1000, 1));

      // Real variable: [a,b] --> [center,b] and [a,center]
      rp_binf(rp_box_elem(b1, var)) =
        rp_bsup(rp_box_elem(b2, var)) =
        split;

      quick_split_vars[&b1]->insert(var);
      quick_split_vars[&b2]->insert(var);
        // rp_interval_midpoint(rp_box_elem(b1,var));
    }
  } else if (rp_variable_integer(rp_problem_var(*_problem, var))){
    if (this->integer_hole(rp_box_elem(b1, var),
                           rp_variable_domain(rp_problem_var(*_problem, var)),
                           i1, i2)) {
      rp_interval_copy(rp_box_elem(b1, var), i1);
      rp_interval_copy(rp_box_elem(b2, var), i2);
    } else { // no hole found
      // Integer variable: [a,b] --> [a+1,b] and [a,a]
      ++rp_binf(rp_box_elem(b1, var));
      rp_bsup(rp_box_elem(b2, var)) = rp_binf(rp_box_elem(b2, var));
    }
  } else {
    if (this->real_hole(rp_box_elem(b1, var),
                        rp_variable_domain(rp_problem_var(*_problem, var)),
                        i1, i2)) {
      rp_interval_copy(rp_box_elem(b1, var), i1);
      rp_interval_copy(rp_box_elem(b2, var), i2);
    } else {
      // Real variable: [a,b] --> [center,b] and [a,center]
      rp_binf(rp_box_elem(b1, var)) =
        rp_bsup(rp_box_elem(b2, var)) =
          rp_interval_midpoint(rp_box_elem(b1, var));
    }
  }
}
コード例 #5
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
// Application of operator to reduce the box b
int rp_operator_piecewise::apply(rp_box b)
{
  DREAL_LOG_DEBUG << "rp_operator_piecewise::apply";
  // Check each piece Ij:Cj, if Cj violated then the elements of Ij
  // are removed from the domain of the main variable of _c
  for (int i=0; i<rp_ctr_piecewise_arity(_c); ++i)
  {
    int violated = 0, j = 0;
    while ((!violated) && (j<rp_ctr_piecewise_elem_size(_c,i)))
    {
      if (rp_ctr_num_unfeasible(rp_ctr_piecewise_elem_ctrnum(_c,i,j),b))
      {
        violated = 1;
      }
      else ++j;
    }
    if (violated)
    {
      // domain restriction dom(var) := dom(var) \ Ij
      rp_interval aux;
      rp_interval_copy(aux,rp_box_elem(b,rp_ctr_piecewise_var(_c)));
      rp_interval_setminus(rp_box_elem(b,rp_ctr_piecewise_var(_c)),
                           aux,
                           rp_ctr_piecewise_elem_dom(_c,i));

      if (rp_interval_empty(rp_box_elem(b,rp_ctr_piecewise_var(_c))))
      {
        return( 0 );
      }
    }
  }

  // Check whether the domain of the main variable of _c
  // intersects at least one Ij
  int intersect = 0, i = 0;
  while ((!intersect) && (i<rp_ctr_piecewise_arity(_c)))
  {
    if (!rp_interval_disjoint(rp_box_elem(b,rp_ctr_piecewise_var(_c)),
                              rp_ctr_piecewise_elem_dom(_c,i)))
    {
      intersect = 1;
    }
    else ++i;
  }
  return( intersect );
}
コード例 #6
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
// Construction
rp_operator_condvar::rp_operator_condvar(int v,
                                         rp_interval x,
                                         rp_operator * o):
  rp_operator(o->priority(),0,o->pruned_arity()),
  _v(v),
  _o(o)
{
  rp_interval_copy(_dom,x);

  rp_intset_create(&_vars);

  // depends on every variable of Operator o
  for (int i=0; i<o->arity(); ++i)
  {
    rp_intset_insert(_vars,o->var(i));
  }
  rp_intset_insert(_vars,v);  // and on v
}
コード例 #7
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
int rp_operator_newton::compute_jacobi(rp_box b)
{
  /* Computation of the Jacobian matrix df(b) */
  rp_interval_matrix_copy(_jacobi,_izero);
  for (int i=0; i<_arity; ++i)
  {
    /* for every function  */
    if (rp_expression_deriv_num(_f[i],b))
    {
      /* for every variable of _f[i] */
      for (int j=0; j<rp_expression_arity(_f[i]); ++j)
      {
        rp_interval_copy(rp_imatrix_elem(_jacobi,i,_vf[i][j]),
                         rp_expression_deriv_local_val(_f[i],j));
      }
    }
    else
    {
      return( 0 );
    }
  }
  return( 1 );
}
コード例 #8
0
void rp_splitter_mixed_hybrid::apply(rp_box_set& bs, int var) {
  rp_interval i1, i2;
  rp_box b1 = bs.remove_insert();
  this->observe(b1, var);
  rp_box b2 = bs.insert(b1);

  rp_box b1_copy;
  rp_box_clone(&b1_copy, b1);
  rp_box suggestion = m_ode_sim_heuristic->sim(b1_copy, var);


  DREAL_LOG_DEBUG << "rp_splitter_mixed_hybrid::apply() "
                  << "suggestion = " << var << " [" << rp_binf(rp_box_elem(suggestion, var)) << ", "
                  << rp_bsup(rp_box_elem(suggestion, var))
                  << "]";
  if (rp_variable_integer(rp_problem_var(*_problem, var)))  {
    if (this->integer_hole(rp_box_elem(b1, var),
                           rp_variable_domain(rp_problem_var(*_problem, var)),
                           i1, i2)){
      if (rp_interval_included(i1, rp_box_elem(suggestion, var))){
        rp_interval_copy(rp_box_elem(b1, var), i1);
        rp_interval_copy(rp_box_elem(b2, var), i2);
      } else{
        rp_interval_copy(rp_box_elem(b1, var), i2);
        rp_interval_copy(rp_box_elem(b2, var), i1);
      }
    } else  { // no hole found
      ++rp_binf(rp_box_elem(b1, var));
      if (rp_interval_included(rp_box_elem(b1, var), rp_box_elem(suggestion, var))){
        // Integer variable: [a,b] --> [a+1,b] and [a,a]
        rp_bsup(rp_box_elem(b2, var)) = rp_binf(rp_box_elem(b2, var));
      } else {
        --rp_binf(rp_box_elem(b1, var));
        ++rp_binf(rp_box_elem(b2, var));
        rp_bsup(rp_box_elem(b1, var)) = rp_binf(rp_box_elem(b1, var));
      }
    }
  }  else  {
    if (this->real_hole(rp_box_elem(b1, var),
                        rp_variable_domain(rp_problem_var(*_problem, var)),
                        i1, i2)) {
      if (rp_interval_included(i1, rp_box_elem(suggestion,  var))){
        rp_interval_copy(rp_box_elem(b1, var), i1);
        rp_interval_copy(rp_box_elem(b2, var), i2);
      }  else {
        rp_interval_copy(rp_box_elem(b1, var), i2);
        rp_interval_copy(rp_box_elem(b2, var), i1);
      }
    }  else {
      // Real variable: [a,b] --> [center,b] and [a,center]
      double mid = rp_interval_midpoint(rp_box_elem(b1, var));

      rp_binf(rp_box_elem(b1, var)) =
        rp_bsup(rp_box_elem(b2, var)) =
          mid;

      double b1Intersection =
        std::min(rp_bsup(rp_box_elem(b1, var)), rp_bsup(rp_box_elem(suggestion, var))) -
        std::max(rp_binf(rp_box_elem(b1, var)), rp_binf(rp_box_elem(suggestion, var)));
      double b2Intersection =
        std::min(rp_bsup(rp_box_elem(b2, var)), rp_bsup(rp_box_elem(suggestion, var))) -
        std::max(rp_binf(rp_box_elem(b2, var)), rp_binf(rp_box_elem(suggestion, var)));

      if (b2Intersection > b1Intersection
          // rp_interval_included(rp_box_elem(suggestion, var), rp_box_elem(b2, var))
          ){
        // okay
        DREAL_LOG_DEBUG << "rp_splitter_mixed_hybrid::apply() "
                        << "*[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
                        << "]* [" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
                        << "]";
        // cout  << "*[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
        //                 << "]* [" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
        //                 << "] \t";
      } else if (b2Intersection < b1Intersection){
          // rp_interval_included(rp_box_elem(suggestion, var), rp_box_elem(b1, var))){
        // reverse

        double b2_sup = rp_bsup(rp_box_elem(b1, var));
        rp_binf(rp_box_elem(b1, var)) = rp_binf(rp_box_elem(b2, var));
        rp_bsup(rp_box_elem(b1, var)) = mid;
        rp_binf(rp_box_elem(b2, var)) = mid;
        rp_bsup(rp_box_elem(b2, var)) = b2_sup;
        DREAL_LOG_DEBUG << "rp_splitter_mixed_hybrid::apply() "
                        << "[" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
                        << "] *[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
                        << "]*";
        // cout << "[" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
        //                 << "] *[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
        //                 << "]* \t";
      } else {
        DREAL_LOG_DEBUG << "rp_splitter_mixed_hybrid::apply() suggestion not found";
        DREAL_LOG_DEBUG << "rp_splitter_mixed_hybrid::apply() "
                        << "-[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
                        << "]- [" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
                        << "]";
        // cout << "-[" << rp_binf(rp_box_elem(b2, var)) << ", " << rp_bsup(rp_box_elem(b2, var))
        //      << "]- [" << rp_binf(rp_box_elem(b1, var)) << ", " << rp_bsup(rp_box_elem(b1, var))
        //      << "] \t";
      }
    }
  }
  rp_box_destroy(&b1_copy);
}