Skip to content

Commit 739366f

Browse files
committed
[iss-108]
2 parents 4b1117d + f82cf29 commit 739366f

121 files changed

Lines changed: 5389 additions & 5274 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3rd-party/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ add_custom_target(
2121
)
2222

2323
add_dependencies(sbgraph 3rd-party-libs)
24+
25+
include(FetchContent)
26+
27+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
28+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
29+
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
30+
31+
FetchContent_Declare(
32+
google_benchmark
33+
GIT_REPOSITORY https://github.com/google/benchmark.git
34+
GIT_TAG v1.6.1
35+
)
36+
FetchContent_MakeAvailable(google_benchmark)

algorithms/scc/decreasing_edges_mrv.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,17 @@ LtEdgesMRV::LtEdgesMRV() : dsbg_(), smap_(PW_FACT.createPWMap())
3333

3434
Set LtEdgesMRV::decreasingRepresentative(const PWMap& rmap) const
3535
{
36-
Set result = SET_FACT.createSet();
37-
3836
PWMap mapB = dsbg_.mapB();
3937
PWMap mapD = dsbg_.mapD();
4038

4139
if (mapB.isEmpty() || mapD.isEmpty())
42-
return result;
40+
return SET_FACT.createSet();
4341

4442
PWMap rmapB = rmap.composition(mapB);
4543
PWMap rmapD = rmap.composition(mapD);
4644

47-
unsigned int dims = rmapD.arity();
48-
PWMap offD = rmapD.offsetImage(MD_NAT(dims, 1));
49-
PWMap subt = (offD - rmapB);
50-
SetPiece im(dims, Interval(0, 1, Inf));
51-
Set min_in_mapD = SET_FACT.createSet();
52-
for (unsigned int k = 0; k < dims; ++k) {
53-
im[k] = Interval(0, 1, 0);
54-
if (k > 0)
55-
im[k-1] = Interval(1, 1, 1);
56-
57-
Set kth = subt.preImage(SET_FACT.createSet(im));
58-
min_in_mapD = min_in_mapD.disjointCup(kth);
59-
}
60-
61-
return min_in_mapD;
45+
Set result = rmapD.lessImage(rmapB);
46+
return result;
6247
}
6348

6449
Set LtEdgesMRV::edgesInPaths(const PWMap& smap) const

algorithms/scc/minadj_mrv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ PWMap MinAdjMRV::calculate(const DSBG& dsbg)
5151
rmap = rmap.minMap(new_rmap).combine(rmap);
5252
Util::DEBUG_LOG << "rmap before rec: " << rmap << "\n\n";
5353

54-
Set positive = SET_FACT.createSet(SetPiece(copies, Interval(1, 1, Inf)));
5554
PWMap rec_rmap = PW_FACT.createPWMap();
5655
Vc = V.difference(old_rmap.equalImage(rmap));
5756
if (!Vc.isEmpty()) {
@@ -92,7 +91,7 @@ PWMap MinAdjMRV::calculate(const DSBG& dsbg)
9291
}
9392
PWMap dmapB = dmap.composition(mapB), dmapD = dmap.composition(mapD);
9493
// Get edges where the end is closer to the rep than the beginning
95-
Set not_cycle_edges = (dmapB - dmapD).preImage(positive);
94+
Set not_cycle_edges = dmapD.lessImage(dmapB);
9695
ER = ER.intersection(not_cycle_edges);
9796

9897
// Extend to subset-edge

algorithms/scc/minreach_scc.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ SCCData MinReachSCC::calculate(const DSBG& dsbg)
7070
PWMap rmap = PW_FACT.createPWMap();
7171
Set Ediff = SET_FACT.createSet();
7272
Set oldE = dsbg.E();
73+
Set deleted_edges = SET_FACT.createSet();
7374
do {
7475
oldE = dsbg_.E();
7576
rmap = sccStep();
7677
Ediff = oldE.difference(dsbg_.E());
78+
deleted_edges = deleted_edges.disjointCup(Ediff);
7779
} while (Ediff != SET_FACT.createSet());
7880
rmap = rmap.compact();
7981
auto end = std::chrono::high_resolution_clock::now();
@@ -85,7 +87,7 @@ SCCData MinReachSCC::calculate(const DSBG& dsbg)
8587

8688
Util::DEBUG_LOG << "MinReachSCC result: " << rmap << "\n\n";
8789

88-
return SCCData(dsbg, rmap, Ediff);
90+
return SCCData(dsbg, rmap, deleted_edges);
8991
}
9092

9193
////////////////////////////////////////////////////////////////////////////////
@@ -99,7 +101,7 @@ PWMap MinReachSCCV1::sccStep()
99101
// Calculate MRV
100102
MinAdjMRV mrv;
101103
PWMap new_rmap = mrv.calculate(dsbg_);
102-
Util::DEBUG_LOG << "MinReachSCC new_rmap: " << new_rmap << "\n";
104+
Util::DEBUG_LOG << "MinReachSCCV1 new_rmap: " << new_rmap << "\n";
103105

104106
// Leave edges in the same SCC
105107
PWMap rmapB = new_rmap.composition(dsbg_.mapB());
@@ -126,14 +128,14 @@ PWMap MinReachSCCV2::sccStep()
126128
// Calculate MRV
127129
LtEdgesMRV mrv;
128130
PWMap new_rmap = mrv.calculate(dsbg_);
129-
Util::DEBUG_LOG << "MinReachSCC new_rmap: " << new_rmap << "\n";
131+
Util::DEBUG_LOG << "MinReachSCCV2 new_rmap: " << new_rmap << "\n";
130132

131133
// Leave edges in the same SCC
132134
PWMap rmapB = new_rmap.composition(dsbg_.mapB());
133135
PWMap rmapD = new_rmap.composition(dsbg_.mapD());
134136
Set Esame = rmapB.equalImage(rmapD);
135137
E_ = Esame;
136-
Util::DEBUG_LOG << "MinReachSCCV1 erased edges: "
138+
Util::DEBUG_LOG << "MinReachSCCV2 erased edges: "
137139
<< dsbg_.E().difference(E_) << "\n\n";
138140

139141
// Swap directions

ast/expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ std::ostream &operator<<(std::ostream &out, const Call &c)
437437
out << c.name() << "(";
438438
if (sz > 0) {
439439
unsigned int i = 0;
440-
for (; i < sz - 1; i++)
440+
for (; i < sz - 1; ++i)
441441
out << c.args()[i] << ", ";
442442
out << c.args()[i];
443443
}

eval/eval_exec.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "eval/visitors/autom_impl_visitor.hpp"
3333
#include "parser/file_parser.hpp"
3434
#include "util/debug.hpp"
35+
#include "util/logger.hpp"
3536

3637
namespace SBG {
3738

@@ -64,29 +65,52 @@ void printHeader(Util::prog_opts::variables_map vm)
6465
// Evaluation Executor ---------------------------------------------------------
6566
////////////////////////////////////////////////////////////////////////////////
6667

67-
EvalExecutor::EvalExecutor() : set_impl_(0)
68+
EvalExecutor::EvalExecutor() : scc_impl_(1)
6869
{
6970
config_.add_options()
7071
("set_impl,s", Util::prog_opts::value(&set_impl_),
7172
" Desired set implementation:"
7273
"\n - 0 for unordered sets (default option)"
7374
"\n - 1 for ordered sets"
7475
"\n - 2 for unidimensional ordered dense sets")
76+
("pw_impl,p", Util::prog_opts::value(&pw_impl_),
77+
" Desired PWMap implementation:"
78+
"\n - 0 for unordered PWMaps (default option)"
79+
"\n - 1 for ordered PWMaps"
80+
"\n - 2 for domain ordered PWMaps")
7581
("scc_impl", Util::prog_opts::value(&scc_impl_),
7682
"Desired SCC algorithm implementation:"
77-
"\n - 0 for V1 of minimum reachable SCC (default option)"
78-
"\n - 1 for V2 of minimum reachable SCC");
83+
"\n - 0 for V1 of minimum reachable SCC"
84+
"\n - 1 for V2 of minimum reachable SCC (default option)");
7985

8086
cmd_line_opts_.add(generic_).add(config_).add(hidden_);
8187
cfg_file_opts_.add(config_).add(hidden_);
8288
visible_.add(generic_).add(config_);
8389
}
8490

85-
EvalUserInput EvalExecutor::gatherUserInput()
91+
EvalUserInput EvalExecutor::chooseImplementation()
8692
{
8793
EvalUserInput result;
8894

89-
result.set_set_impl(set_impl_);
95+
AutomImplVisitor autom_impl_visitor;
96+
EvalUserInput autom_impl = autom_impl_visitor.visit(Parser::parseFile(
97+
*input_file_, false));
98+
99+
result.set_set_impl(autom_impl.set_impl());
100+
result.set_pw_impl(autom_impl.pw_impl());
101+
102+
if (set_impl_) {
103+
if (set_impl_ > autom_impl.set_impl())
104+
Util::ERROR("Incompatible set implementation for the SBG input\n");
105+
106+
result.set_set_impl(set_impl_);
107+
}
108+
if (pw_impl_) {
109+
if (pw_impl_ > autom_impl.pw_impl())
110+
Util::ERROR("Incompatible PW implementation for the SBG input\n");
111+
112+
result.set_pw_impl(pw_impl_);
113+
}
90114
result.set_scc_impl(scc_impl_);
91115

92116
return result;
@@ -130,14 +154,12 @@ void EvalExecutor::execute(int arg_count, char* args[])
130154

131155
// Input SBG program file handling -------------------------------------------
132156

133-
if (input_file_) {
134-
AutomImplVisitor autom_impl;
135-
std::streambuf* old_cout_buffer = std::cout.rdbuf();
136-
std::cout.rdbuf(nullptr);
137-
autom_impl.visit(Parser::parseFile(*input_file_));
138-
std::cout.rdbuf(old_cout_buffer);
157+
if (vm.count("debug")) {
158+
Util::SBGLogger::instance().setLevel(Util::LogLevel::Debug);
159+
}
139160

140-
EvalUserInput input = gatherUserInput();
161+
if (input_file_) {
162+
EvalUserInput input = chooseImplementation();
141163
InputTranslator input_translator;
142164
input_translator.translate(input);
143165
ProgramIO eval_result = parseEvalFile(*input_file_);

eval/eval_exec.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class EvalExecutor : public Util::UserInputHandler {
3838
void execute(int arg_count, char* args[]) override;
3939

4040
private:
41-
EvalUserInput gatherUserInput();
41+
EvalUserInput chooseImplementation();
4242

4343
boost::optional<int> set_impl_;
44+
boost::optional<int> pw_impl_;
4445
boost::optional<int> scc_impl_;
4546
};
4647

eval/input_translator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,23 @@ InputTranslator::InputTranslator() {}
3030
void InputTranslator::translate(EvalUserInput& input)
3131
{
3232
EvalUserInput::MaybeInt s = input.set_impl();
33-
if (s) {
33+
EvalUserInput::MaybeInt pw = input.pw_impl();
34+
if (pw && s) {
35+
if (*pw == 2 && *s == 0) {
36+
Util::ERROR("Domain ordered PWMap should be used with an ordered set"
37+
" implementation\n");
38+
}
39+
else {
40+
setSetFactory(*s);
41+
setPWFactory(*pw);
42+
}
43+
}
44+
else if (s) {
3445
setSetFactory(*s);
3546
}
47+
else if (pw) {
48+
setPWFactory(*pw);
49+
}
3650

3751
EvalUserInput::MaybeInt scc = input.scc_impl();
3852
if (scc) {

eval/pretty_print.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ namespace Eval {
3333
template<typename T, typename... Ts>
3434
std::ostream &operator<<(std::ostream &out, const std::variant<T, Ts...> &v);
3535

36-
using StmResult = std::tuple<AST::Name, ExprBaseType>;
37-
std::ostream &operator<<(std::ostream &out, const StmResult &e);
38-
using StmResultList = std::vector<StmResult>;
39-
std::ostream &operator<<(std::ostream &out, const StmResultList &e);
4036
using ExprResult = std::tuple<AST::Expr, ExprBaseType>;
4137
std::ostream &operator<<(std::ostream &out, const ExprResult &e);
4238
using ExprResultList = std::vector<ExprResult>;
4339
std::ostream &operator<<(std::ostream &out, const ExprResultList &ee);
40+
using StmResult = std::tuple<AST::Name, ExprBaseType>;
41+
std::ostream &operator<<(std::ostream &out, const StmResult &s);
42+
using StmResultList = std::vector<StmResult>;
43+
std::ostream &operator<<(std::ostream &out, const StmResultList &ss);
4444

4545
/**
4646
* @brief Class to pretty print a program and its correspondent evaluation.

eval/user_impl_map.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ UserImplMap::StructImplMap pwMap()
6767
UserImplMap::StructImplMap pw_mapping;
6868
pw_mapping[0] = []() { return std::make_unique<LIB::UnordPWMapFact>(); };
6969
pw_mapping[1] = []() { return std::make_unique<LIB::OrdPWMapFact>(); };
70+
pw_mapping[2] = []() { return std::make_unique<LIB::DomOrdPWMapFact>(); };
7071
pw_mapping.freeze();
7172
return pw_mapping;
7273
}

0 commit comments

Comments
 (0)