Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cadical with preprocessor and local search #8502

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/goto-checker/solver_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ get_sat_solver(message_handlert &message_handler, const optionst &options)
else if(solver_option == "cadical")
{
#if defined SATCHECK_CADICAL
return make_satcheck_prop<satcheck_cadicalt>(message_handler, options);
return make_satcheck_prop<satcheck_cadical_no_preprocessingt>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Does this need to honour the no_simplifier flag as for the other solvers above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the preprocessing becomes default, it should.

message_handler, options);
#else
emit_solver_warning(message_handler, "cadical");
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/sat/satcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ typedef satcheck_glucose_no_simplifiert satcheck_no_simplifiert;

#elif defined SATCHECK_CADICAL

typedef satcheck_cadicalt satcheckt;
typedef satcheck_cadicalt satcheck_no_simplifiert;
typedef satcheck_cadical_no_preprocessingt satcheckt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef satcheck_cadical_no_preprocessingt satcheckt;
typedef satcheck_cadical_preprocessingt satcheckt;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see broader benchmarking data before doing this.

typedef satcheck_cadical_no_preprocessingt satcheck_no_simplifiert;

#endif

Expand Down
30 changes: 21 additions & 9 deletions src/solvers/sat/satcheck_cadical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Author: Michael Tautschnig

# include <cadical.hpp>

tvt satcheck_cadicalt::l_get(literalt a) const
tvt satcheck_cadical_baset::l_get(literalt a) const
{
if(a.is_constant())
return tvt(a.sign());
Expand All @@ -38,12 +38,12 @@ tvt satcheck_cadicalt::l_get(literalt a) const
return result;
}

std::string satcheck_cadicalt::solver_text() const
std::string satcheck_cadical_baset::solver_text() const
{
return std::string("CaDiCaL ") + solver->version();
}
Comment on lines +41 to 44
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we override that method to make clear in the output that the solver is used in a non-default configuration?


void satcheck_cadicalt::lcnf(const bvt &bv)
void satcheck_cadical_baset::lcnf(const bvt &bv)
{
for(const auto &lit : bv)
{
Expand Down Expand Up @@ -85,7 +85,7 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
clause_counter++;
}

propt::resultt satcheck_cadicalt::do_prop_solve(const bvt &assumptions)
propt::resultt satcheck_cadical_baset::do_prop_solve(const bvt &assumptions)
{
INVARIANT(status != statust::ERROR, "there cannot be an error");

Expand All @@ -108,6 +108,12 @@ propt::resultt satcheck_cadicalt::do_prop_solve(const bvt &assumptions)
if(!a.is_true())
solver->assume(a.dimacs());

// set preprocessing and inprocessing limits
auto limit1_ret = solver->limit("preprocessing", preprocessing_limit);
CHECK_RETURN(limit1_ret);
auto limit2_ret = solver->limit("localsearch", localsearch_limit);
CHECK_RETURN(limit2_ret);

switch(solver->solve())
{
case 10:
Expand All @@ -128,24 +134,30 @@ propt::resultt satcheck_cadicalt::do_prop_solve(const bvt &assumptions)
return resultt::P_UNSATISFIABLE;
}

void satcheck_cadicalt::set_assignment(literalt a, bool value)
void satcheck_cadical_baset::set_assignment(literalt a, bool value)
{
INVARIANT(!a.is_constant(), "cannot set an assignment for a constant");
INVARIANT(false, "method not supported");
}

satcheck_cadicalt::satcheck_cadicalt(message_handlert &message_handler)
: cnf_solvert(message_handler), solver(new CaDiCaL::Solver())
satcheck_cadical_baset::satcheck_cadical_baset(
int _preprocessing_limit,
int _localsearch_limit,
message_handlert &message_handler)
: cnf_solvert(message_handler),
solver(new CaDiCaL::Solver()),
preprocessing_limit(_preprocessing_limit),
localsearch_limit(_localsearch_limit)
{
solver->set("quiet", 1);
}

satcheck_cadicalt::~satcheck_cadicalt()
satcheck_cadical_baset::~satcheck_cadical_baset()
{
delete solver;
}

bool satcheck_cadicalt::is_in_conflict(literalt a) const
bool satcheck_cadical_baset::is_in_conflict(literalt a) const
{
return solver->failed(a.dimacs());
}
Expand Down
28 changes: 25 additions & 3 deletions src/solvers/sat/satcheck_cadical.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ namespace CaDiCaL // NOLINT(readability/namespace)
class Solver; // NOLINT(readability/identifiers)
}

class satcheck_cadicalt : public cnf_solvert, public hardness_collectort
class satcheck_cadical_baset : public cnf_solvert, public hardness_collectort
{
public:
explicit satcheck_cadicalt(message_handlert &message_handler);
virtual ~satcheck_cadicalt();
satcheck_cadical_baset(
int preprocessing_limit,
int localsearch_limit,
message_handlert &);
virtual ~satcheck_cadical_baset();

std::string solver_text() const override;
tvt l_get(literalt a) const override;
Expand All @@ -46,6 +49,25 @@ class satcheck_cadicalt : public cnf_solvert, public hardness_collectort

// NOLINTNEXTLINE(readability/identifiers)
CaDiCaL::Solver *solver;
int preprocessing_limit = 0, localsearch_limit = 0;
};

class satcheck_cadical_no_preprocessingt : public satcheck_cadical_baset
{
public:
explicit satcheck_cadical_no_preprocessingt(message_handlert &message_handler)
: satcheck_cadical_baset(0, 0, message_handler)
{
}
};

class satcheck_cadical_preprocessingt : public satcheck_cadical_baset
{
public:
explicit satcheck_cadical_preprocessingt(message_handlert &message_handler)
: satcheck_cadical_baset(1, 0, message_handler)
{
}
};

#endif // CPROVER_SOLVERS_SAT_SATCHECK_CADICAL_H
6 changes: 3 additions & 3 deletions unit/solvers/sat/satcheck_cadical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SCENARIO("satcheck_cadical", "[core][solvers][sat][satcheck_cadical]")

GIVEN("A satisfiable formula f")
{
satcheck_cadicalt satcheck(message_handler);
satcheck_cadical_no_preprocessingt satcheck(message_handler);
literalt f = satcheck.new_variable();
satcheck.l_set_to_true(f);

Expand All @@ -42,7 +42,7 @@ SCENARIO("satcheck_cadical", "[core][solvers][sat][satcheck_cadical]")

GIVEN("An unsatisfiable formula f && !f")
{
satcheck_cadicalt satcheck(message_handler);
satcheck_cadical_no_preprocessingt satcheck(message_handler);
literalt f = satcheck.new_variable();
satcheck.l_set_to_true(satcheck.land(f, !f));

Expand All @@ -54,7 +54,7 @@ SCENARIO("satcheck_cadical", "[core][solvers][sat][satcheck_cadical]")

GIVEN("An unsatisfiable formula false implied by a")
{
satcheck_cadicalt satcheck(message_handler);
satcheck_cadical_no_preprocessingt satcheck(message_handler);
literalt a = satcheck.new_variable();
literalt a_implies_false = satcheck.lor(!a, const_literal(false));
satcheck.l_set_to_true(a_implies_false);
Expand Down
Loading