Skip to content

Commit

Permalink
Added minimum reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalashnikovni committed Oct 20, 2023
1 parent 5452b00 commit cf6561d
Show file tree
Hide file tree
Showing 65 changed files with 1,556 additions and 123 deletions.
27 changes: 27 additions & 0 deletions ast/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,33 @@ std::ostream &operator<<(std::ostream &out, const SBG &g)
return out;
}

// DSBG ------------------------------------------------------------------------

DSBG::DSBG() : V_(), Vmap_(), mapB_(), mapD_(), Emap_() {}
DSBG::DSBG(Expr V, Expr Vmap, Expr mapB, Expr mapD, Expr Emap) : V_(V), Vmap_(Vmap), mapB_(mapB), mapD_(mapD), Emap_(Emap) {}

member_imp(DSBG, Expr, V);
member_imp(DSBG, Expr, Vmap);
member_imp(DSBG, Expr, mapB);
member_imp(DSBG, Expr, mapD);
member_imp(DSBG, Expr, Emap);

bool DSBG::operator==(const DSBG &other) const
{
return V() == other.V() && Vmap() == other.Vmap() && mapB() == other.mapB() && mapD() == other.mapD() && Emap() == other.Emap();
}

std::ostream &operator<<(std::ostream &out, const DSBG &g)
{
out << "V = " << g.V() << ";\n";
out << "Vmap = " << g.Vmap() << ";\n\n";
out << "mapB = " << g.mapB() << ";\n";
out << "mapD = " << g.mapD() << ";\n";
out << "Emap = " << g.Emap() << ";\n";

return out;
}

} // namespace AST

} // namespace SBG
20 changes: 19 additions & 1 deletion ast/expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct MDLExpBinOp;
struct LinearMap;
struct PWLMap;
struct SBG;
struct DSBG;

typedef boost::variant<Natural, Rational, MDNatural, Boolean, Util::VariableName,
boost::recursive_wrapper<UnaryOp>,
Expand All @@ -80,7 +81,8 @@ typedef boost::variant<Natural, Rational, MDNatural, Boolean, Util::VariableName
boost::recursive_wrapper<MDLExpBinOp>,
boost::recursive_wrapper<LinearMap>,
boost::recursive_wrapper<PWLMap>,
boost::recursive_wrapper<SBG>> Expr;
boost::recursive_wrapper<SBG>,
boost::recursive_wrapper<DSBG>> Expr;
typedef std::vector<Expr> ExprList;
std::ostream &operator<<(std::ostream &out, const ExprList &el);

Expand Down Expand Up @@ -336,6 +338,22 @@ struct SBG {
};
std::ostream &operator<<(std::ostream &out, const SBG &g);

// DSBG -------------------------------------------------------------------------

struct DSBG {
member_class(Expr, V);
member_class(Expr, Vmap);
member_class(Expr, mapB);
member_class(Expr, mapD);
member_class(Expr, Emap);

DSBG();
DSBG(Expr V, Expr Vmap, Expr mapB, Expr mapD, Expr Emap);

eq_class(DSBG);
};
std::ostream &operator<<(std::ostream &out, const DSBG &g);

} // namespace AST

} // namespace SBG
Expand Down
3 changes: 3 additions & 0 deletions eval/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ EVAL_SRC := \
$(VISIT_DIR)/eval_canon_pwmap.cpp \
$(VISIT_DIR)/eval_base_sbg.cpp \
$(VISIT_DIR)/eval_canon_sbg.cpp \
$(VISIT_DIR)/eval_base_dsbg.cpp \
$(VISIT_DIR)/eval_canon_dsbg.cpp \
$(VISIT_DIR)/eval_map.cpp \
$(VISIT_DIR)/eval_graph.cpp \
$(VISIT_DIR)/eval_expr.cpp \
Expand All @@ -53,6 +55,7 @@ EVAL_SRC := \
$(SBG_DIR)/map.cpp \
$(SBG_DIR)/pw_map.cpp \
$(SBG_DIR)/sbg.cpp \
$(SBG_DIR)/sbg_algorithms.cpp \
$(SBG_DIR)/info.cpp

# Objects
Expand Down
2 changes: 1 addition & 1 deletion eval/defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MaybeVValue VarEnv::operator[](VKey k) const
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}};
{"reduce", 12}, {"minAdj", 13}, {"CC", 14}, {"minReach", 15}};

MaybeFValue FuncEnv::operator[](FKey k) const
{
Expand Down
10 changes: 7 additions & 3 deletions eval/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ typedef std::variant<LIB::BaseMap
, LIB::CanonPWMap> MapBaseType;

typedef std::variant<LIB::BaseSBG
, LIB::CanonSBG> SBGBaseType;
, LIB::CanonSBG
, LIB::BaseDSBG
, LIB::CanonDSBG> SBGBaseType;

typedef boost::variant<Util::NAT
, Util::MD_NAT
Expand All @@ -83,7 +85,9 @@ typedef boost::variant<Util::NAT
, LIB::BasePWMap
, LIB::CanonPWMap
, LIB::BaseSBG
, LIB::CanonSBG> ExprBaseType;
, LIB::CanonSBG
, LIB::BaseDSBG
, LIB::CanonDSBG> ExprBaseType;
typedef std::optional<ExprBaseType> MaybeEBT;

template <typename T>
Expand Down Expand Up @@ -138,7 +142,7 @@ struct FuncEnv{
};

typedef enum { empty, member, min, max, lt, comp, inv, im, preim, dom, comb, min_map, red, min_adj
, connected } Func;
, connected, min_reach } Func;

// Classes for pretty printing ------------------------------------------------

Expand Down
201 changes: 201 additions & 0 deletions eval/visitors/eval_base_dsbg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*******************************************************************************
This file is part of Set--Based Graph Library.
SBG Library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SBG Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SBG Library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "eval/visitors/eval_base_dsbg.hpp"

namespace SBG {

namespace Eval {

EvalBaseDSBG::EvalBaseDSBG() : env_() {}
EvalBaseDSBG::EvalBaseDSBG(VarEnv env) : env_(env) {}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Natural v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a Natural");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MDNatural v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a MDNatural");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Rational v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a Rational");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Boolean v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a Boolean");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(Util::VariableName v) const
{
MaybeEBT v_opt = env_[v];
if (v_opt) {
ExprBaseType value = *v_opt;
if (is<LIB::BaseDSBG>(value))
return boost::get<LIB::BaseDSBG>(value);

else {
Util::ERROR("EvalBaseDSBG: variable %s is not a PWMap", v.c_str());
return LIB::BaseDSBG();
}
}

Util::ERROR("EvalBaseDSBG: variable %s not defined", v.c_str());
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::UnaryOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an arithmetic BinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::BinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an arithmetic BinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Call v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a Call");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Interval v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an Interval");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::InterUnaryOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an InterUnaryOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::InterBinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an InterBinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MultiDimInter v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an MultiDimInter");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MDInterUnaryOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an MDInterUnaryOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MDInterBinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate an MDInterBinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::Set v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a Set");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::SetUnaryOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a SetUnaryOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::SetBinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a SetBinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::LinearExp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a LinearExp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::LExpBinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a LExpBinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MDLExp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a MDLExp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::MDLExpBinOp v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a MDLExpBinOp");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::LinearMap v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a LinearMap");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::PWLMap v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a PWLMap");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::SBG v) const
{
Util::ERROR("EvalBaseDSBG: trying to evaluate a SBG");
return LIB::BaseDSBG();
}

LIB::BaseDSBG EvalBaseDSBG::operator()(AST::DSBG v) const
{
EvalUnordSet visit_set(env_);
EvalBasePWMap visit_pw(env_);

LIB::UnordSet V = Apply(visit_set, v.V());
LIB::BasePWMap Vmap = Apply(visit_pw, v.Vmap());
LIB::BasePWMap mapB = Apply(visit_pw, v.mapB());
LIB::BasePWMap mapD = Apply(visit_pw, v.mapD());
LIB::BasePWMap Emap = Apply(visit_pw, v.Emap());

return LIB::BaseDSBG(V, Vmap, mapB, mapD, Emap);
}

} // namespace Eval

} // namespace SBG
Loading

0 comments on commit cf6561d

Please sign in to comment.