Skip to content
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
2 changes: 1 addition & 1 deletion src/goto-checker/multi_path_symex_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Author: Daniel Kroening, Peter Schrammel

#include <util/ui_message.h>

#include <solvers/hardness_collector.h>
#include <goto-symex/solver_hardness.h>

#include "bmc_util.h"
#include "counterexample_beautification.h"
Expand Down
11 changes: 6 additions & 5 deletions src/goto-checker/solver_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Author: Daniel Kroening, Peter Schrammel
#include <solvers/smt2_incremental/smt_solver_process.h>
#include <solvers/strings/string_refinement.h>

#include <goto-symex/solver_hardness.h>

solver_factoryt::solver_factoryt(
const optionst &_options,
const namespacet &_ns,
Expand Down Expand Up @@ -190,11 +192,10 @@ make_satcheck_prop(message_handlert &message_handler, const optionst &options)
if(
auto hardness_collector = dynamic_cast<hardness_collectort *>(&*satcheck))
{
hardness_collector->enable_hardness_collection();
hardness_collector->with_solver_hardness(
[&options](solver_hardnesst &hardness) {
hardness.set_outfile(options.get_option("write-solver-stats-to"));
});
std::unique_ptr<solver_hardnesst> solver_hardness =
util_make_unique<solver_hardnesst>();
solver_hardness->set_outfile(options.get_option("write-solver-stats-to"));
hardness_collector->solver_hardness = std::move(solver_hardness);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/goto-symex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SRC = auto_objects.cpp \
show_program.cpp \
show_vcc.cpp \
slice.cpp \
solver_hardness.cpp \
ssa_step.cpp \
symex_assign.cpp \
symex_atomic_section.cpp \
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Author: Diffblue Ltd.
#ifndef CPROVER_SOLVERS_SOLVER_HARDNESS_H
#define CPROVER_SOLVERS_SOLVER_HARDNESS_H

#include <solvers/prop/literal.h>
#include <solvers/hardness_collector.h>
#include <solvers/prop/prop_conv_solver.h>

#include <fstream>
#include <string>
Expand Down Expand Up @@ -38,7 +39,7 @@ Author: Diffblue Ltd.
/// derived class of \ref cnft for SAT solving). For this purpose the object
/// lives in the \ref solver_factoryt::solvert and pointers are passed to both
/// \ref decision_proceduret and \ref propt.
struct solver_hardnesst
struct solver_hardnesst : public clause_hardness_collectort
{
// From SAT solver we collect the number of clauses, the number of literals
// and the number of distinct variables that were used in all clauses.
Expand Down Expand Up @@ -160,4 +161,26 @@ struct hash<solver_hardnesst::hardness_ssa_keyt>
};
} // namespace std

static inline void with_solver_hardness(
decision_proceduret &maybe_hardness_collector,
std::function<void(solver_hardnesst &hardness)> handler)
{
// FIXME I am wondering if there is a way to do this that is a bit less
// dynamically typed.
if(
auto prop_conv_solver =
dynamic_cast<prop_conv_solvert *>(&maybe_hardness_collector))
{
if(auto hardness_collector = prop_conv_solver->get_hardness_collector())
{
if(hardness_collector->solver_hardness)
{
auto &solver_hardness = static_cast<solver_hardnesst &>(
*(hardness_collector->solver_hardness));
handler(solver_hardness);
}
}
}
Comment on lines +168 to +183
Copy link
Collaborator

Choose a reason for hiding this comment

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

This surely is better already, but don't we just need a Boolean function like virtual bool set_hardness_collector(solver_hardnesst *) { return false; } in prop_conv_solvert that will return true when the hardness collector was accepted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To make the above go away, you'd need a get_solver_hardness_collector, or the like, in decision_proceduret. I can't get myself to do that.

}

#endif // CPROVER_SOLVERS_SOLVER_HARDNESS_H
6 changes: 2 additions & 4 deletions src/goto-symex/symex_target_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ Author: Daniel Kroening, kroening@kroening.com

#include <util/std_expr.h>

#include <solvers/decision_procedure.h>
#include <solvers/hardness_collector.h>

#include "solver_hardness.h"
#include "ssa_step.h"

static hardness_collectort::handlert
static std::function<void(solver_hardnesst &)>
hardness_register_ssa(std::size_t step_index, const SSA_stept &step)
{
return [step_index, &step](solver_hardnesst &hardness) {
Expand Down
1 change: 0 additions & 1 deletion src/solvers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ SRC = $(BOOLEFORCE_SRC) \
$(SQUOLEM2_SRC) \
$(CADICAL_SRC) \
decision_procedure.cpp \
solver_hardness.cpp \
flattening/arrays.cpp \
flattening/boolbv.cpp \
flattening/boolbv_abs.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/solvers/flattening/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Author: Daniel Kroening, kroening@kroening.com

#include "equality.h"

class array_comprehension_exprt;
class array_exprt;
class array_of_exprt;
class equal_exprt;
class if_exprt;
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class floatbv_typecast_exprt;
class ieee_float_op_exprt;
class member_exprt;
class replication_exprt;
class union_typet;

class boolbvt:public arrayst
{
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/namespace.h>
#include <util/simplify_expr.h>
#include <util/std_expr.h>
#include <util/threeval.h>
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv_member.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Author: Daniel Kroening, kroening@kroening.com
#include "boolbv.h"

#include <util/c_types.h>
#include <util/namespace.h>

static bvt convert_member_struct(
const member_exprt &expr,
Expand Down
2 changes: 2 additions & 0 deletions src/solvers/flattening/boolbv_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Author: Daniel Kroening, kroening@kroening.com

#include "boolbv.h"

#include <util/namespace.h>

bvt boolbvt::convert_struct(const struct_exprt &expr)
{
const struct_typet &struct_type=to_struct_type(ns.follow(expr.type()));
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com

#include <util/bitvector_types.h>
#include <util/c_types.h>
#include <util/namespace.h>

#include <solvers/floatbv/float_utils.h>

Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/namespace.h>

bvt boolbvt::convert_update(const update_exprt &expr)
{
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/boolbv_with.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/namespace.h>
#include <util/std_expr.h>

bvt boolbvt::convert_with(const with_exprt &expr)
Expand Down
1 change: 1 addition & 0 deletions src/solvers/flattening/bv_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com
#include <util/c_types.h>
#include <util/config.h>
#include <util/exception_utils.h>
#include <util/namespace.h>
#include <util/pointer_expr.h>
#include <util/pointer_offset_size.h>
#include <util/pointer_predicates.h>
Expand Down
47 changes: 26 additions & 21 deletions src/solvers/hardness_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@ Author: Diffblue Ltd.
#ifndef CPROVER_SOLVERS_HARDNESS_COLLECTOR_H
#define CPROVER_SOLVERS_HARDNESS_COLLECTOR_H

#include <functional>
#include <solvers/solver_hardness.h>
#include <solvers/prop/literal.h>

class exprt;
#include <memory>

class hardness_collectort
struct solver_hardnesst;

class clause_hardness_collectort
{
public:
using handlert = std::function<void(solver_hardnesst &)>;
virtual void with_solver_hardness(handlert handler) = 0;
virtual void enable_hardness_collection() = 0;
virtual ~hardness_collectort() = default;
/// Called e.g. from the `satcheck_minisat2::lcnf`, this function adds the
/// complexity statistics from the last SAT query to the `current_ssa_key`.
/// \param bv: the clause (vector of literals)
/// \param cnf: processed clause
/// \param cnf_clause_index: index of clause in dimacs output
/// \param register_cnf: negation of boolean variable tracking if the clause
/// can be eliminated
virtual void register_clause(
const bvt &bv,
const bvt &cnf,
const size_t cnf_clause_index,
bool register_cnf) = 0;

virtual ~clause_hardness_collectort()
{
}
};

template <typename T>
void with_solver_hardness(
T &maybe_hardness_collector,
hardness_collectort::handlert handler)
class hardness_collectort
{
// FIXME I am wondering if there is a way to do this that is a bit less
// dynamically typed.
if(
auto hardness_collector =
dynamic_cast<hardness_collectort *>(&maybe_hardness_collector))
{
hardness_collector->with_solver_hardness(handler);
}
}
public:
std::unique_ptr<clause_hardness_collectort> solver_hardness;
};

#endif // CPROVER_SOLVERS_HARDNESS_COLLECTOR_H
1 change: 0 additions & 1 deletion src/solvers/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cplusplus # cudd
cudd
goto-programs
solvers
util
13 changes: 0 additions & 13 deletions src/solvers/prop/prop_conv_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,3 @@ std::string prop_conv_solvert::decision_procedure_text() const
{
return "propositional reduction";
}

void prop_conv_solvert::with_solver_hardness(
hardness_collectort::handlert handler)
{
::with_solver_hardness(prop, handler);
}
void prop_conv_solvert::enable_hardness_collection()
{
if(auto hardness_collector = dynamic_cast<hardness_collectort *>(&prop))
{
hardness_collector->enable_hardness_collection();
}
}
11 changes: 7 additions & 4 deletions src/solvers/prop/prop_conv_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ Author: Daniel Kroening, kroening@kroening.com
#include "prop_conv.h"
#include "solver_resource_limits.h"

class equal_exprt;

class prop_conv_solvert : public conflict_providert,
public prop_convt,
public solver_resource_limitst,
public hardness_collectort
public solver_resource_limitst
{
public:
prop_conv_solvert(propt &_prop, message_handlert &message_handler)
Expand Down Expand Up @@ -95,8 +96,10 @@ class prop_conv_solvert : public conflict_providert,

std::size_t get_number_of_solver_calls() const override;

void with_solver_hardness(handlert handler) override;
void enable_hardness_collection() override;
hardness_collectort *get_hardness_collector()
{
return dynamic_cast<hardness_collectort *>(&prop);
}

protected:
virtual void post_process();
Expand Down
8 changes: 5 additions & 3 deletions src/solvers/sat/satcheck_cadical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
}
solver->add(0); // terminate clause

with_solver_hardness([this, &bv](solver_hardnesst &hardness) {
if(solver_hardness)
{
// To map clauses to lines of program code, track clause indices in the
// dimacs cnf output. Dimacs output is generated after processing
// clauses to remove duplicates and clauses that are trivially true.
Expand All @@ -77,8 +78,9 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
if(!clause_removed)
cnf_clause_index++;

hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
});
solver_hardness->register_clause(
bv, cnf, cnf_clause_index, !clause_removed);
}

clause_counter++;
}
Expand Down
16 changes: 0 additions & 16 deletions src/solvers/sat/satcheck_cadical.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,13 @@ class satcheck_cadicalt : public cnf_solvert, public hardness_collectort
}
bool is_in_conflict(literalt a) const override;

void
with_solver_hardness(std::function<void(solver_hardnesst &)> handler) override
{
if(solver_hardness.has_value())
{
handler(solver_hardness.value());
}
}

void enable_hardness_collection() override
{
solver_hardness = solver_hardnesst{};
}

protected:
resultt do_prop_solve() override;

// NOLINTNEXTLINE(readability/identifiers)
CaDiCaL::Solver * solver;

bvt assumptions;

optionalt<solver_hardnesst> solver_hardness;
};

#endif // CPROVER_SOLVERS_SAT_SATCHECK_CADICAL_H
8 changes: 5 additions & 3 deletions src/solvers/sat/satcheck_glucose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ void satcheck_glucose_baset<T>::lcnf(const bvt &bv)

solver->addClause_(c);

with_solver_hardness([this, &bv](solver_hardnesst &hardness) {
if(solver_hardness)
{
// To map clauses to lines of program code, track clause indices in the
// dimacs cnf output. Dimacs output is generated after processing
// clauses to remove duplicates and clauses that are trivially true.
Expand All @@ -137,8 +138,9 @@ void satcheck_glucose_baset<T>::lcnf(const bvt &bv)
if(!clause_removed)
cnf_clause_index++;

hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
});
solver_hardness->register_clause(
bv, cnf, cnf_clause_index, !clause_removed);
}

clause_counter++;
}
Expand Down
16 changes: 0 additions & 16 deletions src/solvers/sat/satcheck_glucose.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,13 @@ class satcheck_glucose_baset : public cnf_solvert, public hardness_collectort
return true;
}

void
with_solver_hardness(std::function<void(solver_hardnesst &)> handler) override
{
if(solver_hardness.has_value())
{
handler(solver_hardness.value());
}
}

void enable_hardness_collection() override
{
solver_hardness = solver_hardnesst{};
}

protected:
resultt do_prop_solve() override;

std::unique_ptr<T> solver;

void add_variables();
bvt assumptions;

optionalt<solver_hardnesst> solver_hardness;
};

class satcheck_glucose_no_simplifiert:
Expand Down
Loading