Ejemplo n.º 1
0
void bv_minimizet::operator()(const minimization_listt &symbols)
{
  // build bit-wise objective function

  prop_minimizet prop_minimize(boolbv);
  prop_minimize.set_message_handler(get_message_handler());

  for(minimization_listt::const_iterator
      l_it=symbols.begin();
      l_it!=symbols.end();
      l_it++)
  {
    add_objective(prop_minimize, *l_it);
  }

  // now solve
  prop_minimize();
}
void counterexample_beautificationt::get_minimization_list(
  prop_convt &prop_conv,
  const symex_target_equationt &equation,
  minimization_listt &minimization_list)
{
  // ignore the ones that are assigned under false guards

  for(symex_target_equationt::SSA_stepst::const_iterator
      it=equation.SSA_steps.begin();
      it!=equation.SSA_steps.end(); it++)
  {
    if(it->is_assignment() &&
       it->assignment_type==symex_targett::assignment_typet::STATE)
    {
      if(!prop_conv.l_get(it->guard_literal).is_false())
      {
        const typet &type=it->ssa_lhs.type();

        if(type!=bool_typet())
        {
          // we minimize the absolute value, if applicable
          if(type.id()==ID_signedbv ||
             type.id()==ID_fixedbv ||
             type.id()==ID_floatbv)
          {
            abs_exprt abs_expr(it->ssa_lhs);
            minimization_list.insert(abs_expr);
          }
          else
            minimization_list.insert(it->ssa_lhs);
        }
      }
    }

    // reached failed assertion?
    if(it==failed)
      break;
  }
}
Ejemplo n.º 3
0
bool bv_minimizing_dect::minimize(const minimization_listt &symbols)
{
  // unfortunately, only MiniSat supports this

  #if defined(SATCHECK_MINISAT) || defined(SATCHECK_MINISAT2)
  bvt constraints;

  for(minimization_listt::const_iterator
      l_it=symbols.begin();
      l_it!=symbols.end();
      l_it++)
  {
    unsigned result=0;

    const exprt &symbol = *l_it;

    status("Minimizing... ");

    // FIXME: be more gener[ous|al] here!
    assert(symbol.type().id()==ID_unsignedbv);

    unsigned width=boolbv_width(symbol.type());
    
    for(unsigned i = width; i > 0; i--)
    {
      literalt lit;
#if 0
      std::cout << "SYMBOL: " << symbol << std::endl;
#endif
      if(literal(symbol, i-1, lit))
        continue; // there's no corresponding literal
        
      if(lit.is_constant())
        continue;

      literalt nlit=satcheck.lnot(lit);
      constraints.push_back(nlit);

      if(satcheck.l_get(lit)==tvt(false))
        continue;

      // call Minisat with constraints
      satcheck.set_assumptions(constraints);

      if(satcheck.prop_solve() == propt::P_UNSATISFIABLE)
      {
        // change constraint to 1
        constraints.back().swap(lit);
        result |= 1 << (i-1);

        // make sure the model is reconstructed
        satcheck.set_assumptions(constraints);
        if(satcheck.prop_solve()==propt::P_UNSATISFIABLE)
          assert (false); // do not remove call to prop_solve!!
      }
    }

    status(symbol.get_string(ID_identifier)+" = "+i2string(result));
  }

  return true;
  #else
  // we don't have it...
  return false;
  #endif
}