コード例 #1
0
ファイル: rp_solver.cpp プロジェクト: JichaoS/dreal
void pprint_vars(FILE* out, rp_problem p, rp_box b)
{
    for(int i = 0; i < rp_problem_nvar(p); i++)
    {
        fprintf(out, "%s", rp_variable_name(rp_problem_var(p, i)));
        fprintf(out, " is in: ");
        interval_cout_local(rp_box_elem(b,i), 6, RP_INTERVAL_MODE_BOUND);
        if (i != rp_problem_nvar(p) - 1)
            fprintf(out, ";");
        fprintf(out, "\n");
    }
}
コード例 #2
0
ファイル: rp_solver.cpp プロジェクト: danbryce/dReal-backup
rp_bpsolver::rp_bpsolver(const rp_bpsolver& s):
  _problem(s._problem),
  _propag(0),
  _boxes(rp_problem_nvar(*_problem)),
  _vselect(NULL),
  _ep(NULL)
{}
コード例 #3
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
// Construction
rp_operator_newton::rp_operator_newton(const rp_problem * p,
                                       int n, double improve):
  rp_operator(RP_OPERATOR_NEWTON_PRIORITY,n,n),
//  _problem(const_cast<rp_problem*>(p)),
  _improve(improve),
  _arity(n),
  _vi(0),
  _fi(0)
{
  rp_malloc(_v,int*,n*sizeof(int));
  rp_malloc(_f,rp_expression*,n*sizeof(rp_expression));
  rp_malloc(_vf,int**,n*sizeof(int*));

  rp_box_create(&_midpoint,rp_problem_nvar(*p));

  rp_interval zero;
  rp_interval_set_point(zero,0.0);
  rp_interval_matrix_create(&_jacobi,_arity,_arity);
  rp_interval_matrix_create(&_izero,_arity,_arity);
  rp_interval_matrix_set(_izero,zero);

  rp_interval_vector_create(&_negfmid,_arity);
  rp_interval_vector_create(&_unknown,_arity);

  rp_real_matrix_create(&_midjacobi,_arity,_arity);
  rp_real_matrix_create(&_precond,_arity,_arity);
  rp_real_matrix_create(&_identity,_arity,_arity);
  rp_real_matrix_setid(_identity);

  rp_interval_matrix_create(&_precond_jacobi,_arity,_arity);
  rp_interval_vector_create(&_precond_negfmid,_arity);

//test type
  type = 3;
}
コード例 #4
0
ファイル: rp_parser.c プロジェクト: danbryce/dReal-backup
int rp_rule_solve_list_var(rp_parser p, rp_problem problem)
{
  int result = 1;
  if (rp_parser_accept(p,RP_TOKEN_MUL))
  {
    /* every variable is a decision variable */
    int i;
    for (i=0; i<rp_problem_nvar(problem); ++i)
    {
      rp_variable_set_decision(rp_problem_var(p,i));
    }
  }
  else
  {
    /* list of variables */
    rp_variable * v;
    int iter = 1, index;
    do
    {
      if (rp_parser_expect(p,RP_TOKEN_IDENT,"variable name"))
      {
        if ((v=rp_vector_variable_contains(rp_parser_vars(p),
                                           rp_lexer_prev_text(rp_parser_lexer(p)),
                                           &index))!=NULL)
        {
          rp_variable_set_decision(*v);

          if (!rp_parser_accept(p,RP_TOKEN_COMMA))
          {
            iter = 0;
          }
        }
        else
        {
          rp_parser_stop(p,"variable not defined");
          iter = result = 0;
        }
      }
      else /* variable name not found */
      {
        iter = result = 0;
      }
    } while (iter);
  }

  if (result)
  {
    if (!rp_parser_accept(p,RP_TOKEN_SEMICOLON))
    {
      rp_parser_stop(p,"erroneous end of solve definition");
      result = 0;
    }
  }
  return( result );
}
コード例 #5
0
ファイル: rp_solver.cpp プロジェクト: JichaoS/dreal
rp_bpsolver::rp_bpsolver(const rp_bpsolver& s):
  _problem(s._problem),
  _propag(0),
  _boxes(rp_problem_nvar(*_problem)),
  _vselect(nullptr),
  _dsplit(nullptr),
  _ep(nullptr),
  _sol(0),
  _nsplit(0),
  _improve(0.0)
{}
コード例 #6
0
ファイル: rp_operator.cpp プロジェクト: JichaoS/dreal
// Construction of operator
rp_operator_3b::rp_operator_3b(const rp_problem * p,
                               rp_operator * o, int v, double improve):
  rp_operator(o->priority()+RP_OPERATOR_3B_PRIORITY,0,0),
  _v(v),
  _improve(0.125),  /* 12.5% */
  _o(o)
{
  if ((improve>=0.0) && (improve<=100.0))
  {
    _improve = improve/100.0;  /* user-defined */
  }
  rp_box_create(&_baux,rp_problem_nvar(*p));
}
コード例 #7
0
ファイル: rp_solver.cpp プロジェクト: JichaoS/dreal
// ---------------------------------------------------------
// Branch-and-prune algorithm for solving constraint systems
// ---------------------------------------------------------
rp_bpsolver::rp_bpsolver(rp_problem * p,
                         double improve,
                         rp_selector * vs,
                         rp_splitter * ds,
                         rp_existence_prover * ep):
  _problem(p),
  _propag(p),
  _boxes(rp_problem_nvar(*p)),//sean:number of variables
  _vselect(vs),
  _dsplit(ds),
  _ep(ep),
  _sol(0),
  _nsplit(0),
  _improve(0.0)
{
  // Check once the satisfiability of all the constraints
  // Necessary for variable-free constraints
  int i = 0, sat = 1;
  while ((i<rp_problem_nctr(*p)) && (sat))
  {
    if (rp_constraint_unfeasible(rp_problem_ctr(*p,i),rp_problem_box(*p)))
    {
      sat = 0;
    }
    else ++i;
  }

  if (sat)
  {
    // Insertion of the initial box in the search structure
    _boxes.insert(rp_problem_box(*p));

    // Management of improvement factor
    if ((improve>=0.0) && (improve<=100.0))
    {
      _improve = 1.0-improve/100.0;
    }
    else
    {
      _improve = 0.875;  /* 12.5% */
    }
    _propag.set_improve(_improve);

    // Creation of the operators and insertion in the propagator
    rp_hybrid_factory hfact(_improve);
    hfact.apply(p,_propag);

    rp_domain_factory dfact;
    dfact.apply(p,_propag);

    rp_newton_factory nfact(_improve);
    nfact.apply(p,_propag);

    //rp_3b_factory bfact(_improve);
    //bfact.apply(p,_propag);



    // Used for round-robin strategy: last variable split
    rp_box_set_split(_boxes.get(),-1);//sean: why is the last variable -1? oh, must be length - this number
  }
  else
  {
    rp_box_set_empty(rp_problem_box(*p));
  }
}