Skip to content

Commit 53cd61d

Browse files
committed
Added MFVS algorithm to evaluator
1 parent fcc6555 commit 53cd61d

6 files changed

Lines changed: 58 additions & 153 deletions

File tree

algorithms/mfvs/mfvs_fact.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace SBG {
3030

3131
namespace LIB {
3232

33-
#define MFVS_FACT MFVSFactory::instance().cv_fact()
33+
#define MFVS_FACT MFVSFactory::instance()
3434

3535
class GreedyMFVSFact {
3636
public:

eval/eval_exec.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
1818
******************************************************************************/
1919

20-
//#include "algorithms/cutvertex/cv_fact.hpp"
21-
//#include "algorithms/cc/cc.hpp"
2220
#include "algorithms/matching/matching_fact.hpp"
21+
#include "algorithms/mfvs/mfvs_fact.hpp"
2322
#include "algorithms/scc/scc_fact.hpp"
2423
//#include "algorithms/toposort/ts_fact.hpp"
2524
#include "eval/eval_exec.hpp"
@@ -56,8 +55,8 @@ void printHeader(Util::prog_opts::variables_map vm)
5655
std::cout << "PWMap implementation: " << LIB::PWMAP_FACT.kind() << "\n";
5756
std::cout << "-----------------------------------\n";
5857
std::cout << "Matching algorithm: " << LIB::MATCH_FACT.kind() << "\n";
59-
std::cout << "SCC algorithm: " << LIB::SCC_FACT.kind() << "\n\n";
60-
//std::cout << "Cut vertex algorithm: " << LIB::CV_FACT.kind() << "\n";
58+
std::cout << "SCC algorithm: " << LIB::SCC_FACT.kind() << "\n";
59+
std::cout << "MFVS algorithm: " << LIB::MFVS_FACT.kind() << "\n\n";
6160
//std::cout << "Topological sort algorithm: " << LIB::TS_FACT.kind()
6261
// << "\n";
6362
}

eval/user_impl_map.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ UserImplMap::StructImplMap sccMap()
9595
return scc_mapping;
9696
}
9797

98+
UserImplMap::StructImplMap mfvsMap()
99+
{
100+
UserImplMap::StructImplMap mfvs_mapping;
101+
mfvs_mapping[0] = LIB::MFVSKind::kGreedy;
102+
mfvs_mapping.freeze();
103+
return mfvs_mapping;
104+
}
105+
98106
// TODO
99107
//UserImplMap::StructImplMap tsMap()
100108
//{
@@ -103,14 +111,6 @@ UserImplMap::StructImplMap sccMap()
103111
// ts_mapping.freeze();
104112
// return ts_mapping;
105113
//}
106-
//
107-
//UserImplMap::StructImplMap cvMap()
108-
//{
109-
// UserImplMap::StructImplMap cv_mapping;
110-
// cv_mapping[0] = []() { return std::make_unique<LIB::MaxDegCVFact>(); };
111-
// cv_mapping.freeze();
112-
// return cv_mapping;
113-
//}
114114

115115
////////////////////////////////////////////////////////////////////////////////
116116
// User Implementation Map -----------------------------------------------------
@@ -122,8 +122,8 @@ UserImplMap::UserImplMap()
122122
implementations_["pwmap"] = pwMap();
123123
implementations_["match"] = matchMap();
124124
implementations_["scc"] = sccMap();
125+
implementations_["mfvs"] = mfvsMap();
125126
//implementations_["ts"] = tsMap();
126-
//implementations_["cv"] = cvMap();
127127
}
128128

129129
Kind UserImplMap::getFactory(std::string strct, int impl)

eval/user_impl_map.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#ifndef SBGRAPH_EVAL_USER_IMPL_MAP_HPP_
3030
#define SBGRAPH_EVAL_USER_IMPL_MAP_HPP_
3131

32-
//#include "algorithms/cutvertex/cv_fact.hpp"
32+
#include "algorithms/mfvs/min_feedback_vertex_set.hpp"
3333
#include "algorithms/matching/matching.hpp"
3434
#include "algorithms/scc/scc.hpp"
3535
//#include "algorithms/toposort/ts_fact.hpp"
@@ -58,7 +58,8 @@ namespace detail {
5858
using Kind = std::variant<LIB::SetKind
5959
, LIB::PWMapKind
6060
, LIB::MatchKind
61-
, LIB::SCCKind>;
61+
, LIB::SCCKind
62+
, LIB::MFVSKind>;
6263

6364
/**
6465
* @brief Mapping for all structures such as Set, PW and algorithms.

eval/visitors/func_evaluator.cpp

Lines changed: 40 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
1818
******************************************************************************/
1919

20+
#include "eval/visitors/func_evaluator.hpp"
2021
#include "algorithms/cc/cc.hpp"
21-
//#include "algorithms/cutvertex/cv_fact.hpp"
22+
#include "algorithms/mfvs/min_feedback_vertex_set.hpp"
23+
#include "algorithms/mfvs/mfvs_fact.hpp"
2224
#include "algorithms/matching/matching_fact.hpp"
2325
#include "algorithms/misc/causalization_builders.hpp"
2426
#include "algorithms/scc/scc_fact.hpp"
2527
//#include "algorithms/toposort/ts_fact.hpp"
2628
#include "eval/base_type.hpp"
27-
#include "eval/visitors/func_evaluator.hpp"
2829
#include "sbg/bipartite_sbg.hpp"
2930
#include "sbg/expression.hpp"
3031
#include "sbg/interval.hpp"
@@ -43,85 +44,6 @@ namespace Eval {
4344

4445
namespace detail {
4546

46-
////////////////////////////////////////////////////////////////////////////////
47-
// Auxiliary functions ---------------------------------------------------------
48-
////////////////////////////////////////////////////////////////////////////////
49-
50-
//TODO
51-
/**
52-
* @brief Returns a new bipartite SBG constructed by copying \p times the
53-
* the current bipartite SBG, disconnected one from each other.
54-
*/
55-
/*
56-
LIB::BipartiteSBG copy(unsigned int times, BipartiteSBG bsbg)
57-
{
58-
Set ith_V = _V;
59-
Set new_V = ith_V;
60-
PWMap ith_Vmap = _Vmap;
61-
PWMap new_Vmap = ith_Vmap;
62-
PWMap ith_map1 = _map1;
63-
PWMap new_map1 = ith_map1;
64-
PWMap ith_map2 = _map2;
65-
PWMap new_map2 = ith_map2;
66-
PWMap ith_Emap = _Emap;
67-
PWMap new_Emap = ith_Emap;
68-
PWMap ith_subE = _subEmap;
69-
PWMap new_subE = ith_subE;
70-
Set ith_X = _X;
71-
Set new_X = ith_X;
72-
Set ith_Y = _Y;
73-
Set new_Y = ith_Y;
74-
75-
if (!ith_V.isEmpty()) {
76-
MD_NAT maxv = ith_V.maxElem();
77-
auto dims = maxv.arity();
78-
MD_NAT maxV
79-
= ith_Vmap.isEmpty() ? MD_NAT(dims, 0) : ith_Vmap.image().maxElem();
80-
MD_NAT maxe = _E.isEmpty() ? MD_NAT(dims, 0) : _E.maxElem();
81-
MD_NAT maxE
82-
= ith_Emap.isEmpty() ? MD_NAT(dims, 0) : ith_Emap.image().maxElem();
83-
84-
Exp off;
85-
for (unsigned int j = 0; j < dims; ++j) {
86-
RATIONAL o = RATIONAL(maxv[j]) - RATIONAL(maxe[j]);
87-
off.emplaceBack(LExp(0, o));
88-
}
89-
90-
for (unsigned int j = 0; j < times; ++j) {
91-
if (j > 0) {
92-
new_V = new_V.disjointCup(ith_V);
93-
new_Vmap = new_Vmap.concatenation(ith_Vmap);
94-
new_map1 = new_map1.concatenation(ith_map1);
95-
new_map2 = new_map2.concatenation(ith_map2);
96-
new_Emap = new_Emap.concatenation(ith_Emap);
97-
new_subE = new_subE.concatenation(ith_subE);
98-
new_X = new_X.disjointCup(ith_X);
99-
new_Y = new_Y.disjointCup(ith_Y);
100-
}
101-
102-
ith_V = ith_V.offset(maxv);
103-
ith_Vmap = ith_Vmap.offsetDom(maxv);
104-
ith_Vmap = ith_Vmap.offsetImage(maxV);
105-
106-
ith_map1 = ith_map1.offsetDom(maxe);
107-
ith_map1 = ith_map1.offsetImage(off);
108-
ith_map2 = ith_map2.offsetDom(maxe);
109-
ith_map2 = ith_map2.offsetImage(off);
110-
ith_Emap = ith_Emap.offsetDom(maxe);
111-
ith_Emap = ith_Emap.offsetImage(maxE);
112-
ith_subE = ith_subE.offsetDom(maxe);
113-
ith_subE = ith_subE.offsetImage(maxE);
114-
115-
ith_X = ith_X.offset(maxv);
116-
ith_Y = ith_Y.offset(maxv);
117-
}
118-
}
119-
120-
return BipartiteSBG{new_V, new_Vmap, new_map1, new_map2, new_Emap, new_subE
121-
, new_X, new_Y};
122-
}
123-
*/
124-
12547
////////////////////////////////////////////////////////////////////////////////
12648
// Built-in operators evaluators -----------------------------------------------
12749
////////////////////////////////////////////////////////////////////////////////
@@ -631,22 +553,6 @@ ExprBaseType BuiltInFunctions::minMapEvaluator(const EBTList& args)
631553
return std::visit(min_map_evaluator, args[0], args[1]);
632554
}
633555

634-
// TODO
635-
//ExprBaseType BuiltInFunctions::reduceEvaluator(const EBTList& args)
636-
//{
637-
// Util::ERROR_UNLESS(args.size() == 1
638-
// , "reduceEvaluator: wrong number of arguments\n");
639-
//
640-
// const auto reduce_evaluator = Util::Overload {
641-
// [](LIB::PWMap a) { return ExprBaseType{a.reduce()}; },
642-
// [](auto a) {
643-
// Util::ERROR("reduceEvaluator: wrong argument ", a, " for reduce\n");
644-
// return ExprBaseType{};
645-
// }
646-
// };
647-
// return std::visit(reduce_evaluator, args[0]);
648-
//}
649-
650556
ExprBaseType BuiltInFunctions::minAdjEvaluator(const EBTList& args)
651557
{
652558
Util::ERROR_UNLESS(args.size() == 2
@@ -751,44 +657,6 @@ ExprBaseType BuiltInFunctions::sccEvaluator(const EBTList& args)
751657
return std::visit(scc_evaluator, args[0]);
752658
}
753659

754-
/*
755-
ExprBaseType BuiltInFunctions::topoSortEvaluator(const EBTList& args)
756-
{
757-
Util::ERROR_UNLESS(args.size() == 1
758-
, "topoSortEvaluator: wrong number of arguments\n");
759-
760-
LIB::TopoSort ts_impl = LIB::TS_FACT.createTSAlgorithm();
761-
const auto ts_evaluator = Util::Overload {
762-
[&ts_impl](LIB::DirectedSBG a) {
763-
return ExprBaseType{ts_impl.calculate(a)};
764-
},
765-
[](auto a) {
766-
Util::ERROR("topoSortEvaluator: wrong argument ", a, " for sort\n");
767-
return ExprBaseType{};
768-
}
769-
};
770-
return std::visit(ts_evaluator, args[0]);
771-
}
772-
773-
ExprBaseType BuiltInFunctions::cutVertexEvaluator(const EBTList& args)
774-
{
775-
Util::ERROR_UNLESS(args.size() == 1
776-
, "cutVertexEvaluator: wrong number of arguments\n");
777-
778-
LIB::CutVertex cv_impl = LIB::CV_FACT.createCVAlgorithm();
779-
const auto cv_evaluator = Util::Overload {
780-
[&cv_impl](LIB::DirectedSBG a) {
781-
return ExprBaseType{cv_impl.calculate(a)};
782-
},
783-
[](auto a) {
784-
Util::ERROR("topoSortEvaluator: wrong argument ", a, " for sort\n");
785-
return ExprBaseType{};
786-
}
787-
};
788-
return std::visit(cv_evaluator, args[0]);
789-
}
790-
*/
791-
792660
ExprBaseType BuiltInFunctions::matchSCCEvaluator(const EBTList& args)
793661
{
794662
Util::ERROR_UNLESS(args.size() == 2
@@ -817,7 +685,44 @@ ExprBaseType BuiltInFunctions::matchSCCEvaluator(const EBTList& args)
817685
return std::visit(match_scc_evaluator, args[0], args[1]);
818686
}
819687

688+
ExprBaseType BuiltInFunctions::mfvsEvaluator(const EBTList& args)
689+
{
690+
Util::ERROR_UNLESS(args.size() == 1
691+
, "mfvsEvaluator: wrong number of arguments\n");
692+
693+
LIB::MinFeedbackVertexSet mfvs_impl = LIB::MFVS_FACT.createMFVSAlgorithm();
694+
const auto mfvs_evaluator = Util::Overload {
695+
[&mfvs_impl](LIB::DirectedSBG a) {
696+
return ExprBaseType{mfvs_impl.calculate(a)};
697+
},
698+
[](auto a) {
699+
Util::ERROR("mfvsEvaluator: wrong type of argument ", a
700+
, " for MFVS algorithm\n");
701+
return ExprBaseType{};
702+
}
703+
};
704+
return std::visit(mfvs_evaluator, args[0]);
705+
}
706+
820707
/*
708+
ExprBaseType BuiltInFunctions::topoSortEvaluator(const EBTList& args)
709+
{
710+
Util::ERROR_UNLESS(args.size() == 1
711+
, "topoSortEvaluator: wrong number of arguments\n");
712+
713+
LIB::TopoSort ts_impl = LIB::TS_FACT.createTSAlgorithm();
714+
const auto ts_evaluator = Util::Overload {
715+
[&ts_impl](LIB::DirectedSBG a) {
716+
return ExprBaseType{ts_impl.calculate(a)};
717+
},
718+
[](auto a) {
719+
Util::ERROR("topoSortEvaluator: wrong argument ", a, " for sort\n");
720+
return ExprBaseType{};
721+
}
722+
};
723+
return std::visit(ts_evaluator, args[0]);
724+
}
725+
821726
ExprBaseType BuiltInFunctions::matchSCCTSEvaluator(const EBTList& args)
822727
{
823728
const auto match_scc_ts_evaluator = Util::Overload {

eval/visitors/func_evaluator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class BuiltInFunctions {
9494
static ExprBaseType connectedEvaluator(const EBTList& args);
9595
static ExprBaseType matchingEvaluator(const EBTList& args);
9696
static ExprBaseType sccEvaluator(const EBTList& args);
97-
static ExprBaseType topoSortEvaluator(const EBTList& args);
98-
static ExprBaseType cutVertexEvaluator(const EBTList& args);
9997
static ExprBaseType matchSCCEvaluator(const EBTList& args);
98+
static ExprBaseType mfvsEvaluator(const EBTList& args);
99+
static ExprBaseType topoSortEvaluator(const EBTList& args);
100100
};
101101

102102
} // namespace detail

0 commit comments

Comments
 (0)