Skip to content

Commit

Permalink
Renamed MintermizationDomain to BDDDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhruska committed Sep 30, 2023
1 parent 99a20ea commit 8ce5282
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/example06-mintermization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) {

std::vector<mata::IntermediateAut> inter_auts = mata::IntermediateAut::parse_from_mf(parsed);
for (const auto& ia : inter_auts) {
mata::Mintermization<mata::MintermizationDomain> mintermization;
mata::Mintermization<mata::BDDDomain> mintermization;
std::cout << ia << '\n';
if ((ia.is_nfa() || ia.is_afa()) && ia.alphabet_type == mata::IntermediateAut::AlphabetType::BITVECTOR) {
const auto& aut = mintermization.mintermize(ia);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* mintermization-domain.hh -- Mintermization domain for BDD.
* bdd-domain.hh -- Mintermization domain for BDD.
*
* This file is a part of libmata.
*
Expand All @@ -21,40 +21,49 @@
#include "mata/cudd/cuddObj.hh"

namespace mata {
struct MintermizationDomain {
struct BDDDomain {
Cudd bdd_mng; // Manager of BDDs from lib cubdd, it allocates and manages BDDs.
BDD val;

MintermizationDomain() : bdd_mng(0), val(BDD()) {}
BDDDomain() : bdd_mng(0), val(BDD()) {}

MintermizationDomain(Cudd mng) : bdd_mng(mng), val(BDD()) {}
BDDDomain(Cudd mng) : bdd_mng(mng), val(BDD()) {}

MintermizationDomain(Cudd mng, BDD val) : bdd_mng(mng), val(val) {};
BDDDomain(Cudd mng, BDD val) : bdd_mng(mng), val(val) {};

friend MintermizationDomain operator&&(const MintermizationDomain& lhs, const MintermizationDomain &rhs) {
friend BDDDomain operator&&(const BDDDomain& lhs, const BDDDomain &rhs) {
return {lhs.bdd_mng, lhs.val * rhs.val};
}

friend MintermizationDomain operator||(const MintermizationDomain& lhs, const MintermizationDomain &rhs) {
friend BDDDomain operator||(const BDDDomain& lhs, const BDDDomain &rhs) {
return {lhs.bdd_mng, lhs.val + rhs.val};
}

friend MintermizationDomain operator!(const MintermizationDomain &lhs) {
friend BDDDomain operator!(const BDDDomain &lhs) {
return {lhs.bdd_mng, !lhs.val};
}

bool operator==(const MintermizationDomain &rhs) const {
bool operator==(const BDDDomain &rhs) const {
return this->val == rhs.val;
}

bool isFalse() const {
return val.IsZero();
}

MintermizationDomain getTrue() const;
MintermizationDomain getFalse() const;
MintermizationDomain getVar() const;
BDDDomain getTrue() const;
BDDDomain getFalse() const;
BDDDomain getVar() const;
};
}

#endif //LIBMATA_MINTERMIZATION_DOMAIN_HH
namespace std {
template<>
struct hash<struct mata::BDDDomain> {
size_t operator()(const struct mata::BDDDomain &algebra) const noexcept {
return hash<BDD>{}(algebra.val);
}
};
}

#endif //LIBMATA_BDD_DOMAIN_HH
12 changes: 1 addition & 11 deletions include/mata/parser/mintermization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@
#define MATA_MINTERM_HH

#include "inter-aut.hh"
#include "mintermization-domain.hh"

// custom specialization of std::hash can be injected in namespace std
namespace std {
template<>
struct hash<struct mata::MintermizationDomain> {
size_t operator()(const struct mata::MintermizationDomain &algebra) const noexcept {
return hash<BDD>{}(algebra.val);
}
};
}
#include "bdd-domain.hh"

namespace mata {

Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_library(libmata STATIC
"${CMAKE_CURRENT_BINARY_DIR}/config.cc"
inter-aut.cc
mintermization.cc
mintermization-domain.cc
bdd-domain.cc
parser.cc
re2parser.cc
nfa/nfa.cc
Expand All @@ -24,6 +24,8 @@ add_library(libmata STATIC
nfa/builder.cc
)

SET(CMAKE_BUILD_TYPE Debug)

# libmata needs at least c++20
target_compile_features(libmata PUBLIC cxx_std_20)

Expand Down
16 changes: 8 additions & 8 deletions src/mintermization-domain.cc → src/bdd-domain.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* mintermization-domain.cc -- Mintermization domain for BDD.
* bdd-domain.cc -- Mintermization domain for BDD.
*
* This file is a part of libmata.
*
Expand All @@ -14,16 +14,16 @@
* GNU General Public License for more details.
*/

#include "mata/parser/mintermization-domain.hh"
#include "mata/parser/bdd-domain.hh"

struct mata::MintermizationDomain mata::MintermizationDomain::getTrue() const {
return MintermizationDomain(bdd_mng, bdd_mng.bddOne());
struct mata::BDDDomain mata::BDDDomain::getTrue() const {
return BDDDomain(bdd_mng, bdd_mng.bddOne());
}

struct mata::MintermizationDomain mata::MintermizationDomain::getFalse() const {
return MintermizationDomain(bdd_mng, bdd_mng.bddZero());
struct mata::BDDDomain mata::BDDDomain::getFalse() const {
return BDDDomain(bdd_mng, bdd_mng.bddZero());
}

struct mata::MintermizationDomain mata::MintermizationDomain::getVar() const {
return MintermizationDomain(bdd_mng, bdd_mng.bddVar());
struct mata::BDDDomain mata::BDDDomain::getVar() const {
return BDDDomain(bdd_mng, bdd_mng.bddVar());
}
2 changes: 0 additions & 2 deletions src/mintermization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#include <vector>

using MintermizationDomain = struct mata::MintermizationDomain;

namespace {
const mata::FormulaGraph* detect_state_part(const mata::FormulaGraph* node)
{
Expand Down
4 changes: 2 additions & 2 deletions tests-integration/src/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int load_automaton(
if (!mintermize_automata or inter_auts[0].alphabet_type != mata::IntermediateAut::AlphabetType::BITVECTOR) {
aut = mata::nfa::builder::construct(inter_auts[0], &alphabet);
} else {
mata::Mintermization<mata::MintermizationDomain> mintermization;
mata::Mintermization<mata::BDDDomain> mintermization;
TIME_BEGIN(mintermization);
mata::IntermediateAut mintermized = mintermization.mintermize(inter_auts[0]);
TIME_END(mintermization);
Expand Down Expand Up @@ -57,7 +57,7 @@ int load_automata(
auts.push_back(mata::nfa::builder::construct(inter_aut, &alphabet));
}
} else {
mata::Mintermization<mata::MintermizationDomain> mintermization;
mata::Mintermization<mata::BDDDomain> mintermization;
TIME_BEGIN(mintermization);
std::vector<mata::IntermediateAut> mintermized = mintermization.mintermize(inter_auts);
TIME_END(mintermization);
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ add_executable(tests
strings/nfa-string-solving.cc
)

SET(CMAKE_BUILD_TYPE Debug)

target_link_libraries(tests PRIVATE libmata Catch2::Catch2)

# Add common compile warnings.
Expand Down
20 changes: 10 additions & 10 deletions tests/mintermization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

#include "mata/parser/inter-aut.hh"
#include "mata/parser/mintermization.hh"
#include "mata/parser/mintermization-domain.hh"
#include "mata/parser/bdd-domain.hh"

using namespace mata::parser;

TEST_CASE("Mata::Mintermization::trans_to_vars_nfa")
{
Parsed parsed;
mata::Mintermization<mata::MintermizationDomain> mintermization{};
mata::Mintermization<mata::BDDDomain> mintermization{};

SECTION("Empty trans")
{
Expand All @@ -43,7 +43,7 @@ TEST_CASE("Mata::Mintermization::trans_to_vars_nfa")
const auto& aut= auts[0];
REQUIRE(aut.transitions[0].first.is_operand());
REQUIRE(aut.transitions[0].second.children[0].node.is_operand());
const mata::MintermizationDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
const mata::BDDDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
REQUIRE(alg.val.nodeCount() == 2);
}

Expand All @@ -62,7 +62,7 @@ TEST_CASE("Mata::Mintermization::trans_to_vars_nfa")
const auto& aut= auts[0];
REQUIRE(aut.transitions[0].second.children[0].node.is_operator());
REQUIRE(aut.transitions[0].second.children[1].node.is_operand());
const mata::MintermizationDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
const mata::BDDDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
REQUIRE(alg.val.nodeCount() == 3);
}

Expand All @@ -81,7 +81,7 @@ TEST_CASE("Mata::Mintermization::trans_to_vars_nfa")
const auto& aut= auts[0];
REQUIRE(aut.transitions[0].second.children[0].node.is_operator());
REQUIRE(aut.transitions[0].second.children[1].node.is_operand());
const mata::MintermizationDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
const mata::BDDDomain alg = mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]);
REQUIRE(alg.val.nodeCount() == 4);
int inputs[] = {0,0,0,0};
REQUIRE(alg.val.Eval(inputs).IsOne());
Expand All @@ -93,7 +93,7 @@ TEST_CASE("Mata::Mintermization::trans_to_vars_nfa")
TEST_CASE("mata::Mintermization::compute_minterms")
{
Parsed parsed;
mata::Mintermization<mata::MintermizationDomain> mintermization{};
mata::Mintermization<mata::BDDDomain> mintermization{};

SECTION("Minterm from trans no elimination")
{
Expand All @@ -111,7 +111,7 @@ TEST_CASE("mata::Mintermization::compute_minterms")
const auto& aut= auts[0];
REQUIRE(aut.transitions[0].second.children[0].node.is_operator());
REQUIRE(aut.transitions[0].second.children[1].node.is_operand());
std::unordered_set<mata::MintermizationDomain> vars;
std::unordered_set<mata::BDDDomain> vars;
vars.insert(mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]));
vars.insert(mintermization.graph_to_vars_nfa(aut.transitions[1].second.children[0]));
auto res = mintermization.compute_minterms(vars);
Expand All @@ -134,7 +134,7 @@ TEST_CASE("mata::Mintermization::compute_minterms")
const auto& aut= auts[0];
REQUIRE(aut.transitions[0].second.children[0].node.is_operator());
REQUIRE(aut.transitions[0].second.children[1].node.is_operand());
std::unordered_set<struct mata::MintermizationDomain> vars;
std::unordered_set<struct mata::BDDDomain> vars;
vars.insert(mintermization.graph_to_vars_nfa(aut.transitions[0].second.children[0]));
vars.insert(mintermization.graph_to_vars_nfa(aut.transitions[1].second.children[0]));
auto res = mintermization.compute_minterms(vars);
Expand All @@ -144,7 +144,7 @@ TEST_CASE("mata::Mintermization::compute_minterms")

TEST_CASE("mata::Mintermization::mintermization") {
Parsed parsed;
mata::Mintermization<mata::MintermizationDomain> mintermization{};
mata::Mintermization<mata::BDDDomain> mintermization{};

SECTION("Mintermization small") {
std::string file =
Expand Down Expand Up @@ -202,7 +202,7 @@ TEST_CASE("mata::Mintermization::mintermization") {

SECTION("Mintermization NFA multiple") {
Parsed parsed;
mata::Mintermization<mata::MintermizationDomain> mintermization{};
mata::Mintermization<mata::BDDDomain> mintermization{};

std::string file =
"@NFA-bits\n"
Expand Down

0 comments on commit 8ce5282

Please sign in to comment.