Commit c7755637 authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

One provability options of pccompile

parent d9df191c
...@@ -52,7 +52,7 @@ struct config_t ...@@ -52,7 +52,7 @@ struct config_t
SUBool::PCEncoder::UP_EMPOWER::ONE_LEVEL}; SUBool::PCEncoder::UP_EMPOWER::ONE_LEVEL};
SUBool::AbsEncoder::AbsConfig enc_conf{}; SUBool::AbsEncoder::AbsConfig enc_conf{};
SUBool::AbsCheckerSAT::Timeouts timeouts{}; SUBool::AbsCheckerSAT::Timeouts timeouts{};
SUBool::LIT_IMPL_SYSTEM impl_system{SUBool::LIT_IMPL_SYSTEM::NONE}; SUBool::LIT_IMPL_SYSTEM impl_system{SUBool::LIT_IMPL_SYSTEM::Default};
GOAL goal{GOAL::PC}; GOAL goal{GOAL::PC};
SUBool::AmoEncoder::KIND amo_encoding{SUBool::AmoEncoder::KIND::REPR}; SUBool::AmoEncoder::KIND amo_encoding{SUBool::AmoEncoder::KIND::REPR};
SUBool::ExOneEncoder::KIND exone_encoding{SUBool::ExOneEncoder::KIND::REPR}; SUBool::ExOneEncoder::KIND exone_encoding{SUBool::ExOneEncoder::KIND::REPR};
...@@ -89,11 +89,13 @@ dump_config(const config_t &conf, unsigned level) ...@@ -89,11 +89,13 @@ dump_config(const config_t &conf, unsigned level)
SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl; SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl;
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\toutput_file: " << conf.output_file << std::endl; << "\toutput_file: " << conf.output_file << std::endl;
SUBool::logs.DumpVerbosity("\t", level);
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\tencode_only: " << SUBool::bool_to_string(conf.encode_only) << "\tencode_only: " << SUBool::bool_to_string(conf.encode_only)
<< std::endl; << std::endl;
SUBool::logs.DumpValue("\t", level, "no_up_backbones", conf.no_up_backbones); SUBool::logs.DumpValue("\t", level, "no_up_backbones", conf.no_up_backbones);
SUBool::kLitImplSystemAnnotation.DumpValue(
"\t", level, "impl_system", conf.impl_system);
SUBool::PCEncoder::kUPEmpowerAnnotation.DumpValue( SUBool::PCEncoder::kUPEmpowerAnnotation.DumpValue(
"\t", level, "up_empower", conf.up_empower); "\t", level, "up_empower", conf.up_empower);
SUBool::logs.TLog(level) << "\tenc_conf:" << std::endl; SUBool::logs.TLog(level) << "\tenc_conf:" << std::endl;
...@@ -105,8 +107,8 @@ dump_config(const config_t &conf, unsigned level) ...@@ -105,8 +107,8 @@ dump_config(const config_t &conf, unsigned level)
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\ttimeouts.level_factor: " << conf.timeouts.level_factor << "\ttimeouts.level_factor: " << conf.timeouts.level_factor
<< std::endl; << std::endl;
SUBool::dump_enum_value( SUBool::kLitImplSystemAnnotation.DumpValue(
"\t", level, "impl_system", conf.impl_system, SUBool::kImplSystemNames); "\t", level, "impl_system", conf.impl_system);
SUBool::logs.TLog(level) << "\tgoal: " << goal_name(conf) << std::endl; SUBool::logs.TLog(level) << "\tgoal: " << goal_name(conf) << std::endl;
SUBool::AmoEncoder::kKindAnnotation.DumpValue( SUBool::AmoEncoder::kKindAnnotation.DumpValue(
"\t", level, "amo_encoding", conf.amo_encoding); "\t", level, "amo_encoding", conf.amo_encoding);
......
...@@ -65,7 +65,7 @@ struct config_t ...@@ -65,7 +65,7 @@ struct config_t
SUBool::AbsEncoder::AbsConfig(), SUBool::AbsEncoder::AbsConfig(),
SUBool::AbsCheckerSAT::Timeouts(), SUBool::AbsCheckerSAT::Timeouts(),
true, true,
SUBool::LIT_IMPL_SYSTEM::NONE, SUBool::LIT_IMPL_SYSTEM::Default,
SUBool::SOLVER_TYPE::GLUCOSE, SUBool::SOLVER_TYPE::GLUCOSE,
}; };
bool unfinished_write{true}; bool unfinished_write{true};
...@@ -102,12 +102,15 @@ dump_config(const config_t &conf, unsigned level) ...@@ -102,12 +102,15 @@ dump_config(const config_t &conf, unsigned level)
SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl; SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl;
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\toutput_file: " << conf.output_file << std::endl; << "\toutput_file: " << conf.output_file << std::endl;
SUBool::logs.DumpVerbosity("\t", level);
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\tminimize: " << SUBool::bool_to_string(conf.minimize) << std::endl; << "\tminimize: " << SUBool::bool_to_string(conf.minimize) << std::endl;
SUBool::kMinimizeMethodAnnotation.DumpValue( SUBool::kMinimizeMethodAnnotation.DumpValue(
"\t", level, "minimize_method", conf.comp_base_config.minimize_method); "\t", level, "minimize_method", conf.comp_base_config.minimize_method);
SUBool::PCCompAlgorithmOptions::kAlgorithmAnnotation.DumpValue( SUBool::PCCompAlgorithmOptions::kAlgorithmAnnotation.DumpValue(
"\t", level, "algorithm", conf.algorithm); "\t", level, "algorithm", conf.algorithm);
SUBool::kLitImplSystemAnnotation.DumpValue(
"\t", level, "impl_system", conf.comp_base_config.impl_system);
SUBool::PCEncoder::kUPEmpowerAnnotation.DumpValue("\t", level, SUBool::PCEncoder::kUPEmpowerAnnotation.DumpValue("\t", level,
"comp_base_config.up_empower", conf.comp_base_config.up_empower); "comp_base_config.up_empower", conf.comp_base_config.up_empower);
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
...@@ -119,9 +122,8 @@ dump_config(const config_t &conf, unsigned level) ...@@ -119,9 +122,8 @@ dump_config(const config_t &conf, unsigned level)
SUBool::logs.TLog(level) SUBool::logs.TLog(level)
<< "\tlevel_simplify: " << (conf.level_simplify ? "yes" : "no") << "\tlevel_simplify: " << (conf.level_simplify ? "yes" : "no")
<< std::endl; << std::endl;
SUBool::dump_enum_value("\t", level, "comp_base_config.impl_system", SUBool::kLitImplSystemAnnotation.DumpValue("\t", level,
conf.comp_base_config.impl_system, SUBool::kImplSystemNames); "comp_base_config.impl_system", conf.comp_base_config.impl_system);
SUBool::logs.TLog(level) << "\tverbosity: " << conf.verbosity << std::endl;
SUBool::AbsComp::kPreprocessMethodAnnotation.DumpValue("\t", level, SUBool::AbsComp::kPreprocessMethodAnnotation.DumpValue("\t", level,
"comp_base_config.preprocess", conf.comp_base_config.preprocess); "comp_base_config.preprocess", conf.comp_base_config.preprocess);
SUBool::logs.DumpValue("\t", level, "comp_base_config.propagate_backbones", SUBool::logs.DumpValue("\t", level, "comp_base_config.propagate_backbones",
...@@ -206,12 +208,12 @@ parse_arguments(int argc, char *argv[], config_t &conf) ...@@ -206,12 +208,12 @@ parse_arguments(int argc, char *argv[], config_t &conf)
opts.MakeOptionsGroup<SUBool::PCCompPreprocessOptions>(); opts.MakeOptionsGroup<SUBool::PCCompPreprocessOptions>();
auto solver_opts = opts.MakeOptionsGroup<SUBool::PCSolverOptions>(); auto solver_opts = opts.MakeOptionsGroup<SUBool::PCSolverOptions>();
auto empower_opts = opts.MakeOptionsGroup<SUBool::PCEmpowerOptions>(); auto empower_opts = opts.MakeOptionsGroup<SUBool::PCEmpowerOptions>();
auto oneprove_opts = opts.MakeOptionsGroup<SUBool::PCOneProveOptions>();
if (!opts.Parse(argc, argv)) if (!opts.Parse(argc, argv))
{ {
return 1; return 1;
} }
conf.algorithm = algorithm_opts->Algorithm(); conf.algorithm = algorithm_opts->Algorithm();
conf.use_empty_initial_hypothesis = conf.use_empty_initial_hypothesis =
pclearncomp_opts->UseEmptyInitialHypothesis(); pclearncomp_opts->UseEmptyInitialHypothesis();
conf.initial_negatives = pclearncomp_opts->InitialNegatives(); conf.initial_negatives = pclearncomp_opts->InitialNegatives();
...@@ -220,6 +222,12 @@ parse_arguments(int argc, char *argv[], config_t &conf) ...@@ -220,6 +222,12 @@ parse_arguments(int argc, char *argv[], config_t &conf)
!preprocess_opts->NoBackbonePropagation(); !preprocess_opts->NoBackbonePropagation();
conf.comp_base_config.solver_type = solver_opts->SolverType(); conf.comp_base_config.solver_type = solver_opts->SolverType();
conf.comp_base_config.up_empower = empower_opts->Empower(); conf.comp_base_config.up_empower = empower_opts->Empower();
conf.comp_base_config.enc_conf.up_one_prove = oneprove_opts->OneProve();
conf.comp_base_config.enc_conf.up_level_bound =
oneprove_opts->UPLevelBound();
conf.comp_base_config.enc_conf.log_conf =
oneprove_opts->EncLogarithmicConf();
conf.comp_base_config.impl_system = oneprove_opts->ImplSystem();
return 0; return 0;
#if 0 #if 0
try try
......
...@@ -187,7 +187,7 @@ minimize(const config_t &conf, SUBool::CNF cnf) ...@@ -187,7 +187,7 @@ minimize(const config_t &conf, SUBool::CNF cnf)
{ {
SUBool::CPUTime cpu_time; SUBool::CPUTime cpu_time;
SUBool::CompHypothesis hyp(conf.minimize_method, SUBool::CompHypothesis hyp(conf.minimize_method,
SUBool::LIT_IMPL_SYSTEM::NONE, SUBool::CNF(), std::move(cnf), false); SUBool::LIT_IMPL_SYSTEM::Default, SUBool::CNF(), std::move(cnf), false);
if (conf.backbones if (conf.backbones
&& !run_with_timeout( && !run_with_timeout(
conf.timeout < 0.0f, conf.timeout - cpu_time.TimeSpan(), conf.timeout < 0.0f, conf.timeout - cpu_time.TimeSpan(),
......
...@@ -78,7 +78,7 @@ namespace SUBool ...@@ -78,7 +78,7 @@ namespace SUBool
AbsEncoder::AbsConfig enc_conf{}; AbsEncoder::AbsConfig enc_conf{};
AbsCheckerSAT::Timeouts timeouts{}; AbsCheckerSAT::Timeouts timeouts{};
bool level_simplify{true}; bool level_simplify{true};
LIT_IMPL_SYSTEM impl_system{LIT_IMPL_SYSTEM::NONE}; LIT_IMPL_SYSTEM impl_system{LIT_IMPL_SYSTEM::Default};
SOLVER_TYPE solver_type{SOLVER_TYPE::GLUCOSE}; SOLVER_TYPE solver_type{SOLVER_TYPE::GLUCOSE};
}; };
......
...@@ -22,6 +22,36 @@ ...@@ -22,6 +22,36 @@
#include "up_scc_binary.h" #include "up_scc_binary.h"
#include "up_scc_unary.h" #include "up_scc_unary.h"
const SUBool::EnumAnnotation<SUBool::AbsEncoder::UP_ONE_PROVE>
SUBool::AbsEncoder::kUPOneProveAnnotation("UP_ONE_PROVE",
{//
{UP_ONE_PROVE::QUADRATIC_EQUIV, "quadratic_equiv",
"quadratic encoding with equivalences."}, //
{UP_ONE_PROVE::QUADRATIC_ONE_SIDED, "quadratic_one_sided",
"quadratic encoding with implications."}, //
{UP_ONE_PROVE::LOGARITHMIC, "logarithmic",
"based on encoding levels of unit propagations with binary "
"encoding (logarithmic size)"}, //
{UP_ONE_PROVE::MAX_LEVEL, "max_level",
"encoding based on determining a maximum level of a literal in "
"a clause"}, //
{UP_ONE_PROVE::MIN_LQ, "min_lq",
"each time, pick the smaller one from the quadratic encoding "
"with implications (quadratic_one_sided) and the logarithmic "
"encoding (logarithmic)"}, //
{UP_ONE_PROVE::QUAD_IMPL_SYSTEM, "quad_impl_system",
"quadratic encoding which uses an implication system to "
"represent the dual rail encoding."}, //
{UP_ONE_PROVE::IMPL_LEVEL, "impl_level",
"encoding based on an implication system where levels are "
"encoded in binary."}, //
{UP_ONE_PROVE::SCC_UNARY, "scc_unary",
"encoding based on the strongly connected components (SCC) of "
"an implication system with unary encoding of levels."}, //
{UP_ONE_PROVE::SCC_BINARY, "scc_binary",
"encoding based on the strongly connected components (SCC) of "
"an implication system with binary encoding of levels."}});
SUBool::AbsEncoder::AbsEncoder(const AbsConfig &conf) SUBool::AbsEncoder::AbsEncoder(const AbsConfig &conf)
: mVarStore(conf.use_backmap), mClauses(), mOneProveEncoder(), : mVarStore(conf.use_backmap), mClauses(), mOneProveEncoder(),
mCnfMaxVariable(0), mMaxUPLevelBound(0) mCnfMaxVariable(0), mMaxUPLevelBound(0)
...@@ -198,9 +228,8 @@ void ...@@ -198,9 +228,8 @@ void
SUBool::AbsEncoder::AbsConfig::Dump( SUBool::AbsEncoder::AbsConfig::Dump(
const std::string &line_prefix, unsigned level) const const std::string &line_prefix, unsigned level) const
{ {
logs.DumpValue(line_prefix, level, "up_one_prove", kUPOneProveAnnotation.DumpValue(
AbsEncoder::kUPOneProveNames.at(static_cast<unsigned>(up_one_prove)) line_prefix, level, "up_one_prove", up_one_prove);
+ " (" + std::to_string(static_cast<unsigned>(up_one_prove)) + ")");
logs.DumpValue(line_prefix, level, "optimize", optimize); logs.DumpValue(line_prefix, level, "optimize", optimize);
logs.DumpValue(line_prefix, level, "up_level_bound", up_level_bound); logs.DumpValue(line_prefix, level, "up_level_bound", up_level_bound);
logs.DumpValue(line_prefix, level, "use_backmap", use_backmap); logs.DumpValue(line_prefix, level, "use_backmap", use_backmap);
...@@ -211,16 +240,3 @@ SUBool::AbsEncoder::AbsConfig::Dump( ...@@ -211,16 +240,3 @@ SUBool::AbsEncoder::AbsConfig::Dump(
line_prefix, level, "min_lq_quad_weights", min_lq_quad_weights); line_prefix, level, "min_lq_quad_weights", min_lq_quad_weights);
} }
auto
SUBool::AbsEncoder::ParseUPOneProve(const std::string &up_one_prove)
-> UP_ONE_PROVE
{
if (isdigit(up_one_prove.front()))
{
return enum_of_int<SUBool::AbsEncoder::UP_ONE_PROVE>(
std::stol(up_one_prove));
}
return enum_of_name<SUBool::AbsEncoder::UP_ONE_PROVE>(
up_one_prove, SUBool::AbsEncoder::kUPOneProveNames);
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "cardinal.h" #include "cardinal.h"
#include "cl2lit.h" #include "cl2lit.h"
#include "enum.h"
#include "glucose_bind.h" #include "glucose_bind.h"
#include "impl_system.h" #include "impl_system.h"
#include "impl_system_graph.h" #include "impl_system_graph.h"
...@@ -40,8 +41,7 @@ namespace SUBool ...@@ -40,8 +41,7 @@ namespace SUBool
QUAD_IMPL_SYSTEM, QUAD_IMPL_SYSTEM,
IMPL_LEVEL, IMPL_LEVEL,
SCC_UNARY, SCC_UNARY,
SCC_BINARY, SCC_BINARY
Last = SCC_BINARY
}; };
struct UPOneProveTraits struct UPOneProveTraits
...@@ -51,26 +51,19 @@ namespace SUBool ...@@ -51,26 +51,19 @@ namespace SUBool
bool requires_scc_graph; bool requires_scc_graph;
}; };
inline static const std::array< inline static const std::array kUPOneProveTraits{
UPOneProveTraits, static_cast<unsigned>(UP_ONE_PROVE::Last) + 1> UPOneProveTraits{UP_ONE_PROVE::QUADRATIC_EQUIV, false, false},
kUPOneProveTraits = { UPOneProveTraits{UP_ONE_PROVE::QUADRATIC_ONE_SIDED, false, false},
UPOneProveTraits{UP_ONE_PROVE::QUADRATIC_EQUIV, false, false}, UPOneProveTraits{UP_ONE_PROVE::LOGARITHMIC, false, false},
UPOneProveTraits{UP_ONE_PROVE::QUADRATIC_ONE_SIDED, false, false}, UPOneProveTraits{UP_ONE_PROVE::MAX_LEVEL, false, false},
UPOneProveTraits{UP_ONE_PROVE::LOGARITHMIC, false, false}, UPOneProveTraits{UP_ONE_PROVE::MIN_LQ, false, false},
UPOneProveTraits{UP_ONE_PROVE::MAX_LEVEL, false, false}, UPOneProveTraits{UP_ONE_PROVE::QUAD_IMPL_SYSTEM, true, false},
UPOneProveTraits{UP_ONE_PROVE::MIN_LQ, false, false}, UPOneProveTraits{UP_ONE_PROVE::IMPL_LEVEL, true, false},
UPOneProveTraits{UP_ONE_PROVE::QUAD_IMPL_SYSTEM, true, false}, UPOneProveTraits{UP_ONE_PROVE::SCC_UNARY, true, true},
UPOneProveTraits{UP_ONE_PROVE::IMPL_LEVEL, true, false}, UPOneProveTraits{UP_ONE_PROVE::SCC_BINARY, true, true}};
UPOneProveTraits{UP_ONE_PROVE::SCC_UNARY, true, true},
UPOneProveTraits{UP_ONE_PROVE::SCC_BINARY, true, true}}; static const EnumAnnotation<UP_ONE_PROVE> kUPOneProveAnnotation;
inline static const std::array<
std::string, static_cast<unsigned>(UP_ONE_PROVE::Last) + 1>
kUPOneProveNames = {"quadratic_equiv", "quadratic_one_sided",
"logarithmic", "max_level",
"min_lq", "quad_impl_system",
"impl_level", "scc_unary",
"scc_binary"};
static UP_ONE_PROVE ParseUPOneProve(const std::string &up_one_prove); static UP_ONE_PROVE ParseUPOneProve(const std::string &up_one_prove);
struct AbsConfig struct AbsConfig
...@@ -95,8 +88,8 @@ namespace SUBool ...@@ -95,8 +88,8 @@ namespace SUBool
AbsConfig(AbsConfig &&conf) = default; AbsConfig(AbsConfig &&conf) = default;
AbsConfig &operator=(const AbsConfig &conf) = default; AbsConfig &operator=(const AbsConfig &conf) = default;
AbsConfig &operator=(AbsConfig &&conf) = default; AbsConfig &operator=(AbsConfig &&conf) = default;
virtual void Dump(const std::string &line_prefix, virtual void Dump(
unsigned level) const; const std::string &line_prefix, unsigned level) const;
static constexpr bool static constexpr bool
OneProveRequiresImplSystem(UP_ONE_PROVE op) OneProveRequiresImplSystem(UP_ONE_PROVE op)
{ {
...@@ -119,25 +112,23 @@ namespace SUBool ...@@ -119,25 +112,23 @@ namespace SUBool
unsigned mMaxUPLevelBound; unsigned mMaxUPLevelBound;
virtual void InitOneProveEncoder(const CNF &cnf, virtual void InitOneProveEncoder(const CNF &cnf,
const ClausesToLiterals &cl2lit, const ClausesToLiterals &cl2lit, const LitImplSystem &impl_system,
const LitImplSystem &impl_system, const LitISGraph &scc_graph);
const LitISGraph &scc_graph);
virtual void WriteHeader(std::ostream &out) const; virtual void WriteHeader(std::ostream &out) const;
virtual std::string Name() const = 0; virtual std::string Name() const = 0;
virtual void WriteMappingsOfVariable(std::ostream &out, unsigned i) const; virtual void WriteMappingsOfVariable(std::ostream &out, unsigned i) const;
virtual void WriteClause(std::ostream &out, const Clause &clause) const; virtual void WriteClause(std::ostream &out, const Clause &clause) const;
virtual void AddClauses(const CNF &cnf, const ClausesToLiterals &cl2lit, virtual void AddClauses(const CNF &cnf, const ClausesToLiterals &cl2lit,
const LitImplSystem &impl_system) = 0; const LitImplSystem &impl_system) = 0;
virtual const AbsConfig &GetConfig() const = 0; virtual const AbsConfig &GetConfig() const = 0;
public: public:
AbsEncoder(const AbsConfig &conf = AbsConfig()); AbsEncoder(const AbsConfig &conf = AbsConfig());
virtual ~AbsEncoder() = default; virtual ~AbsEncoder() = default;
virtual void BuildEncoding(const CNF &cnf, virtual void BuildEncoding(const CNF &cnf,
const ClausesToLiterals &cl2lit, const ClausesToLiterals &cl2lit, const LitImplSystem &impl_system,
const LitImplSystem &impl_system, const LitISGraph &scc_graph);
const LitISGraph &scc_graph);
virtual unsigned MaxVariable() const; virtual unsigned MaxVariable() const;
virtual unsigned Size() const; virtual unsigned Size() const;
...@@ -146,14 +137,12 @@ namespace SUBool ...@@ -146,14 +137,12 @@ namespace SUBool
virtual bool RequiresSCCGraph() const; virtual bool RequiresSCCGraph() const;
virtual unsigned MaxUPLevelBound() const; virtual unsigned MaxUPLevelBound() const;
virtual unsigned NextUPLevelBound(const CNF &cnf, virtual unsigned NextUPLevelBound(const CNF &cnf,
const ClausesToLiterals &cl2lit, const ClausesToLiterals &cl2lit, const LitImplSystem &impl_system,
const LitImplSystem &impl_system, const LitISGraph &scc_graph, unsigned level);
const LitISGraph &scc_graph,
unsigned level);
// The meaning of the return value depends on descendant, // The meaning of the return value depends on descendant,
// in any case it returns a witness variable (e.g. empowered) // in any case it returns a witness variable (e.g. empowered)
virtual unsigned ExtractClause(const SolverInterface &solver, virtual unsigned ExtractClause(
Clause *clause) const = 0; const SolverInterface &solver, Clause *clause) const = 0;
virtual bool PassToSolver(SolverInterface &solver) const; virtual bool PassToSolver(SolverInterface &solver) const;
virtual void WriteEncoding(std::ostream &out) const; virtual void WriteEncoding(std::ostream &out) const;
......
...@@ -34,7 +34,7 @@ namespace SUBool ...@@ -34,7 +34,7 @@ namespace SUBool
bool mHypSimplified{false}; bool mHypSimplified{false};
bool mReprSimplified{false}; bool mReprSimplified{false};
MINIMIZE_METHOD mMinimizeMethod{MINIMIZE_METHOD::FULL}; MINIMIZE_METHOD mMinimizeMethod{MINIMIZE_METHOD::FULL};
LIT_IMPL_SYSTEM mImplSystemKind{kDefaultImplSystem}; LIT_IMPL_SYSTEM mImplSystemKind{LIT_IMPL_SYSTEM::Default};
std::vector<Literal> mBackbone{}; std::vector<Literal> mBackbone{};
CNFCompressor mCompressor{}; CNFCompressor mCompressor{};
LitImplSystem mImplSystem{}; LitImplSystem mImplSystem{};
...@@ -67,11 +67,10 @@ namespace SUBool ...@@ -67,11 +67,10 @@ namespace SUBool
public: public:
static const unsigned kSimpLogThreshold = 3000; static const unsigned kSimpLogThreshold = 3000;
CompHypothesis(
MINIMIZE_METHOD minimize_method, LIT_IMPL_SYSTEM impl_system_kind);
CompHypothesis(MINIMIZE_METHOD minimize_method, CompHypothesis(MINIMIZE_METHOD minimize_method,
LIT_IMPL_SYSTEM impl_system_kind); LIT_IMPL_SYSTEM impl_system_kind, CNF cnf, CNF repr, bool safe);
CompHypothesis(MINIMIZE_METHOD minimize_method,
LIT_IMPL_SYSTEM impl_system_kind, CNF cnf, CNF repr,
bool safe);
~CompHypothesis() = default; ~CompHypothesis() = default;
void ClearHypothesis(); void ClearHypothesis();
...@@ -109,17 +108,17 @@ namespace SUBool ...@@ -109,17 +108,17 @@ namespace SUBool
void SetSafe(); void SetSafe();
bool Safe() const; bool Safe() const;
std::optional<PartialAssignment> std::optional<PartialAssignment> PropagateUP(
PropagateUP(const PartialAssignment &alpha); const PartialAssignment &alpha);
std::optional<PartialAssignment> std::optional<PartialAssignment> PropagateAllSAT(
PropagateAllSAT(const PartialAssignment &alpha); // const; const PartialAssignment &alpha); // const;
std::optional<std::vector<Literal>> std::optional<std::vector<Literal>> AllEmpoweredLiterals(
AllEmpoweredLiterals(const Clause &clause); const Clause &clause);
std::optional<Literal> EmpoweredLiteral(const Clause &clause); std::optional<Literal> EmpoweredLiteral(const Clause &clause);
bool SimplifyHypothesis(); // true if simplification executed bool SimplifyHypothesis(); // true if simplification executed
bool SimplifyRepresentation(); // true if simplification executed bool SimplifyRepresentation(); // true if simplification executed
std::vector<ClauseWithEmpowered> std::vector<ClauseWithEmpowered> MinimizeReprWithCollectingEmpowered(
MinimizeReprWithCollectingEmpowered(bool collect_all); bool collect_all);
const CNFCompressor & const CNFCompressor &
Compressor() const Compressor() const
{ {
...@@ -132,11 +131,10 @@ namespace SUBool ...@@ -132,11 +131,10 @@ namespace SUBool
bool IsEmpowering(const Clause &c); bool IsEmpowering(const Clause &c);
bool IsImplicate(const Clause &clause) const; bool IsImplicate(const Clause &clause) const;
std::optional<Clause> PrimeSubimplicate(const Clause &clause, std::optional<Clause> PrimeSubimplicate(
unsigned ignore_var, const Clause &clause, unsigned ignore_var, bool promised_sat) const;
bool promised_sat) const; std::optional<Clause> FindEmpowering(
std::optional<Clause> FindEmpowering(AbsCheckerSAT &checker, AbsCheckerSAT &checker, bool level_simplify);
bool level_simplify);
void PushBack(Clause c); void PushBack(Clause c);
// Returns true if pushed // Returns true if pushed
bool PushIfEmpowering(const Clause &c, bool find_prime_subimplicate); bool PushIfEmpowering(const Clause &c, bool find_prime_subimplicate);
......
...@@ -9,25 +9,27 @@ ...@@ -9,25 +9,27 @@
#include "drenc.h" #include "drenc.h"
const std::array<std::string, const SUBool::EnumAnnotation<SUBool::LIT_IMPL_SYSTEM>
static_cast<unsigned>(SUBool::LIT_IMPL_SYSTEM::Last) + 1> SUBool::kLitImplSystemAnnotation("LIT_IMPL_SYSTEM",
SUBool::kImplSystemNames = {"none", { //
"drenc", {LIT_IMPL_SYSTEM::DRENC, "drenc", "plain dual rail encoding"}, //
"irredundant", {LIT_IMPL_SYSTEM::IRREDUNDANT, "irredundant",
"gdbasis", "make the dual rail encoding irredundant (both body and right "
"gdbasis_right_irred", "irredundant)"}, //
"body_minimal", {LIT_IMPL_SYSTEM::GDBASIS, "gdbasis",
"body_minimal_irred"}; "use GD basis of the dual rail encoding."}, //
const SUBool::LIT_IMPL_SYSTEM SUBool::kDefaultImplSystem = {LIT_IMPL_SYSTEM::GDBASIS_RIGHT_IRRED, "gdbasis_right_irred",
SUBool::LIT_IMPL_SYSTEM::BODY_MINIMAL_IRRED; "construct the GD basis and make it right irredundant."}, //
{LIT_IMPL_SYSTEM::BODY_MINIMAL, "body_minimal",
"make the dual rail encoding body minimal (like GD basis but "
"without left saturation)."}, //
{LIT_IMPL_SYSTEM::BODY_MINIMAL_IRRED, "body_minimal_irred",
"make the dual rail encoding body minimal and right "
"irredundant."}});
SUBool::LitImplSystem SUBool::LitImplSystem
SUBool::init_lit_impl_system(const CNF &cnf, LIT_IMPL_SYSTEM is_kind) SUBool::init_lit_impl_system(const CNF &cnf, LIT_IMPL_SYSTEM is_kind)
{ {
if (is_kind == LIT_IMPL_SYSTEM::NONE)
{
return SUBool::LitImplSystem();
}
auto impl_system = dual_rail(cnf, true); auto impl_system = dual_rail(cnf, true);
if (is_kind == LIT_IMPL_SYSTEM::GDBASIS if (is_kind == LIT_IMPL_SYSTEM::GDBASIS
|| is_kind == LIT_IMPL_SYSTEM::GDBASIS_RIGHT_IRRED) || is_kind == LIT_IMPL_SYSTEM::GDBASIS_RIGHT_IRRED)
...@@ -53,8 +55,8 @@ SUBool::init_lit_impl_system(const CNF &cnf, LIT_IMPL_SYSTEM is_kind) ...@@ -53,8 +55,8 @@ SUBool::init_lit_impl_system(const CNF &cnf, LIT_IMPL_SYSTEM is_kind)
} }
void void
SUBool::append_clause_dual_rail(std::vector<LitImpl> &impl, SUBool::append_clause_dual_rail(
const Clause &clause) std::vector<LitImpl> &impl, const Clause &clause)
{ {
if (clause.Empty()) if (clause.Empty())
{ {
...@@ -63,12 +65,12 @@ SUBool::append_clause_dual_rail(std::vector<LitImpl> &impl, ...@@ -63,12 +65,12 @@ SUBool::append_clause_dual_rail(std::vector<LitImpl> &impl,
std::vector<Literal> body(clause.Size() - 1); std::vector<Literal> body(clause.Size() - 1);
for (size_t i = 0; i < clause.Size(); ++i) for (size_t i = 0; i < clause.Size(); ++i)
{ {
if (std::remove_copy(clause.cbegin(), clause.cend(), body.begin(), if (std::remove_copy(
clause[i]) clause.cbegin(), clause.cend(), body.begin(), clause[i])
!= body.end()) != body.end())
{ {
throw BadParameterException("append_clause_dual_rail", throw BadParameterException(
"two equal literals"); "append_clause_dual_rail", "two equal literals");
} }
std::for_each(body.begin(), body.end(), [](auto &lit) { lit.Negate(); }); std::for_each(body.begin(), body.end(), [](auto &lit) { lit.Negate(); });
impl.push_back(LitImpl(body, {clause[i]}, true)); impl.push_back(LitImpl(body, {clause[i]}, true));
...@@ -92,8 +94,8 @@ SUBool::dual_rail(const CNF &cnf, bool merge_bodies) ...@@ -92,8 +94,8 @@ SUBool::dual_rail(const CNF &cnf, bool merge_bodies)
} }
void void
SUBool::append_clauses_of_impl(std::vector<Clause> &clauses, SUBool::append_clauses_of_impl(
const LitImpl &impl) std::vector<Clause> &clauses, const LitImpl &impl)
{ {
LitImpl simple_impl = impl; LitImpl simple_impl = impl;
simple_impl.MakeConsWithoutBody(); simple_impl.MakeConsWithoutBody();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef __DRENC_H #ifndef __DRENC_H