Skip to content

Commit

Permalink
New version of topsort
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalashnikovni committed Apr 8, 2024
1 parent 7ec9ccf commit 1a9d2ec
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 440 deletions.
4 changes: 1 addition & 3 deletions eval/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ typedef std::variant<LIB::BaseSBG
, LIB::CanonDSBG> SBGBaseType;

typedef std::variant<LIB::MatchInfo<LIB::UnordSet>
, LIB::MatchInfo<LIB::OrdSet>
, LIB::VertexOrder<LIB::UnordSet>
, LIB::VertexOrder<LIB::OrdSet>> InfoBaseType;
, LIB::MatchInfo<LIB::OrdSet>> InfoBaseType;

typedef std::variant<Util::MD_NAT
, Util::RATIONAL
Expand Down
47 changes: 18 additions & 29 deletions eval/visitors/eval_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,17 @@ auto scc_visitor_ = Util::Overload {
};

auto ts_visitor_ = Util::Overload {
[](LIB::BaseDSBG a, LIB::BasePWMap b, bool c) {
LIB::BaseTopSort ts(a, c);
LIB::BaseVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), b);
std::cout << rec_info << "\n\n";
return InfoBaseType(ts_res);
[](LIB::BaseDSBG a, bool b) {
LIB::BaseTopSort ts(a, b);
return MapBaseType(ts.calculate());
},
[](LIB::CanonDSBG a, LIB::CanonPWMap b, bool c) {
LIB::CanonTopSort ts(a, c);
LIB::CanonVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), b);
std::cout << rec_info << "\n\n";
return InfoBaseType(ts_res);
[](LIB::CanonDSBG a, bool b) {
LIB::CanonTopSort ts(a, b);
return MapBaseType(ts.calculate());
},
[](auto a, auto b, auto c) {
[](auto a, auto b) {
Util::ERROR("Wrong arguments for ts");
return InfoBaseType();
return MapBaseType();
}
};

Expand Down Expand Up @@ -335,27 +329,23 @@ auto match_scc_ts_visitor_ = Util::Overload {
LIB::BaseSCC scc(buildSCCFromMatching(match), d);
LIB::BasePWMap scc_res = scc.calculate();
LIB::BaseTopSort ts(buildSortFromSCC(scc, scc_res), d);
LIB::BaseVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), a.subE_map());
std::cout << rec_info << "\n";
buildJson(match_res, scc.transformResult(scc_res), ts_res);
return InfoBaseType(ts_res);
LIB::BasePWMap ts_res = ts.calculate();
buildJson(match_res, scc.transformResult(scc_res));
return MapBaseType(ts_res);
},
[](LIB::CanonSBG a, Util::MD_NAT b, Util::MD_NAT c, bool d) {
LIB::CanonMatch match(a.copy(b[0]), d);
LIB::OrdSet match_res = match.calculate(c[0]).matched_edges();
LIB::CanonSCC scc(buildSCCFromMatching(match), d);
LIB::CanonPWMap scc_res = scc.calculate();
LIB::CanonTopSort ts(buildSortFromSCC(scc, scc_res), d);
LIB::CanonVO ts_res = ts.calculate();
LIB::RecInfo rec_info = buildRecursionInfo(ts.dsbg(), ts.rec_map(), a.subE_map());
std::cout << rec_info << "\n";
buildJson(match_res, scc.transformResult(scc_res), ts_res);
return InfoBaseType(ts_res);
LIB::CanonPWMap ts_res = ts.calculate();
buildJson(match_res, scc.transformResult(scc_res));
return MapBaseType(ts_res);
},
[](auto a, auto b, auto c, auto d) {
Util::ERROR("Wrong arguments for matching+scc+ts");
return InfoBaseType();
return MapBaseType();
}
};

Expand Down Expand Up @@ -716,9 +706,8 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
arity_ok = true;

SBGBaseType g = std::visit(EvalGraph{}, eval_args[0]);
MapBaseType pw = std::visit(EvalMap(), eval_args[1]);
InfoBaseType result = std::visit(
ts_visitor_, g, pw, std::variant<bool>(debug_)
MapBaseType result = std::visit(
ts_visitor_, g, std::variant<bool>(debug_)
);
return result;
}
Expand Down Expand Up @@ -754,7 +743,7 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
SBGBaseType g = std::visit(EvalGraph{}, eval_args[0]);
NatBaseType copies = std::visit(EvalNatBT{}, eval_args[1]);
NatBaseType k = std::visit(EvalNatBT{}, eval_args[2]);
InfoBaseType result = std::visit(
MapBaseType result = std::visit(
match_scc_ts_visitor_, g, copies, k, std::variant<bool>(debug_)
);
return result;
Expand Down
7 changes: 7 additions & 0 deletions sbg/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ SetPiece image(SetPiece mdi, Exp mdle)
template<typename Set>
SBGMap<Set>::SBGMap() : dom_(Set()), exp_(Exp()) {}
template<typename Set>
SBGMap<Set>::SBGMap(Util::MD_NAT x, Exp exp) : dom_(), exp_() {
SetPiece mdi(x);
compatible(mdi, exp);
dom_ = Set(mdi);
exp_ = exp;
}
template<typename Set>
SBGMap<Set>::SBGMap(Interval i, LExp le) : dom_(), exp_() {
compatible(i, le);
dom_ = Set(SetPiece(i));
Expand Down
1 change: 1 addition & 0 deletions sbg/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct SBGMap {
member_class(Exp, exp);

SBGMap();
SBGMap(Util::MD_NAT x, Exp exp);
SBGMap(Interval i, LExp le);
SBGMap(SetPiece mdi, Exp exp);
SBGMap(Set dom, Exp exp);
Expand Down
6 changes: 4 additions & 2 deletions sbg/ord_pw_mdinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ std::ostream &operator<<(std::ostream &out, const MDInterOrdSet &ii)
// OrdPWMDInter ------------------------------------------------------------------

OrdPWMDInter::OrdPWMDInter() : pieces_() {}
OrdPWMDInter::OrdPWMDInter(Interval i) : pieces_()
{
OrdPWMDInter::OrdPWMDInter(Util::MD_NAT x) : pieces_() {
pieces_.insert(SetPiece(x));
}
OrdPWMDInter::OrdPWMDInter(Interval i) : pieces_() {
if (!i.isEmpty())
pieces_.insert(SetPiece(i));
}
Expand Down
1 change: 1 addition & 0 deletions sbg/ord_pw_mdinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct OrdPWMDInter {
* @brief Constructors don't check if intervals are disjoint (performance).
*/
OrdPWMDInter();
OrdPWMDInter(Util::MD_NAT x);
OrdPWMDInter(Interval i);
OrdPWMDInter(SetPiece mdi);
OrdPWMDInter(MDInterOrdSet container);
Expand Down
Loading

0 comments on commit 1a9d2ec

Please sign in to comment.