Skip to content

Commit

Permalink
Merge branch 'sb-graph-dev' of https://github.com/CIFASIS/sb-graph in…
Browse files Browse the repository at this point in the history
…to sb-graph-dev
  • Loading branch information
Kalashnikovni committed Jul 2, 2024
2 parents 90d10a4 + 0739a4d commit 73ed0c6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
6 changes: 3 additions & 3 deletions eval/defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ FuncEnv::FuncEnv() {}
FuncEnvType FuncEnv::mapping_ = {
{"isEmpty", 0}, {"isMember", 1}, {"minElem", 2}, {"maxElem", 3}, {"lt", 4}
, {"compose", 5}, {"inv", 6}, {"image", 7}, {"preImage", 8}, {"dom", 9}
, {"combine", 10}, {"minMap", 11}, {"reduce", 12}, {"minAdj", 13}, {"CC", 14}
, {"minReach", 15}, {"matching", 16}, {"scc", 17}, {"sort", 18}
, {"firstInv", 19}, {"matchSCC", 20}, {"matchSCCTS", 21}
, {"combine", 10}, {"firstInv", 11}, {"minMap", 12}, {"reduce", 13}
, {"minAdj", 14}, {"mapInf", 15}, {"CC", 16}, {"matching", 17}, {"scc", 18}
, {"sort", 19}, {"matchSCC", 20}, {"matchSCCTS", 21}
};

MaybeFValue FuncEnv::operator[](FKey k) const
Expand Down
2 changes: 1 addition & 1 deletion eval/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct FuncEnv{
};

typedef enum { empty, member, min, max, lt, comp, inv, im, preim, dom, comb
, min_map, red, min_adj, connected, min_reach, matching, scc, ts, first_inv
, first_inv, min_map, red, min_adj, inf, connected, matching, scc, ts
, match_scc, match_scc_ts } Func;

// Classes for pretty printing ------------------------------------------------
Expand Down
63 changes: 41 additions & 22 deletions eval/visitors/eval_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ auto combine_visitor_ = Util::Overload {
}
};

auto first_inv_visitor_ = Util::Overload {
[](LIB::BasePWMap a) {
return MapBaseType(a.firstInv());
},
[](LIB::CanonPWMap a) {
return MapBaseType(a.firstInv());
},
[](auto a) {
Util::ERROR("Wrong arguments for firstInv");
return MapBaseType();
}
};

auto min_map_visitor2_ = Util::Overload {
[](LIB::BasePWMap a, LIB::BasePWMap b) { return MapBaseType(a.minMap(b)); },
[](LIB::CanonPWMap a, LIB::CanonPWMap b) { return MapBaseType(a.minMap(b)); },
Expand Down Expand Up @@ -236,6 +249,15 @@ auto min_adj_visitor2_ = Util::Overload {
}
};

auto inf_visitor_ = Util::Overload {
[](LIB::BasePWMap a) { return MapBaseType(a.mapInf()); },
[](LIB::CanonPWMap a) { return MapBaseType(a.mapInf()); },
[](auto a, auto b) {
Util::ERROR("Wrong arguments for mapInf");
return MapBaseType();
}
};

auto connected_visitor_ = Util::Overload {
[](LIB::BaseSBG a) { return MapBaseType(connectedComponents(a)); },
[](LIB::CanonSBG a) { return MapBaseType(connectedComponents(a)); },
Expand Down Expand Up @@ -290,19 +312,6 @@ auto ts_visitor_ = Util::Overload {
}
};

auto first_inv_visitor_ = Util::Overload {
[](LIB::BasePWMap a) {
return MapBaseType(a.firstInv());
},
[](LIB::CanonPWMap a) {
return MapBaseType(a.firstInv());
},
[](auto a) {
Util::ERROR("Wrong arguments for firstInv");
return MapBaseType();
}
};

auto match_scc_visitor_ = Util::Overload {
[](LIB::BaseSBG a, Util::MD_NAT b, bool c) {
LIB::BaseMatch match(a.copy(b[0]), c);
Expand Down Expand Up @@ -580,6 +589,15 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
}
break;

case Eval::Func::first_inv:
if (eval_args.size() == 1) {
arity_ok = true;

MapBaseType pw = std::visit(EvalMap(), eval_args[0]);
MapBaseType result = std::visit(first_inv_visitor_, pw);
return result;
}

case Eval::Func::min_map:
if (eval_args.size() == 2) {
arity_ok = true;
Expand Down Expand Up @@ -664,6 +682,16 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
}
break;

case Eval::Func::inf:
if (eval_args.size() == 1) {
arity_ok = true;

MapBaseType map = std::visit(EvalMap{}, eval_args[0]);
MapBaseType result = std::visit(inf_visitor_, map);
return result;
}
break;

case Eval::Func::connected:
if (eval_args.size() == 1) {
arity_ok = true;
Expand Down Expand Up @@ -712,15 +740,6 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const
}
break;

case Eval::Func::first_inv:
if (eval_args.size() == 1) {
arity_ok = true;

MapBaseType pw = std::visit(EvalMap(), eval_args[0]);
MapBaseType result = std::visit(first_inv_visitor_, pw);
return result;
}

case Eval::Func::match_scc:
if (eval_args.size() == 2) {
arity_ok = true;
Expand Down
2 changes: 2 additions & 0 deletions test/pw_map1.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ minMap(<<{[1:1:10], [15:3:30]} -> 1*x+0, {[12:3:12], [50:5:100]} -> 1*x+1>>, <<{
reduce(<<{[100:1:200]} -> 1*x-1>>)

firstInv(<<{[1:1:10]} -> 0*x+10>>)

mapInf(<<{[50:1:50]} -> 1*x-49, {[49:1:49]} -> 1*x-48, {[3:1:48]} -> 1*x+1>>)
2 changes: 1 addition & 1 deletion test/scc2.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SCC test, with a simple long cycle

N = 10000
N = 10

V1 = N
V2 = 1+V1
Expand Down
3 changes: 2 additions & 1 deletion test/scc4.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SCC test, with a simple long cycle
// SCC test, with a long path, and a branch in the middle
// that goes to a minimum value

N = 100
N2 = 50
Expand Down

0 comments on commit 73ed0c6

Please sign in to comment.