diff --git a/ast/expr.cpp b/ast/expr.cpp index 97041bc..90d8d1e 100755 --- a/ast/expr.cpp +++ b/ast/expr.cpp @@ -69,7 +69,7 @@ std::ostream &operator<<(std::ostream &out, const Op &op) std::ostream &operator<<(std::ostream &out, const ExprList &el) { - BOOST_FOREACH (Expr e, el) + for (Expr e : el) out << e << "\n"; return out; diff --git a/ast/expr.hpp b/ast/expr.hpp index 394a6ef..2340539 100755 --- a/ast/expr.hpp +++ b/ast/expr.hpp @@ -24,7 +24,6 @@ #ifndef PARSER_EXPR_AST_HPP #define PARSER_EXPR_AST_HPP -#include #include #include diff --git a/ast/statement.cpp b/ast/statement.cpp index c152279..1ed94bc 100755 --- a/ast/statement.cpp +++ b/ast/statement.cpp @@ -59,7 +59,7 @@ bool IsConfig::operator()(ConfigDims v) const { return true; } std::ostream &operator<<(std::ostream &out, const StatementList &stml) { - BOOST_FOREACH (Statement s, stml) + for (Statement s : stml) out << s << "\n"; return out; diff --git a/eval/Makefile.include b/eval/Makefile.include index 274ef7f..2c7fe5a 100755 --- a/eval/Makefile.include +++ b/eval/Makefile.include @@ -11,7 +11,7 @@ EVAL := bin/sbg-eval all: $(EVAL) EVAL_SRC := \ - $(EVAL_DIR)/main.cpp \ + $(EVAL_DIR)/main.cpp \ $(EVAL_DIR)/defs.cpp \ $(UTIL_DIR)/debug.cpp \ $(UTIL_DIR)/defs.cpp \ @@ -23,25 +23,15 @@ EVAL_SRC := \ $(PARSER_DIR)/statement.cpp \ $(PARSER_DIR)/sbg_program.cpp \ $(VISIT_DIR)/eval_nat.cpp \ - $(VISIT_DIR)/eval_natbt.cpp \ + $(VISIT_DIR)/eval_mdnat.cpp \ $(VISIT_DIR)/eval_rat.cpp \ $(VISIT_DIR)/eval_interval.cpp \ $(VISIT_DIR)/eval_mdi.cpp \ - $(VISIT_DIR)/eval_unord_set.cpp \ - $(VISIT_DIR)/eval_ord_set.cpp \ - $(VISIT_DIR)/eval_container.cpp \ + $(VISIT_DIR)/eval_set.cpp \ $(VISIT_DIR)/eval_le.cpp \ $(VISIT_DIR)/eval_mdle.cpp \ - $(VISIT_DIR)/eval_linear.cpp \ - $(VISIT_DIR)/eval_base_map.cpp \ - $(VISIT_DIR)/eval_canon_map.cpp \ - $(VISIT_DIR)/eval_base_pwmap.cpp \ - $(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_pwmap.cpp \ $(VISIT_DIR)/eval_graph.cpp \ $(VISIT_DIR)/eval_expr.cpp \ $(VISIT_DIR)/stm_visitor.cpp \ @@ -50,13 +40,13 @@ EVAL_SRC := \ $(SBG_DIR)/multidim_inter.cpp \ $(SBG_DIR)/unord_pw_mdinter.cpp \ $(SBG_DIR)/ord_pw_mdinter.cpp \ + $(SBG_DIR)/set.cpp \ $(SBG_DIR)/lexp.cpp \ $(SBG_DIR)/multidim_lexp.cpp \ $(SBG_DIR)/map.cpp \ $(SBG_DIR)/pw_map.cpp \ $(SBG_DIR)/sbg.cpp \ - $(SBG_DIR)/sbg_algorithms.cpp \ - $(SBG_DIR)/info.cpp + $(SBG_DIR)/sbg_algorithms.cpp # Objects EVAL_OBJ=$(addprefix $(BUILD_DIR)/, $(EVAL_SRC:.cpp=.o)) diff --git a/eval/defs.cpp b/eval/defs.cpp index 529ce9e..69f852e 100755 --- a/eval/defs.cpp +++ b/eval/defs.cpp @@ -82,7 +82,7 @@ std::ostream &operator<<(std::ostream &out, const ExprEval &e) std::ostream &operator<<(std::ostream &out, const ExprEvalList &ee) { - BOOST_FOREACH (ExprEval e, ee) out << e << "\n"; + for (ExprEval e : ee) out << e << "\n"; return out; } diff --git a/eval/defs.hpp b/eval/defs.hpp index 0b02a93..b9fc286 100755 --- a/eval/defs.hpp +++ b/eval/defs.hpp @@ -33,8 +33,6 @@ #include "ast/expr.hpp" #include "ast/statement.hpp" -#include "sbg/unord_pw_mdinter.hpp" -#include "sbg/ord_pw_mdinter.hpp" #include "sbg/sbg.hpp" namespace SBG { @@ -43,51 +41,18 @@ namespace Eval { // Type definitions ------------------------------------------------------------ -/** @brief Types NatBaseType, ContainerBaseType, LinearBaseType and MapBaseType - * are defined to decrease the compilation memory consumption of eval_expr.cpp. - * When evaluating an AST::Call, multiple std::visit are invoked, where each - * one generates a function table with size dependent of the number types in - * the variant. Initially ExprBaseType was used. - */ - -typedef std::variant NatBaseType; - -typedef std::variant ContainerBaseType; - -typedef std::variant LinearBaseType; - -typedef std::variant MapBaseType; - -typedef std::variant SBGBaseType; - typedef boost::variant ExprBaseType; + , LIB::SBGMap + , LIB::PWMap + , LIB::SBGraph + , LIB::DSBGraph> ExprBaseType; typedef std::optional MaybeEBT; template diff --git a/eval/visitors/eval_base_dsbg.cpp b/eval/visitors/eval_base_dsbg.cpp deleted file mode 100755 index 68f9dc7..0000000 --- a/eval/visitors/eval_base_dsbg.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#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(value)) - return boost::get(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 diff --git a/eval/visitors/eval_base_dsbg.hpp b/eval/visitors/eval_base_dsbg.hpp deleted file mode 100755 index 6f9e6bf..0000000 --- a/eval/visitors/eval_base_dsbg.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_base_dsbg.hpp - - @brief Base DSBG expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_BASE_DSBG -#define AST_VISITOR_EVAL_BASE_DSBG - -#include "eval/visitors/eval_base_pwmap.hpp" -#include "sbg/sbg.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalBaseDSBG : public boost::static_visitor { - public: - EvalBaseDSBG(); - EvalBaseDSBG(VarEnv env); - - LIB::BaseDSBG operator()(AST::Natural v) const; - LIB::BaseDSBG operator()(AST::MDNatural v) const; - LIB::BaseDSBG operator()(AST::Rational v) const; - LIB::BaseDSBG operator()(AST::Boolean v) const; - LIB::BaseDSBG operator()(Util::VariableName v) const; - LIB::BaseDSBG operator()(AST::UnaryOp v) const; - LIB::BaseDSBG operator()(AST::BinOp v) const; - LIB::BaseDSBG operator()(AST::Call v) const; - LIB::BaseDSBG operator()(AST::Interval v) const; - LIB::BaseDSBG operator()(AST::InterUnaryOp v) const; - LIB::BaseDSBG operator()(AST::InterBinOp v) const; - LIB::BaseDSBG operator()(AST::MultiDimInter v) const; - LIB::BaseDSBG operator()(AST::MDInterUnaryOp v) const; - LIB::BaseDSBG operator()(AST::MDInterBinOp v) const; - LIB::BaseDSBG operator()(AST::Set v) const; - LIB::BaseDSBG operator()(AST::SetUnaryOp v) const; - LIB::BaseDSBG operator()(AST::SetBinOp v) const; - LIB::BaseDSBG operator()(AST::LinearExp v) const; - LIB::BaseDSBG operator()(AST::LExpBinOp v) const; - LIB::BaseDSBG operator()(AST::MDLExp v) const; - LIB::BaseDSBG operator()(AST::MDLExpBinOp v) const; - LIB::BaseDSBG operator()(AST::LinearMap v) const; - LIB::BaseDSBG operator()(AST::PWLMap v) const; - LIB::BaseDSBG operator()(AST::SBG v) const; - LIB::BaseDSBG operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_base_map.cpp b/eval/visitors/eval_base_map.cpp deleted file mode 100755 index bc72fdf..0000000 --- a/eval/visitors/eval_base_map.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_base_map.hpp" - -namespace SBG { - -namespace Eval { - -EvalBaseMap::EvalBaseMap() : env_() {} -EvalBaseMap::EvalBaseMap(VarEnv env) : env_(env) {} - -LIB::BaseMap EvalBaseMap::operator()(AST::Natural v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a Natural"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a MDNatural"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::Rational v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a Rational"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a Boolean"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalBaseMap: variable %s is not a linear expression", v.c_str()); - return LIB::BaseMap(); - } - } - - Util::ERROR("EvalBaseMap: variable %s not defined", v.c_str()); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an arithmetic UnaryOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an arithmetic BinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::Call v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a Call"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::Interval v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an Interval"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an InterUnaryOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an InterBinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an MultiDimInter"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an MDInterUnaryOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate an MDInterBinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::Set v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a Set"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a SetUnaryOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a SetBinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a LinearExp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a LExpBinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MDLExp le) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a MDLExp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a MDLExpBinOp"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::LinearMap v) const -{ - EvalUnordSet visit_set(env_); - EvalMDLE visit_mdle(env_); - - return LIB::BaseMap(Apply(visit_set, v.dom()), Apply(visit_mdle, v.lexp())); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a PWLMap"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::SBG v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a SBG"); - return LIB::BaseMap(); -} - -LIB::BaseMap EvalBaseMap::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalBaseMap: trying to evaluate a DSBG"); - return LIB::BaseMap(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_base_map.hpp b/eval/visitors/eval_base_map.hpp deleted file mode 100755 index 353be20..0000000 --- a/eval/visitors/eval_base_map.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/** @file eval_base_map.hpp - - @brief Linear base map expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_BASE_MAP -#define AST_VISITOR_EVAL_BASE_MAP - -#include "eval/visitors/eval_mdle.hpp" -#include "eval/visitors/eval_unord_set.hpp" -#include "sbg/map.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalBaseMap : public boost::static_visitor { - public: - EvalBaseMap(); - EvalBaseMap(VarEnv env); - - LIB::BaseMap operator()(AST::Natural v) const; - LIB::BaseMap operator()(AST::MDNatural v) const; - LIB::BaseMap operator()(AST::Rational v) const; - LIB::BaseMap operator()(AST::Boolean v) const; - LIB::BaseMap operator()(Util::VariableName v) const; - LIB::BaseMap operator()(AST::UnaryOp v) const; - LIB::BaseMap operator()(AST::BinOp v) const; - LIB::BaseMap operator()(AST::Call v) const; - LIB::BaseMap operator()(AST::Interval v) const; - LIB::BaseMap operator()(AST::InterUnaryOp v) const; - LIB::BaseMap operator()(AST::InterBinOp v) const; - LIB::BaseMap operator()(AST::MultiDimInter v) const; - LIB::BaseMap operator()(AST::MDInterUnaryOp v) const; - LIB::BaseMap operator()(AST::MDInterBinOp v) const; - LIB::BaseMap operator()(AST::Set v) const; - LIB::BaseMap operator()(AST::SetUnaryOp v) const; - LIB::BaseMap operator()(AST::SetBinOp v) const; - LIB::BaseMap operator()(AST::LinearExp v) const; - LIB::BaseMap operator()(AST::LExpBinOp v) const; - LIB::BaseMap operator()(AST::MDLExp v) const; - LIB::BaseMap operator()(AST::MDLExpBinOp v) const; - LIB::BaseMap operator()(AST::LinearMap v) const; - LIB::BaseMap operator()(AST::PWLMap v) const; - LIB::BaseMap operator()(AST::SBG v) const; - LIB::BaseMap operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_base_pwmap.cpp b/eval/visitors/eval_base_pwmap.cpp deleted file mode 100755 index 6a13daa..0000000 --- a/eval/visitors/eval_base_pwmap.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_base_pwmap.hpp" - -namespace SBG { - -namespace Eval { - -EvalBasePWMap::EvalBasePWMap() : env_() {} -EvalBasePWMap::EvalBasePWMap(VarEnv env) : env_(env) {} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Natural v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a Natural"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a MDNatural"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Rational v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a Rational"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a Boolean"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalBasePWMap: variable %s is not a PWMap", v.c_str()); - return LIB::BasePWMap(); - } - } - - Util::ERROR("EvalBasePWMap: variable %s not defined", v.c_str()); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an arithmetic BinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an arithmetic BinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Call v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a Call"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Interval v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an Interval"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an InterUnaryOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an InterBinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an MultiDimInter"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an MDInterUnaryOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate an MDInterBinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::Set v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a Set"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a SetUnaryOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a SetBinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a LinearExp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a LExpBinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a MDLExp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a MDLExpBinOp"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a LinearMap"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::PWLMap v) const -{ - LIB::BasePWMap res; - - EvalBaseMap visit_map(env_); - BOOST_FOREACH (AST::Expr e, v.maps()) - res.emplace(Apply(visit_map, e)); - - return LIB::BasePWMap(res); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::SBG v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a SBG"); - return LIB::BasePWMap(); -} - -LIB::BasePWMap EvalBasePWMap::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalBasePWMap: trying to evaluate a DSBG"); - return LIB::BasePWMap(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_base_pwmap.hpp b/eval/visitors/eval_base_pwmap.hpp deleted file mode 100755 index 23ee128..0000000 --- a/eval/visitors/eval_base_pwmap.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_base_pwmap.hpp - - @brief Base piecewise linear map expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_BASE_PWMAP -#define AST_VISITOR_EVAL_BASE_PWMAP - -#include "eval/visitors/eval_base_map.hpp" -#include "sbg/pw_map.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalBasePWMap : public boost::static_visitor { - public: - EvalBasePWMap(); - EvalBasePWMap(VarEnv env); - - LIB::BasePWMap operator()(AST::Natural v) const; - LIB::BasePWMap operator()(AST::MDNatural v) const; - LIB::BasePWMap operator()(AST::Rational v) const; - LIB::BasePWMap operator()(AST::Boolean v) const; - LIB::BasePWMap operator()(Util::VariableName v) const; - LIB::BasePWMap operator()(AST::UnaryOp v) const; - LIB::BasePWMap operator()(AST::BinOp v) const; - LIB::BasePWMap operator()(AST::Call v) const; - LIB::BasePWMap operator()(AST::Interval v) const; - LIB::BasePWMap operator()(AST::InterUnaryOp v) const; - LIB::BasePWMap operator()(AST::InterBinOp v) const; - LIB::BasePWMap operator()(AST::MultiDimInter v) const; - LIB::BasePWMap operator()(AST::MDInterUnaryOp v) const; - LIB::BasePWMap operator()(AST::MDInterBinOp v) const; - LIB::BasePWMap operator()(AST::Set v) const; - LIB::BasePWMap operator()(AST::SetUnaryOp v) const; - LIB::BasePWMap operator()(AST::SetBinOp v) const; - LIB::BasePWMap operator()(AST::LinearExp v) const; - LIB::BasePWMap operator()(AST::LExpBinOp v) const; - LIB::BasePWMap operator()(AST::MDLExp v) const; - LIB::BasePWMap operator()(AST::MDLExpBinOp v) const; - LIB::BasePWMap operator()(AST::LinearMap v) const; - LIB::BasePWMap operator()(AST::PWLMap v) const; - LIB::BasePWMap operator()(AST::SBG v) const; - LIB::BasePWMap operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_base_sbg.cpp b/eval/visitors/eval_base_sbg.cpp deleted file mode 100755 index b23f8eb..0000000 --- a/eval/visitors/eval_base_sbg.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_base_sbg.hpp" - -namespace SBG { - -namespace Eval { - -EvalBaseSBG::EvalBaseSBG() : env_() {} -EvalBaseSBG::EvalBaseSBG(VarEnv env) : env_(env) {} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Natural v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a Natural"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a MDNatural"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Rational v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a Rational"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a Boolean"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalBaseSBG: variable %s is not a PWMap", v.c_str()); - return LIB::BaseSBG(); - } - } - - Util::ERROR("EvalBaseSBG: variable %s not defined", v.c_str()); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an arithmetic BinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an arithmetic BinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Call v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a Call"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Interval v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an Interval"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an InterUnaryOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an InterBinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an MultiDimInter"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an MDInterUnaryOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate an MDInterBinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::Set v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a Set"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a SetUnaryOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a SetBinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a LinearExp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a LExpBinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a MDLExp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a MDLExpBinOp"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a LinearMap"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a PWLMap"); - return LIB::BaseSBG(); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::SBG 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 map1 = Apply(visit_pw, v.map1()); - LIB::BasePWMap map2 = Apply(visit_pw, v.map2()); - LIB::BasePWMap Emap = Apply(visit_pw, v.Emap()); - - return LIB::BaseSBG(V, Vmap, map1, map2, Emap); -} - -LIB::BaseSBG EvalBaseSBG::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalBaseSBG: trying to evaluate a DSBG"); - return LIB::BaseSBG(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_base_sbg.hpp b/eval/visitors/eval_base_sbg.hpp deleted file mode 100755 index eb6c6eb..0000000 --- a/eval/visitors/eval_base_sbg.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_base_sbg.hpp - - @brief Base SBG expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_BASE_SBG -#define AST_VISITOR_EVAL_BASE_SBG - -#include "eval/visitors/eval_base_pwmap.hpp" -#include "sbg/sbg.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalBaseSBG : public boost::static_visitor { - public: - EvalBaseSBG(); - EvalBaseSBG(VarEnv env); - - LIB::BaseSBG operator()(AST::Natural v) const; - LIB::BaseSBG operator()(AST::MDNatural v) const; - LIB::BaseSBG operator()(AST::Rational v) const; - LIB::BaseSBG operator()(AST::Boolean v) const; - LIB::BaseSBG operator()(Util::VariableName v) const; - LIB::BaseSBG operator()(AST::UnaryOp v) const; - LIB::BaseSBG operator()(AST::BinOp v) const; - LIB::BaseSBG operator()(AST::Call v) const; - LIB::BaseSBG operator()(AST::Interval v) const; - LIB::BaseSBG operator()(AST::InterUnaryOp v) const; - LIB::BaseSBG operator()(AST::InterBinOp v) const; - LIB::BaseSBG operator()(AST::MultiDimInter v) const; - LIB::BaseSBG operator()(AST::MDInterUnaryOp v) const; - LIB::BaseSBG operator()(AST::MDInterBinOp v) const; - LIB::BaseSBG operator()(AST::Set v) const; - LIB::BaseSBG operator()(AST::SetUnaryOp v) const; - LIB::BaseSBG operator()(AST::SetBinOp v) const; - LIB::BaseSBG operator()(AST::LinearExp v) const; - LIB::BaseSBG operator()(AST::LExpBinOp v) const; - LIB::BaseSBG operator()(AST::MDLExp v) const; - LIB::BaseSBG operator()(AST::MDLExpBinOp v) const; - LIB::BaseSBG operator()(AST::LinearMap v) const; - LIB::BaseSBG operator()(AST::PWLMap v) const; - LIB::BaseSBG operator()(AST::SBG v) const; - LIB::BaseSBG operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_canon_dsbg.cpp b/eval/visitors/eval_canon_dsbg.cpp deleted file mode 100755 index 3c24bdd..0000000 --- a/eval/visitors/eval_canon_dsbg.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_canon_dsbg.hpp" - -namespace SBG { - -namespace Eval { - -EvalCanonDSBG::EvalCanonDSBG() : env_() {} -EvalCanonDSBG::EvalCanonDSBG(VarEnv env) : env_(env) {} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Natural v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a Natural"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a MDNatural"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Rational v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a Rational"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a Boolean"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalCanonDSBG: variable %s is not a PWMap", v.c_str()); - return LIB::CanonDSBG(); - } - } - - Util::ERROR("EvalCanonDSBG: variable %s not defined", v.c_str()); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an arithmetic BinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an arithmetic BinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Call v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a Call"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Interval v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an Interval"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an InterUnaryOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an InterBinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an MultiDimInter"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an MDInterUnaryOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate an MDInterBinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::Set v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a Set"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a SetUnaryOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a SetBinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a LinearExp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a LExpBinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a MDLExp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a MDLExpBinOp"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a LinearMap"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a PWLMap"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::SBG v) const -{ - Util::ERROR("EvalCanonDSBG: trying to evaluate a SBG"); - return LIB::CanonDSBG(); -} - -LIB::CanonDSBG EvalCanonDSBG::operator()(AST::DSBG v) const -{ - EvalOrdSet visit_set(env_); - EvalCanonPWMap visit_pw(env_); - - LIB::OrdSet V = Apply(visit_set, v.V()); - LIB::CanonPWMap Vmap = Apply(visit_pw, v.Vmap()); - LIB::CanonPWMap mapB = Apply(visit_pw, v.mapB()); - LIB::CanonPWMap mapD = Apply(visit_pw, v.mapD()); - LIB::CanonPWMap Emap = Apply(visit_pw, v.Emap()); - - return LIB::CanonDSBG(V, Vmap, mapB, mapD, Emap); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_canon_dsbg.hpp b/eval/visitors/eval_canon_dsbg.hpp deleted file mode 100755 index 3b09d1c..0000000 --- a/eval/visitors/eval_canon_dsbg.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_canon_dsbg.hpp - - @brief Canon DSBG expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_CANON_DSBG -#define AST_VISITOR_EVAL_CANON_DSBG - -#include "eval/visitors/eval_canon_pwmap.hpp" -#include "sbg/sbg.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalCanonDSBG : public boost::static_visitor { - public: - EvalCanonDSBG(); - EvalCanonDSBG(VarEnv env); - - LIB::CanonDSBG operator()(AST::Natural v) const; - LIB::CanonDSBG operator()(AST::MDNatural v) const; - LIB::CanonDSBG operator()(AST::Rational v) const; - LIB::CanonDSBG operator()(AST::Boolean v) const; - LIB::CanonDSBG operator()(Util::VariableName v) const; - LIB::CanonDSBG operator()(AST::UnaryOp v) const; - LIB::CanonDSBG operator()(AST::BinOp v) const; - LIB::CanonDSBG operator()(AST::Call v) const; - LIB::CanonDSBG operator()(AST::Interval v) const; - LIB::CanonDSBG operator()(AST::InterUnaryOp v) const; - LIB::CanonDSBG operator()(AST::InterBinOp v) const; - LIB::CanonDSBG operator()(AST::MultiDimInter v) const; - LIB::CanonDSBG operator()(AST::MDInterUnaryOp v) const; - LIB::CanonDSBG operator()(AST::MDInterBinOp v) const; - LIB::CanonDSBG operator()(AST::Set v) const; - LIB::CanonDSBG operator()(AST::SetUnaryOp v) const; - LIB::CanonDSBG operator()(AST::SetBinOp v) const; - LIB::CanonDSBG operator()(AST::LinearExp v) const; - LIB::CanonDSBG operator()(AST::LExpBinOp v) const; - LIB::CanonDSBG operator()(AST::MDLExp v) const; - LIB::CanonDSBG operator()(AST::MDLExpBinOp v) const; - LIB::CanonDSBG operator()(AST::LinearMap v) const; - LIB::CanonDSBG operator()(AST::PWLMap v) const; - LIB::CanonDSBG operator()(AST::SBG v) const; - LIB::CanonDSBG operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_canon_map.cpp b/eval/visitors/eval_canon_map.cpp deleted file mode 100755 index 2b8d259..0000000 --- a/eval/visitors/eval_canon_map.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_canon_map.hpp" - -namespace SBG { - -namespace Eval { - -EvalCanonMap::EvalCanonMap() : env_() {} -EvalCanonMap::EvalCanonMap(VarEnv env) : env_(env) {} - -LIB::CanonMap EvalCanonMap::operator()(AST::Natural v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a Natural"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a MDNatural"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::Rational v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a Rational"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a Boolean"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalCanonMap: variable %s is not a linear expression", v.c_str()); - return LIB::CanonMap(); - } - } - - Util::ERROR("EvalCanonMap: variable %s not defined", v.c_str()); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an arithmetic UnaryOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an arithmetic BinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::Call v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a Call"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::Interval v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an Interval"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an InterUnaryOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an InterBinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an MultiDimInter"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an MDInterUnaryOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate an MDInterBinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::Set v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a Set"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a SetUnaryOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a SetBinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a LinearExp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a LExpBinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a MDLExp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a MDLExpBinOp"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::LinearMap v) const -{ - EvalOrdSet visit_set(env_); - EvalMDLE visit_mdle(env_); - - return LIB::CanonMap(Apply(visit_set, v.dom()), Apply(visit_mdle, v.lexp())); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a PWLMap"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::SBG v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a SBG"); - return LIB::CanonMap(); -} - -LIB::CanonMap EvalCanonMap::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalCanonMap: trying to evaluate a DSBG"); - return LIB::CanonMap(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_canon_map.hpp b/eval/visitors/eval_canon_map.hpp deleted file mode 100755 index b6c01a8..0000000 --- a/eval/visitors/eval_canon_map.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/** @file eval_canon_map.hpp - - @brief Linear canon map expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_CANON_MAP -#define AST_VISITOR_EVAL_CANON_MAP - -#include "eval/visitors/eval_mdle.hpp" -#include "eval/visitors/eval_ord_set.hpp" -#include "sbg/map.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalCanonMap : public boost::static_visitor { - public: - EvalCanonMap(); - EvalCanonMap(VarEnv env); - - LIB::CanonMap operator()(AST::Natural v) const; - LIB::CanonMap operator()(AST::MDNatural v) const; - LIB::CanonMap operator()(AST::Rational v) const; - LIB::CanonMap operator()(AST::Boolean v) const; - LIB::CanonMap operator()(Util::VariableName v) const; - LIB::CanonMap operator()(AST::UnaryOp v) const; - LIB::CanonMap operator()(AST::BinOp v) const; - LIB::CanonMap operator()(AST::Call v) const; - LIB::CanonMap operator()(AST::Interval v) const; - LIB::CanonMap operator()(AST::InterUnaryOp v) const; - LIB::CanonMap operator()(AST::InterBinOp v) const; - LIB::CanonMap operator()(AST::MultiDimInter v) const; - LIB::CanonMap operator()(AST::MDInterUnaryOp v) const; - LIB::CanonMap operator()(AST::MDInterBinOp v) const; - LIB::CanonMap operator()(AST::Set v) const; - LIB::CanonMap operator()(AST::SetUnaryOp v) const; - LIB::CanonMap operator()(AST::SetBinOp v) const; - LIB::CanonMap operator()(AST::LinearExp v) const; - LIB::CanonMap operator()(AST::LExpBinOp v) const; - LIB::CanonMap operator()(AST::MDLExp v) const; - LIB::CanonMap operator()(AST::MDLExpBinOp v) const; - LIB::CanonMap operator()(AST::LinearMap v) const; - LIB::CanonMap operator()(AST::PWLMap v) const; - LIB::CanonMap operator()(AST::SBG v) const; - LIB::CanonMap operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_canon_pwmap.cpp b/eval/visitors/eval_canon_pwmap.cpp deleted file mode 100755 index b3e1dd5..0000000 --- a/eval/visitors/eval_canon_pwmap.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_canon_pwmap.hpp" - -namespace SBG { - -namespace Eval { - -EvalCanonPWMap::EvalCanonPWMap() : env_() {} -EvalCanonPWMap::EvalCanonPWMap(VarEnv env) : env_(env) {} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Natural v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a Natural"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MDNatural"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Rational v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a Rational"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a Boolean"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalCanonPWMap: variable %s is not a PWMap", v.c_str()); - return LIB::CanonPWMap(); - } - } - - Util::ERROR("EvalCanonPWMap: variable %s not defined", v.c_str()); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate an arithmetic UnaryOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate an arithmetic BinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Call v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a Call"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Interval v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate an Interval"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate an InterUnaryOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate an InterBinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MultiDimInter"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MDInterUnaryOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MDInterBinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::Set v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a Set"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a SetUnaryOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a SetBinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a LinearExp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a LExpBinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MDLExp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a MDLExpBinOp"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a LinearMap"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::PWLMap v) const -{ - LIB::CanonPWMap res; - - EvalCanonMap visit_map(env_); - BOOST_FOREACH (AST::Expr e, v.maps()) - res.emplace(Apply(visit_map, e)); - - return res; -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::SBG v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a SBG"); - return LIB::CanonPWMap(); -} - -LIB::CanonPWMap EvalCanonPWMap::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalCanonPWMap: trying to evaluate a DSBG"); - return LIB::CanonPWMap(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_canon_pwmap.hpp b/eval/visitors/eval_canon_pwmap.hpp deleted file mode 100755 index 6a2aab4..0000000 --- a/eval/visitors/eval_canon_pwmap.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_canon_pwmap.hpp - - @brief Canon piecewise linear map expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_CANON_PWMAP -#define AST_VISITOR_EVAL_CANON_PWMAP - -#include "eval/visitors/eval_canon_map.hpp" -#include "sbg/pw_map.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalCanonPWMap : public boost::static_visitor { - public: - EvalCanonPWMap(); - EvalCanonPWMap(VarEnv env); - - LIB::CanonPWMap operator()(AST::Natural v) const; - LIB::CanonPWMap operator()(AST::MDNatural v) const; - LIB::CanonPWMap operator()(AST::Rational v) const; - LIB::CanonPWMap operator()(AST::Boolean v) const; - LIB::CanonPWMap operator()(Util::VariableName v) const; - LIB::CanonPWMap operator()(AST::UnaryOp v) const; - LIB::CanonPWMap operator()(AST::BinOp v) const; - LIB::CanonPWMap operator()(AST::Call v) const; - LIB::CanonPWMap operator()(AST::Interval v) const; - LIB::CanonPWMap operator()(AST::InterUnaryOp v) const; - LIB::CanonPWMap operator()(AST::InterBinOp v) const; - LIB::CanonPWMap operator()(AST::MultiDimInter v) const; - LIB::CanonPWMap operator()(AST::MDInterUnaryOp v) const; - LIB::CanonPWMap operator()(AST::MDInterBinOp v) const; - LIB::CanonPWMap operator()(AST::Set v) const; - LIB::CanonPWMap operator()(AST::SetUnaryOp v) const; - LIB::CanonPWMap operator()(AST::SetBinOp v) const; - LIB::CanonPWMap operator()(AST::LinearExp v) const; - LIB::CanonPWMap operator()(AST::LExpBinOp v) const; - LIB::CanonPWMap operator()(AST::MDLExp v) const; - LIB::CanonPWMap operator()(AST::MDLExpBinOp v) const; - LIB::CanonPWMap operator()(AST::LinearMap v) const; - LIB::CanonPWMap operator()(AST::PWLMap v) const; - LIB::CanonPWMap operator()(AST::SBG v) const; - LIB::CanonPWMap operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_canon_sbg.cpp b/eval/visitors/eval_canon_sbg.cpp deleted file mode 100755 index 24c3025..0000000 --- a/eval/visitors/eval_canon_sbg.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_canon_sbg.hpp" - -namespace SBG { - -namespace Eval { - -EvalCanonSBG::EvalCanonSBG() : env_() {} -EvalCanonSBG::EvalCanonSBG(VarEnv env) : env_(env) {} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Natural v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a Natural"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a MDNatural"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Rational v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a Rational"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a Boolean"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalCanonSBG: variable %s is not a PWMap", v.c_str()); - return LIB::CanonSBG(); - } - } - - Util::ERROR("EvalCanonSBG: variable %s not defined", v.c_str()); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an arithmetic BinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an arithmetic BinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Call v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a Call"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Interval v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an Interval"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an InterUnaryOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an InterBinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an MultiDimInter"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an MDInterUnaryOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate an MDInterBinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::Set v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a Set"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::SetUnaryOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a SetUnaryOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::SetBinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a SetBinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a LinearExp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a LExpBinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a MDLExp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a MDLExpBinOp"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a LinearMap"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a PWLMap"); - return LIB::CanonSBG(); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::SBG v) const -{ - EvalOrdSet visit_set(env_); - EvalCanonPWMap visit_pw(env_); - - LIB::OrdSet V = Apply(visit_set, v.V()); - LIB::CanonPWMap Vmap = Apply(visit_pw, v.Vmap()); - LIB::CanonPWMap map1 = Apply(visit_pw, v.map1()); - LIB::CanonPWMap map2 = Apply(visit_pw, v.map2()); - LIB::CanonPWMap Emap = Apply(visit_pw, v.Emap()); - - return LIB::CanonSBG(V, Vmap, map1, map2, Emap); -} - -LIB::CanonSBG EvalCanonSBG::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalCanonSBG: trying to evaluate a DSBG"); - return LIB::CanonSBG(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_canon_sbg.hpp b/eval/visitors/eval_canon_sbg.hpp deleted file mode 100755 index 488a307..0000000 --- a/eval/visitors/eval_canon_sbg.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** @file eval_canon_sbg.hpp - - @brief Canon SBG expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_CANON_SBG -#define AST_VISITOR_EVAL_CANON_SBG - -#include "eval/visitors/eval_canon_pwmap.hpp" -#include "sbg/sbg.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalCanonSBG : public boost::static_visitor { - public: - EvalCanonSBG(); - EvalCanonSBG(VarEnv env); - - LIB::CanonSBG operator()(AST::Natural v) const; - LIB::CanonSBG operator()(AST::MDNatural v) const; - LIB::CanonSBG operator()(AST::Rational v) const; - LIB::CanonSBG operator()(AST::Boolean v) const; - LIB::CanonSBG operator()(Util::VariableName v) const; - LIB::CanonSBG operator()(AST::UnaryOp v) const; - LIB::CanonSBG operator()(AST::BinOp v) const; - LIB::CanonSBG operator()(AST::Call v) const; - LIB::CanonSBG operator()(AST::Interval v) const; - LIB::CanonSBG operator()(AST::InterUnaryOp v) const; - LIB::CanonSBG operator()(AST::InterBinOp v) const; - LIB::CanonSBG operator()(AST::MultiDimInter v) const; - LIB::CanonSBG operator()(AST::MDInterUnaryOp v) const; - LIB::CanonSBG operator()(AST::MDInterBinOp v) const; - LIB::CanonSBG operator()(AST::Set v) const; - LIB::CanonSBG operator()(AST::SetUnaryOp v) const; - LIB::CanonSBG operator()(AST::SetBinOp v) const; - LIB::CanonSBG operator()(AST::LinearExp v) const; - LIB::CanonSBG operator()(AST::LExpBinOp v) const; - LIB::CanonSBG operator()(AST::MDLExp v) const; - LIB::CanonSBG operator()(AST::MDLExpBinOp v) const; - LIB::CanonSBG operator()(AST::LinearMap v) const; - LIB::CanonSBG operator()(AST::PWLMap v) const; - LIB::CanonSBG operator()(AST::SBG v) const; - LIB::CanonSBG operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_container.cpp b/eval/visitors/eval_container.cpp deleted file mode 100755 index 1d9235c..0000000 --- a/eval/visitors/eval_container.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_container.hpp" - -namespace SBG { - -namespace Eval { - -ContainerBaseType EvalContainer::operator()(Util::NAT v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a NAT"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(Util::MD_NAT v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a MD_NAT"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(Util::RATIONAL v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a RATIONAL"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::Interval v) const { return ContainerBaseType(v); } - -ContainerBaseType EvalContainer::operator()(LIB::SetPiece v) const { return ContainerBaseType(v); } - -ContainerBaseType EvalContainer::operator()(LIB::UnordSet v) const { return ContainerBaseType(v); } - -ContainerBaseType EvalContainer::operator()(LIB::OrdSet v) const { return ContainerBaseType(v); } - -ContainerBaseType EvalContainer::operator()(LIB::LExp v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a LExp"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::Exp v) const -{ - Util::ERROR("EvalContainer: trying to evaluate an Exp"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::BaseMap v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a BaseMap"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::CanonMap v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a CanonMap"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::BasePWMap v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a BasePWMap"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::CanonPWMap v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a CanonPWMap"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::BaseSBG v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a BaseSBG"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::CanonSBG v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a CanonSBG"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::BaseDSBG v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a BaseDSBG"); - return ContainerBaseType(); -} - -ContainerBaseType EvalContainer::operator()(LIB::CanonDSBG v) const -{ - Util::ERROR("EvalContainer: trying to evaluate a CanonDSBG"); - return ContainerBaseType(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_container.hpp b/eval/visitors/eval_container.hpp deleted file mode 100755 index f1061ad..0000000 --- a/eval/visitors/eval_container.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/** @file eval_container.hpp - - @brief Container base type evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_CONTAINER -#define AST_VISITOR_EVAL_CONTAINER - -#include - -#include "eval/defs.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalContainer : public boost::static_visitor { - public: - ContainerBaseType operator()(Util::NAT v) const; - ContainerBaseType operator()(Util::MD_NAT v) const; - ContainerBaseType operator()(Util::RATIONAL v) const; - ContainerBaseType operator()(LIB::Interval v) const; - ContainerBaseType operator()(LIB::SetPiece v) const; - ContainerBaseType operator()(LIB::UnordSet v) const; - ContainerBaseType operator()(LIB::OrdSet v) const; - ContainerBaseType operator()(LIB::LExp v) const; - ContainerBaseType operator()(LIB::Exp v) const; - ContainerBaseType operator()(LIB::BaseMap v) const; - ContainerBaseType operator()(LIB::CanonMap v) const; - ContainerBaseType operator()(LIB::BasePWMap v) const; - ContainerBaseType operator()(LIB::CanonPWMap v) const; - ContainerBaseType operator()(LIB::BaseSBG v) const; - ContainerBaseType operator()(LIB::CanonSBG v) const; - ContainerBaseType operator()(LIB::BaseDSBG v) const; - ContainerBaseType operator()(LIB::CanonDSBG v) const; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_expr.cpp b/eval/visitors/eval_expr.cpp index 196f107..6831209 100755 --- a/eval/visitors/eval_expr.cpp +++ b/eval/visitors/eval_expr.cpp @@ -23,265 +23,6 @@ namespace SBG { namespace Eval { -// ----------------------------------------------------------------------------- -// Function visitors ----------------------------------------------------------- -// ----------------------------------------------------------------------------- - -auto empty_visitor_ = Util::Overload { - [](LIB::Interval a) { return isEmpty(a); }, - [](LIB::MultiDimInter a) { return isEmpty(a); }, - [](LIB::UnordSet a) { return isEmpty(a); }, - [](LIB::OrdSet a) { return isEmpty(a); }, - [](auto a) { - Util::ERROR("Wrong arguments for isEmpty"); - return true; - } -}; - -auto member_visitor_ = Util::Overload { - [](Util::NAT a, LIB::Interval b) { return isMember(a, b); }, - [](Util::NAT a, LIB::MultiDimInter b) { return isMember(Util::MD_NAT(a), b); }, - [](Util::MD_NAT a, LIB::MultiDimInter b) { return isMember(a, b); }, - [](Util::NAT a, LIB::UnordSet b) { return isMember(Util::MD_NAT(a), b); }, - [](Util::NAT a, LIB::OrdSet b) { return isMember(Util::MD_NAT(a), b); }, - [](Util::MD_NAT a, LIB::UnordSet b) { return isMember(a, b); }, - [](Util::MD_NAT a, LIB::OrdSet b) { return isMember(a, b); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for isMember"); - return false; - } -}; - -auto min_visitor_ = Util::Overload { - [](LIB::Interval a) { return ExprBaseType(minElem(a)); }, - [](LIB::MultiDimInter a) { return ExprBaseType(minElem(a)); }, - [](LIB::UnordSet a) { return ExprBaseType(minElem(a)); }, - [](LIB::OrdSet a) { return ExprBaseType(minElem(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for minElem"); - return ExprBaseType(); - } -}; - -auto max_visitor_ = Util::Overload { - [](LIB::Interval a) { return ExprBaseType(maxElem(a)); }, - [](LIB::MultiDimInter a) { return ExprBaseType(maxElem(a)); }, - [](LIB::UnordSet a) { return ExprBaseType(maxElem(a)); }, - [](LIB::OrdSet a) { return ExprBaseType(maxElem(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for maxElem"); - return ExprBaseType(); - } -}; - -auto lt_visitor_ = Util::Overload { - [](LIB::Interval a, LIB::Interval b) { return ExprBaseType(least(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for lt"); - return ExprBaseType(); - } -}; - -auto compose_visitor_ = Util::Overload { - [](LIB::LExp a, LIB::LExp b) { return ExprBaseType(composition(a, b)); }, - [](LIB::Exp a, LIB::Exp b) { return ExprBaseType(composition(a, b)); }, - [](LIB::BaseMap a, LIB::BaseMap b) { return ExprBaseType(composition(a, b)); }, - [](LIB::CanonMap a, LIB::CanonMap b) { return ExprBaseType(composition(a, b)); }, - [](LIB::BasePWMap a, LIB::BasePWMap b) { return ExprBaseType(composition(a, b)); }, - [](LIB::CanonPWMap a, LIB::CanonPWMap b) { return ExprBaseType(composition(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for composition"); - return ExprBaseType(); } -}; - -auto inverse_visitor_ = Util::Overload { - [](LIB::LExp a) { return ExprBaseType(inverse(a)); }, - [](LIB::Exp a) { return ExprBaseType(inverse(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for inversion"); - return ExprBaseType(); - } -}; - -auto image_visitor1_ = Util::Overload { - [](LIB::BaseMap a) { return ExprBaseType(image(a)); }, - [](LIB::CanonMap a) { return ExprBaseType(image(a)); }, - [](LIB::BasePWMap a) { return ExprBaseType(image(a)); }, - [](LIB::CanonPWMap a) { return ExprBaseType(image(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for image 1"); - return ExprBaseType(); - } -}; - -auto image_visitor2_ = Util::Overload { - [](LIB::UnordSet a, LIB::BaseMap b) { return ExprBaseType(image(a, b)); }, - [](LIB::OrdSet a, LIB::CanonMap b) { return ExprBaseType(image(a, b)); }, - [](LIB::UnordSet a, LIB::BasePWMap b) { return ExprBaseType(image(a, b)); }, - [](LIB::OrdSet a, LIB::CanonPWMap b) { return ExprBaseType(image(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for image 2"); - return ExprBaseType(); - } -}; - -auto pre_image_visitor1_ = Util::Overload { - [](LIB::BaseMap a) { return ExprBaseType(preImage(a)); }, - [](LIB::CanonMap a) { return ExprBaseType(preImage(a)); }, - [](LIB::BasePWMap a) { return ExprBaseType(preImage(a)); }, - [](LIB::CanonPWMap a) { return ExprBaseType(preImage(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for pre image 1"); - return ExprBaseType(); - } -}; - -auto pre_image_visitor2_ = Util::Overload { - [](LIB::UnordSet a, LIB::BaseMap b) { return ExprBaseType(preImage(a, b)); }, - [](LIB::OrdSet a, LIB::CanonMap b) { return ExprBaseType(preImage(a, b)); }, - [](LIB::UnordSet a, LIB::BasePWMap b) { return ExprBaseType(preImage(a, b)); }, - [](LIB::OrdSet a, LIB::CanonPWMap b) { return ExprBaseType(preImage(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for pre image 2"); - return ExprBaseType(); - } -}; - -auto dom_visitor_ = Util::Overload { - [](LIB::BasePWMap a) { return ExprBaseType(LIB::dom(a)); }, - [](LIB::CanonPWMap a) { return ExprBaseType(LIB::dom(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for dom"); - return ExprBaseType(); - } -}; - -auto combine_visitor_ = Util::Overload { - [](LIB::BasePWMap a, LIB::BasePWMap b) { return ExprBaseType(combine(a, b)); }, - [](LIB::CanonPWMap a, LIB::CanonPWMap b) { return ExprBaseType(combine(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for combine"); - return ExprBaseType(); - } -}; - -auto min_map_visitor2_ = Util::Overload { - [](LIB::BasePWMap a, LIB::BasePWMap b) { return ExprBaseType(minMap(a, b)); }, - [](LIB::CanonPWMap a, LIB::CanonPWMap b) { return ExprBaseType(minMap(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for minMap2"); - return ExprBaseType(); - } -}; - -auto min_map_unord_visitor3_ = Util::Overload { - [](LIB::Interval a, LIB::LExp b, LIB::LExp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](LIB::SetPiece a, LIB::Exp b, LIB::Exp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](LIB::UnordSet a, LIB::Exp b, LIB::Exp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](auto a, auto b, auto c) { - Util::ERROR("Wrong arguments for minMap3"); - return ExprBaseType(); - } -}; - -auto min_map_ord_visitor3_ = Util::Overload { - [](LIB::Interval a, LIB::LExp b, LIB::LExp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](LIB::SetPiece a, LIB::Exp b, LIB::Exp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](LIB::OrdSet a, LIB::Exp b, LIB::Exp c) { return ExprBaseType(LIB::minMap(a, b, c)); }, - [](auto a, auto b, auto c) { - Util::ERROR("Wrong arguments for minMap3"); - return ExprBaseType(); - } -}; - -auto min_map_visitor4_ = Util::Overload { - [](LIB::BasePWMap a, LIB::BasePWMap b, LIB::BasePWMap c, LIB::BasePWMap d) { - return ExprBaseType(minMap(a, b, c, d)); - }, - [](LIB::CanonPWMap a, LIB::CanonPWMap b, LIB::CanonPWMap c, LIB::CanonPWMap d) { - return ExprBaseType(minMap(a, b, c, d)); - }, - [](auto a, auto b, auto c, auto d) { - Util::ERROR("Wrong arguments for minMap4"); - return ExprBaseType(); - } -}; - -auto min_map_unord_visitor5_ = Util::Overload { - [](LIB::Interval a, LIB::LExp b, LIB::LExp c, LIB::LExp d, LIB::LExp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](LIB::SetPiece a, LIB::Exp b, LIB::Exp c, LIB::Exp d, LIB::Exp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](LIB::UnordSet a, LIB::Exp b, LIB::Exp c, LIB::Exp d, LIB::Exp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](auto a, auto b, auto c, auto d, auto e) { - Util::ERROR("Wrong arguments for minMap5"); - return ExprBaseType(); - } -}; - -auto min_map_ord_visitor5_ = Util::Overload { - [](LIB::Interval a, LIB::LExp b, LIB::LExp c, LIB::LExp d, LIB::LExp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](LIB::SetPiece a, LIB::Exp b, LIB::Exp c, LIB::Exp d, LIB::Exp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](LIB::OrdSet a, LIB::Exp b, LIB::Exp c, LIB::Exp d, LIB::Exp e) { - return ExprBaseType(LIB::minMap(a, b, c, d, e)); - }, - [](auto a, auto b, auto c, auto d, auto e) { - Util::ERROR("Wrong arguments for minMap5"); - return ExprBaseType(); - } -}; - -auto reduce_visitor_ = Util::Overload { - [](LIB::BasePWMap a) { return ExprBaseType(reduce(a)); }, - [](LIB::CanonPWMap a) { return ExprBaseType(reduce(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for reduce"); - return ExprBaseType(); - } -}; - - -auto min_adj_visitor2_ = Util::Overload { - [](LIB::BasePWMap a, LIB::BasePWMap b) { return ExprBaseType(minAdjMap(a, b)); }, - [](LIB::CanonPWMap a, LIB::CanonPWMap b) { return ExprBaseType(minAdjMap(a, b)); }, - [](auto a, auto b) { - Util::ERROR("Wrong arguments for minAdjMap"); - return ExprBaseType(); - } -}; - -auto connected_visitor_ = Util::Overload { - [](LIB::BaseSBG a) { return ExprBaseType(connectedComponents(a)); }, - [](LIB::CanonSBG a) { return ExprBaseType(connectedComponents(a)); }, - [](auto a) { - Util::ERROR("Wrong arguments for connectedComponents"); - return ExprBaseType(); - } -}; - -auto matching_visitor_ = Util::Overload { - [](LIB::BaseSBG a) { - LIB::BaseMatch match(a); - return ExprBaseType(match.calculate().matched_edges()); - }, - [](LIB::CanonSBG a) { - LIB::CanonMatch match(a); - return ExprBaseType(match.calculate().matched_edges()); - }, - [](auto a) { - Util::ERROR("Wrong arguments for minReach"); - return ExprBaseType(); - } -}; - // ----------------------------------------------------------------------------- // Expression evaluator -------------------------------------------------------- // ----------------------------------------------------------------------------- @@ -333,243 +74,212 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const auto venv = fenv_[vname]; if (venv) { - std::vector eval_args; - BOOST_FOREACH (AST::Expr a, v.args()) - eval_args.push_back(ApplyThis(a)); - + AST::ExprList args = v.args(); + std::size_t args_size = v.args().size(); bool arity_ok = false; switch (*venv) { case Eval::Func::empty: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[0]); - bool result = std::visit(empty_visitor_, container); - return result; + EvalSet visit_set(nmbr_dims_, env_); + return isEmpty(Apply(visit_set, args[0])); } break; case Eval::Func::member: - if (eval_args.size() == 2) { + if (args_size == 2) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[1]); - NatBaseType x = Apply(EvalNatBT{}, eval_args[0]); - bool result = std::visit(member_visitor_, x, container); - return result; + EvalMDNat visit_mdnat(env_); + Util::MD_NAT x = Apply(visit_mdnat, args[0]); + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, args[1]); + return isMember(x, s); } break; case Eval::Func::min: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[0]); - ExprBaseType result = std::visit(min_visitor_, container); - return result; + EvalSet visit_set(nmbr_dims_, env_); + return minElem(Apply(visit_set, args[0])); } break; case Eval::Func::max: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[0]); - ExprBaseType result = std::visit(max_visitor_, container); - return result; - } - break; - - case Eval::Func::lt: - if (eval_args.size() == 2) { - arity_ok = true; - - EvalContainer visit_cont; - ContainerBaseType cont1 = Apply(visit_cont, eval_args[0]), cont2 = Apply(visit_cont, eval_args[1]); - ExprBaseType result = std::visit(lt_visitor_, cont1, cont2); - return result; + EvalSet visit_set(nmbr_dims_, env_); + return maxElem(Apply(visit_set, args[0])); } break; case Eval::Func::comp: - if (eval_args.size() == 2) { + if (args_size == 2) { arity_ok = true; - ExprBaseType result; - if (is(eval_args[0]) || is(eval_args[0])){ - EvalLinear visit_linear; - LinearBaseType e1 = Apply(visit_linear, eval_args[0]), e2 = Apply(visit_linear, eval_args[1]); - result = std::visit(compose_visitor_, e1, e2); - } - - else{ - EvalMap visit_map; - MapBaseType m1 = Apply(visit_map, eval_args[0]), m2 = Apply(visit_map, eval_args[1]); - result = std::visit(compose_visitor_, m1, m2); - } - - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw1 = Apply(visit_pwmap, args[0]); + LIB::PWMap pw2 = Apply(visit_pwmap, args[1]); + return composition(pw1, pw2); } break; case Eval::Func::inv: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - LinearBaseType lexp = Apply(EvalLinear(), eval_args[0]); - ExprBaseType result = std::visit(inverse_visitor_, lexp); - return result; + EvalMDLE visit_mdle(env_); + return inverse(Apply(visit_mdle, args[0])); } break; case Eval::Func::im: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - MapBaseType sbgmap = Apply(EvalMap(), eval_args[0]); - ExprBaseType result = std::visit(image_visitor1_, sbgmap); - return result; + EvalSet visit_set(nmbr_dims_, env_); + return image(Apply(visit_set, args[0])); } - else if (eval_args.size() == 2) { + else if (args_size == 2) { arity_ok = true; - ContainerBaseType subdom = Apply(EvalContainer{}, eval_args[0]); - MapBaseType sbgmap = Apply(EvalMap(), eval_args[1]); - ExprBaseType result = std::visit(image_visitor2_, subdom, sbgmap); - return result; + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, args[1]); + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw = Apply(visit_pwmap, args[0]); + return image(s, pw); } break; case Eval::Func::preim: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - MapBaseType sbgmap = Apply(EvalMap(), eval_args[0]); - ExprBaseType result = std::visit(pre_image_visitor1_, sbgmap); - return result; + EvalSet visit_set(nmbr_dims_, env_); + return preImage(Apply(visit_set, args[0])); } - else if (eval_args.size() == 2) { + else if (args_size == 2) { arity_ok = true; - ContainerBaseType subdom = Apply(EvalContainer{}, eval_args[0]); - MapBaseType map = Apply(EvalMap(), eval_args[1]); - ExprBaseType result = std::visit(pre_image_visitor2_, subdom, map); - return result; + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, args[1]); + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw = Apply(visit_pwmap, args[0]); + return preImage(s, pw); } - + break; case Eval::Func::dom: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - MapBaseType pw = Apply(EvalMap(), eval_args[0]); - ExprBaseType result = std::visit(dom_visitor_, pw); - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + return LIB::dom(Apply(visit_pwmap, args[0])); } break; case Eval::Func::comb: - if (eval_args.size() == 2) { + if (args_size == 2) { arity_ok = true; - - MapBaseType pw1 = Apply(EvalMap(), eval_args[0]), pw2 = Apply(EvalMap(), eval_args[1]); - ExprBaseType result = std::visit(combine_visitor_, pw1, pw2); - return result; + + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw1 = Apply(visit_pwmap, args[0]); + LIB::PWMap pw2 = Apply(visit_pwmap, args[1]); + return combine(pw1, pw2); } break; case Eval::Func::min_map: - if (eval_args.size() == 2) { + if (args_size == 2) { arity_ok = true; - EvalMap visit_map; - MapBaseType pw1 = Apply(visit_map, eval_args[0]), pw2 = Apply(visit_map, eval_args[1]); - ExprBaseType result = std::visit(min_map_visitor2_, pw1, pw2); - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw1 = Apply(visit_pwmap, args[0]); + LIB::PWMap pw2 = Apply(visit_pwmap, args[1]); + return minMap(pw1, pw2); } - if (eval_args.size() == 3) { + if (args_size == 3) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[0]); - EvalLinear visit_linear; - LinearBaseType e1 = Apply(visit_linear, eval_args[1]), e2 = Apply(visit_linear, eval_args[2]); - - ExprBaseType result; - if (nmbr_dims_ == 1) result = std::visit(min_map_ord_visitor3_, container, e1, e2); - else result = std::visit(min_map_unord_visitor3_, container, e1, e2); - - return result; + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, args[0]); + EvalMDLE visit_mdle(env_); + LIB::Exp e1 = Apply(visit_mdle, args[1]); + LIB::Exp e2 = Apply(visit_mdle, args[2]); + return minMap(s, e1, e2); } - if (eval_args.size() == 4) { + if (args_size == 4) { arity_ok = true; - EvalMap visit_map; - MapBaseType pw1 = Apply(visit_map, eval_args[0]), pw2 = Apply(visit_map, eval_args[1]); - MapBaseType pw3 = Apply(visit_map, eval_args[2]), pw4 = Apply(visit_map, eval_args[3]); - - ExprBaseType result = std::visit(min_map_visitor4_, pw1, pw2, pw3, pw4); - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw1 = Apply(visit_pwmap, args[0]); + LIB::PWMap pw2 = Apply(visit_pwmap, args[1]); + LIB::PWMap pw3 = Apply(visit_pwmap, args[2]); + LIB::PWMap pw4 = Apply(visit_pwmap, args[3]); + return minMap(pw1, pw2, pw3, pw4); } - if (eval_args.size() == 5) { + if (args_size == 5) { arity_ok = true; - ContainerBaseType container = Apply(EvalContainer{}, eval_args[0]); - EvalLinear visit_linear; - LinearBaseType e1 = Apply(visit_linear, eval_args[1]), e2 = Apply(visit_linear, eval_args[2]); - LinearBaseType e3 = Apply(visit_linear, eval_args[3]), e4 = Apply(visit_linear, eval_args[4]); - ExprBaseType result; - - if (nmbr_dims_ == 1) result = std::visit(min_map_ord_visitor5_, container, e1, e2, e3, e4); - else result = std::visit(min_map_unord_visitor5_, container, e1, e2, e3, e4); - - return result; + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, args[0]); + EvalMDLE visit_mdle(env_); + LIB::Exp e1 = Apply(visit_mdle, args[1]); + LIB::Exp e2 = Apply(visit_mdle, args[2]); + LIB::Exp e3 = Apply(visit_mdle, args[3]); + LIB::Exp e4 = Apply(visit_mdle, args[4]); + return minMap(s, e1, e2, e3, e4); } break; case Eval::Func::red: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - MapBaseType map = Apply(EvalMap{}, eval_args[0]); - ExprBaseType result = std::visit(reduce_visitor_, map); - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + return reduce(Apply(visit_pwmap, args[0])); } break; case Eval::Func::min_adj: - if (eval_args.size() == 2) { + if (args_size == 2) { arity_ok = true; - MapBaseType map1 = Apply(EvalMap{}, eval_args[0]), map2 = Apply(EvalMap{}, eval_args[1]); - ExprBaseType result = std::visit(min_adj_visitor2_, map1, map2); - return result; + EvalPWMap visit_pwmap(nmbr_dims_, env_); + LIB::PWMap pw1 = Apply(visit_pwmap, args[0]); + LIB::PWMap pw2 = Apply(visit_pwmap, args[1]); + return minAdjMap(pw1, pw2); } break; case Eval::Func::connected: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - SBGBaseType g = Apply(EvalGraph{}, eval_args[0]); - ExprBaseType result = std::visit(connected_visitor_, g); - return result; + EvalGraph visit_graph(nmbr_dims_, env_); + LIB::SBGraph g = Apply(visit_graph, args[0]).sbg(); + return connectedComponents(g); } break; case Eval::Func::matching: - if (eval_args.size() == 1) { + if (args_size == 1) { arity_ok = true; - SBGBaseType g = Apply(EvalGraph{}, eval_args[0]); - ExprBaseType result = std::visit(matching_visitor_, g); - return result; + EvalGraph visit_graph(nmbr_dims_, env_); + LIB::SBGraph g = Apply(visit_graph, args[0]).sbg(); + return LIB::SBGMatching(g).calculate().matched_edges(); } break; @@ -593,10 +303,10 @@ ExprBaseType EvalExpression::operator()(AST::Interval v) const { return Apply(Ev ExprBaseType EvalExpression::operator()(AST::InterUnaryOp v) const { AST::Expr exp = v.e(); - EvalInterval eval_interval(env_); + EvalInterval visit_interval(env_); switch (v.op()) { case AST::ContainerUOp::card: - return cardinal(Apply(eval_interval, exp)); + return cardinal(Apply(visit_interval, exp)); default: std::stringstream ss; @@ -609,16 +319,16 @@ ExprBaseType EvalExpression::operator()(AST::InterUnaryOp v) const ExprBaseType EvalExpression::operator()(AST::InterBinOp v) const { AST::Expr l = v.left(), r = v.right(); - EvalInterval eval_interval(env_); + EvalInterval visit_interval(env_); switch (v.op()) { case AST::ContainerOp::cap: - return intersection(Apply(eval_interval, l), Apply(eval_interval, r)); + return intersection(Apply(visit_interval, l), Apply(visit_interval, r)); case AST::ContainerOp::less: - return Apply(eval_interval, l) < Apply(eval_interval, r); + return Apply(visit_interval, l) < Apply(visit_interval, r); case AST::ContainerOp::eq: - return Apply(eval_interval, l) == Apply(eval_interval, r); + return Apply(visit_interval, l) == Apply(visit_interval, r); default: std::stringstream ss; @@ -632,11 +342,11 @@ ExprBaseType EvalExpression::operator()(AST::MultiDimInter v) const { return App ExprBaseType EvalExpression::operator()(AST::MDInterUnaryOp v) const { - AST::Expr exp = v.e(); EvalMDI visit_mdi(env_); + LIB::MultiDimInter mdi = Apply(visit_mdi, v.e()); switch (v.op()) { case AST::ContainerUOp::card: - return cardinal(Apply(visit_mdi, exp)); + return cardinal(mdi); default: std::stringstream ss; @@ -650,19 +360,19 @@ ExprBaseType EvalExpression::operator()(AST::MDInterUnaryOp v) const ExprBaseType EvalExpression::operator()(AST::MDInterBinOp v) const { - AST::Expr l = v.left(), r = v.right(); EvalMDI visit_mdi(env_); + LIB::MultiDimInter l = Apply(visit_mdi, v.left()), r = Apply(visit_mdi, v.right()); switch (v.op()) { - case AST::ContainerOp::cap: { - return intersection(Apply(visit_mdi, l), Apply(visit_mdi, r)); - } + case AST::ContainerOp::cap: + return intersection(l, r); + break; case AST::ContainerOp::less: - return Apply(visit_mdi, l) < Apply(visit_mdi, r); + return l < r; break; case AST::ContainerOp::eq: - return Apply(visit_mdi, l) == Apply(visit_mdi, r); + return l == r; break; default: @@ -676,68 +386,25 @@ ExprBaseType EvalExpression::operator()(AST::MDInterBinOp v) const return 0; } -ExprBaseType EvalExpression::operator()(AST::Set v) const -{ - if (nmbr_dims_ == 1) return Apply(EvalOrdSet(env_), AST::Expr(v)); - - return Apply(EvalUnordSet(env_), AST::Expr(v)); -} +ExprBaseType EvalExpression::operator()(AST::Set v) const { return Apply(EvalSet(nmbr_dims_, env_), AST::Expr(v)); } // ----- // -ExprBaseType VisitSetUnOp(AST::SetUnaryOp v, LIB::OrdSet s) -{ - switch (v.op()) { - case AST::ContainerUOp::card: - return cardinal(s); - - case AST::ContainerUOp::comp: - return complement(s); - - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalExpression: SetUnaryOp %s not supported.", ss.str().c_str()); - return 0; - } - - return 0; -} - -ExprBaseType VisitSetUnOp(AST::SetUnaryOp v, LIB::UnordSet s) +ExprBaseType EvalExpression::operator()(AST::SetUnaryOp v) const { + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set s = Apply(visit_set, v.e()); switch (v.op()) { case AST::ContainerUOp::card: return cardinal(s); - - case AST::ContainerUOp::comp: - return complement(s); + break; default: std::stringstream ss; ss << v.op(); Util::ERROR("EvalExpression: SetUnaryOp %s not supported.", ss.str().c_str()); return 0; - } - - return 0; -} - -ExprBaseType EvalExpression::operator()(AST::SetUnaryOp v) const -{ - AST::Expr exp = v.e(); - switch (nmbr_dims_) { - case 1: { - EvalOrdSet visit_ord_set(env_); - LIB::OrdSet s = Apply(visit_ord_set, exp); - return VisitSetUnOp(v, s); - } - - default: { - EvalUnordSet visit_unord_set(env_); - LIB::UnordSet s = Apply(visit_unord_set, exp); - return VisitSetUnOp(v, s); - } + break; } return 0; @@ -745,71 +412,34 @@ ExprBaseType EvalExpression::operator()(AST::SetUnaryOp v) const // ----- // -ExprBaseType VisitSetBinOp(AST::SetBinOp v, LIB::OrdSet sl, LIB::OrdSet sr) +ExprBaseType EvalExpression::operator()(AST::SetBinOp v) const { + EvalSet visit_set(nmbr_dims_, env_); + LIB::Set l = Apply(visit_set, v.left()), r = Apply(visit_set, v.right()); switch (v.op()) { case AST::ContainerOp::cap: - return intersection(sl, sr); - - case AST::ContainerOp::diff: - return difference(sl, sr); - - case AST::ContainerOp::eq: - return sl == sr; + return intersection(l, r); case AST::ContainerOp::cup: - return cup(sl, sr); - - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalExpression: SetBinOp %s not supported.", ss.str().c_str()); - return 0; - } - - return 0; -} - -ExprBaseType VisitSetBinOp(AST::SetBinOp v, LIB::UnordSet sl, LIB::UnordSet sr) -{ - switch (v.op()) { - case AST::ContainerOp::cap: - return intersection(sl, sr); + return cup(l, r); case AST::ContainerOp::diff: - return difference(sl, sr); + return difference(l, r); - case AST::ContainerOp::eq: - return sl == sr; + case AST::ContainerOp::less: + return l < r; + break; - case AST::ContainerOp::cup: - return cup(sl, sr); + case AST::ContainerOp::eq: + return l == r; + break; default: std::stringstream ss; ss << v.op(); - Util::ERROR("EvalExpression: SetBinOp %s not supported.", ss.str().c_str()); + Util::ERROR("EvalExpression: MDInterBinOp %s not supported.", ss.str().c_str()); return 0; - } - - return 0; -} - -ExprBaseType EvalExpression::operator()(AST::SetBinOp v) const -{ - AST::Expr l = v.left(), r = v.right(); - switch (nmbr_dims_) { - case 1: { - EvalOrdSet visit_ord_set(env_); - LIB::OrdSet sl = Apply(visit_ord_set, l), sr = Apply(visit_ord_set, r); - return VisitSetBinOp(v, sl, sr); - } - - default: { - EvalUnordSet visit_unord_set(env_); - LIB::UnordSet sl = Apply(visit_unord_set, l), sr = Apply(visit_unord_set, r); - return VisitSetBinOp(v, sl, sr); - } + break; } return 0; @@ -875,32 +505,26 @@ ExprBaseType EvalExpression::operator()(AST::MDLExpBinOp v) const ExprBaseType EvalExpression::operator()(AST::LinearMap v) const { - if (nmbr_dims_ == 1) return Apply(EvalCanonMap(env_), AST::Expr(v)); - - return Apply(EvalBaseMap(env_), AST::Expr(v)); + return Apply(EvalMap(nmbr_dims_, env_), AST::Expr(v)); } // ----- // ExprBaseType EvalExpression::operator()(AST::PWLMap v) const { - if (nmbr_dims_ == 1) return Apply(EvalCanonPWMap(env_), AST::Expr(v)); - - return Apply(EvalBasePWMap(env_), AST::Expr(v)); + return Apply(EvalPWMap(nmbr_dims_, env_), AST::Expr(v)); } ExprBaseType EvalExpression::operator()(AST::SBG v) const { - if (nmbr_dims_ == 1) return Apply(EvalCanonSBG(env_), AST::Expr(v)); - - return Apply(EvalBaseSBG(env_), AST::Expr(v)); + EvalGraphType res = Apply(EvalGraph(nmbr_dims_, env_), AST::Expr(v)); + return res.sbg(); } ExprBaseType EvalExpression::operator()(AST::DSBG v) const { - if (nmbr_dims_ == 1) return Apply(EvalCanonDSBG(env_), AST::Expr(v)); - - return Apply(EvalBaseDSBG(env_), AST::Expr(v)); + EvalGraphType res = Apply(EvalGraph(nmbr_dims_, env_), AST::Expr(v)); + return res.dsbg(); } } // namespace Eval diff --git a/eval/visitors/eval_expr.hpp b/eval/visitors/eval_expr.hpp index 19c10e3..8a3665a 100755 --- a/eval/visitors/eval_expr.hpp +++ b/eval/visitors/eval_expr.hpp @@ -24,14 +24,7 @@ #ifndef AST_VISITOR_EVALEXP #define AST_VISITOR_EVALEXP -#include "eval/visitors/eval_base_sbg.hpp" -#include "eval/visitors/eval_canon_sbg.hpp" -#include "eval/visitors/eval_base_dsbg.hpp" -#include "eval/visitors/eval_canon_dsbg.hpp" -#include "eval/visitors/eval_natbt.hpp" -#include "eval/visitors/eval_container.hpp" -#include "eval/visitors/eval_linear.hpp" -#include "eval/visitors/eval_map.hpp" +#include "eval/visitors/eval_mdnat.hpp" #include "eval/visitors/eval_graph.hpp" #include "sbg/sbg_algorithms.hpp" diff --git a/eval/visitors/eval_graph.cpp b/eval/visitors/eval_graph.cpp old mode 100755 new mode 100644 index 09508c8..ad51f6c --- a/eval/visitors/eval_graph.cpp +++ b/eval/visitors/eval_graph.cpp @@ -23,91 +23,183 @@ namespace SBG { namespace Eval { -SBGBaseType EvalGraph::operator()(Util::NAT v) const +EvalGraphType::EvalGraphType() : sbg_(), dsbg_() {} +EvalGraphType::EvalGraphType(LIB::SBGraph sbg) : sbg_(sbg), dsbg_() {} +EvalGraphType::EvalGraphType(LIB::DSBGraph dsbg) : sbg_(), dsbg_(dsbg) {} + +member_imp(EvalGraphType, LIB::SBGraph, sbg); +member_imp(EvalGraphType, LIB::DSBGraph, dsbg); + +EvalGraph::EvalGraph() : nmbr_dims_(), env_() {} +EvalGraph::EvalGraph(unsigned int nmbr_dims, VarEnv env) : nmbr_dims_(nmbr_dims), env_(env) {} + +EvalGraphType EvalGraph::operator()(AST::Natural v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a Natural"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::MDNatural v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a MDNatural"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::Rational v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a Rational"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::Boolean v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a Boolean"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(Util::VariableName v) const { - Util::ERROR("EvalGraph: trying to evaluate a NAT"); - return SBGBaseType(); + Util::ERROR("EvalGraph: variable %s not defined", v.c_str()); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(Util::MD_NAT v) const +EvalGraphType EvalGraph::operator()(AST::UnaryOp v) const { - Util::ERROR("EvalGraph: trying to evaluate a MD_NAT"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate an arithmetic UnaryOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(Util::RATIONAL v) const -{ - Util::ERROR("EvalGraph: trying to evaluate a RATIONAL"); - return SBGBaseType(); +EvalGraphType EvalGraph::operator()(AST::BinOp v) const +{ + Util::ERROR("EvalGraph: trying to evaluate an arithmetic BinOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::Interval v) const +EvalGraphType EvalGraph::operator()(AST::Call v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a Call"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::Interval v) const { Util::ERROR("EvalGraph: trying to evaluate an Interval"); - return SBGBaseType(); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::SetPiece v) const +EvalGraphType EvalGraph::operator()(AST::InterUnaryOp v) const { - Util::ERROR("EvalGraph: trying to evaluate a SetPiece"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate an InterUnaryOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::UnordSet v) const +EvalGraphType EvalGraph::operator()(AST::InterBinOp v) const { - Util::ERROR("EvalGraph: trying to evaluate an UnordSet"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate an InterBinOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::OrdSet v) const +EvalGraphType EvalGraph::operator()(AST::MultiDimInter v) const { - Util::ERROR("EvalGraph: trying to evaluate an OrdSet"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate an MultiDimInter"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::LExp v) const +EvalGraphType EvalGraph::operator()(AST::MDInterUnaryOp v) const { - Util::ERROR("EvalGraph: trying to evaluate a LExp"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate an MDInterUnaryOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::Exp v) const -{ - Util::ERROR("EvalGraph: trying to evaluate an Exp"); - return SBGBaseType(); +EvalGraphType EvalGraph::operator()(AST::MDInterBinOp v) const +{ + Util::ERROR("EvalGraph: trying to evaluate an MDInterBinOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::BaseMap v) const +EvalGraphType EvalGraph::operator()(AST::Set v) const { - Util::ERROR("EvalGraph: trying to evaluate a BaseMap"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate a Set"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::CanonMap v) const +EvalGraphType EvalGraph::operator()(AST::SetUnaryOp v) const { - Util::ERROR("EvalGraph: trying to evaluate a CanonMap"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate a SetUnaryOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::BasePWMap v) const +EvalGraphType EvalGraph::operator()(AST::SetBinOp v) const { - Util::ERROR("EvalGraph: trying to evaluate a BasePWMap"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate a SetBinOp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::CanonPWMap v) const +EvalGraphType EvalGraph::operator()(AST::LinearExp v) const { - Util::ERROR("EvalGraph: trying to evaluate a CanonPWMap"); - return SBGBaseType(); + Util::ERROR("EvalGraph: trying to evaluate a LinearExp"); + return EvalGraphType(); } -SBGBaseType EvalGraph::operator()(LIB::BaseSBG v) const { return SBGBaseType(v); } +EvalGraphType EvalGraph::operator()(AST::LExpBinOp v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a LExpBinOp"); + return EvalGraphType(); +} -SBGBaseType EvalGraph::operator()(LIB::CanonSBG v) const { return SBGBaseType(v); } +EvalGraphType EvalGraph::operator()(AST::MDLExp v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a MDLExp"); + return EvalGraphType(); +} -SBGBaseType EvalGraph::operator()(LIB::BaseDSBG v) const { return SBGBaseType(v); } +EvalGraphType EvalGraph::operator()(AST::MDLExpBinOp v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a MDLExpBinOp"); + return EvalGraphType(); +} -SBGBaseType EvalGraph::operator()(LIB::CanonDSBG v) const { return SBGBaseType(v); } +EvalGraphType EvalGraph::operator()(AST::LinearMap v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a LinearMap"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::PWLMap v) const +{ + Util::ERROR("EvalGraph: trying to evaluate a PWLMap"); + return EvalGraphType(); +} + +EvalGraphType EvalGraph::operator()(AST::SBG v) const +{ + EvalSet visit_set(nmbr_dims_, env_); + EvalPWMap visit_pwmap(nmbr_dims_, env_); + + LIB::Set new_V = Apply(visit_set, v.V()); + LIB::PWMap new_Vmap = Apply(visit_pwmap, v.Vmap()); + + LIB::PWMap new_map1 = Apply(visit_pwmap, v.map1()); + LIB::PWMap new_map2 = Apply(visit_pwmap, v.map2()); + LIB::PWMap new_Emap = Apply(visit_pwmap, v.Emap()); + + return EvalGraphType(LIB::SBGraph(new_V, new_Vmap, new_map1, new_map2, new_Emap)); +} + +EvalGraphType EvalGraph::operator()(AST::DSBG v) const +{ + EvalSet visit_set(nmbr_dims_, env_); + EvalPWMap visit_pwmap(nmbr_dims_, env_); + + LIB::Set new_V = Apply(visit_set, v.V()); + LIB::PWMap new_Vmap = Apply(visit_pwmap, v.Vmap()); + + LIB::PWMap new_mapB = Apply(visit_pwmap, v.mapB()); + LIB::PWMap new_mapD = Apply(visit_pwmap, v.mapD()); + LIB::PWMap new_Emap = Apply(visit_pwmap, v.Emap()); + + return EvalGraphType(LIB::SBGraph(new_V, new_Vmap, new_mapB, new_mapD, new_Emap)); +} } // namespace Eval diff --git a/eval/visitors/eval_graph.hpp b/eval/visitors/eval_graph.hpp old mode 100755 new mode 100644 index af5890d..d81082a --- a/eval/visitors/eval_graph.hpp +++ b/eval/visitors/eval_graph.hpp @@ -1,6 +1,6 @@ /** @file eval_graph.hpp - @brief Graph base type evaluator + @brief Graph expression evaluator
@@ -24,31 +24,55 @@ #ifndef AST_VISITOR_EVAL_GRAPH #define AST_VISITOR_EVAL_GRAPH -#include "eval/defs.hpp" +#include "eval/visitors/eval_pwmap.hpp" namespace SBG { namespace Eval { -struct EvalGraph : public boost::static_visitor { +struct EvalGraphType { + member_class(LIB::SBGraph, sbg); + member_class(LIB::DSBGraph, dsbg); + + EvalGraphType(); + EvalGraphType(LIB::SBGraph sbg); + EvalGraphType(LIB::DSBGraph dsbg); +}; + +struct EvalGraph : public boost::static_visitor { public: - SBGBaseType operator()(Util::NAT v) const; - SBGBaseType operator()(Util::MD_NAT v) const; - SBGBaseType operator()(Util::RATIONAL v) const; - SBGBaseType operator()(LIB::Interval v) const; - SBGBaseType operator()(LIB::SetPiece v) const; - SBGBaseType operator()(LIB::UnordSet v) const; - SBGBaseType operator()(LIB::OrdSet v) const; - SBGBaseType operator()(LIB::LExp v) const; - SBGBaseType operator()(LIB::Exp v) const; - SBGBaseType operator()(LIB::BaseMap v) const; - SBGBaseType operator()(LIB::CanonMap v) const; - SBGBaseType operator()(LIB::BasePWMap v) const; - SBGBaseType operator()(LIB::CanonPWMap v) const; - SBGBaseType operator()(LIB::BaseSBG v) const; - SBGBaseType operator()(LIB::CanonSBG v) const; - SBGBaseType operator()(LIB::BaseDSBG v) const; - SBGBaseType operator()(LIB::CanonDSBG v) const; + EvalGraph(); + EvalGraph(unsigned int nmbr_dims, VarEnv env); + + EvalGraphType operator()(AST::Natural v) const; + EvalGraphType operator()(AST::MDNatural v) const; + EvalGraphType operator()(AST::Rational v) const; + EvalGraphType operator()(AST::Boolean v) const; + EvalGraphType operator()(Util::VariableName v) const; + EvalGraphType operator()(AST::UnaryOp v) const; + EvalGraphType operator()(AST::BinOp v) const; + EvalGraphType operator()(AST::Call v) const; + EvalGraphType operator()(AST::Interval v) const; + EvalGraphType operator()(AST::InterUnaryOp v) const; + EvalGraphType operator()(AST::InterBinOp v) const; + EvalGraphType operator()(AST::MultiDimInter v) const; + EvalGraphType operator()(AST::MDInterUnaryOp v) const; + EvalGraphType operator()(AST::MDInterBinOp v) const; + EvalGraphType operator()(AST::Set v) const; + EvalGraphType operator()(AST::SetUnaryOp v) const; + EvalGraphType operator()(AST::SetBinOp v) const; + EvalGraphType operator()(AST::LinearExp v) const; + EvalGraphType operator()(AST::LExpBinOp v) const; + EvalGraphType operator()(AST::MDLExp v) const; + EvalGraphType operator()(AST::MDLExpBinOp v) const; + EvalGraphType operator()(AST::LinearMap v) const; + EvalGraphType operator()(AST::PWLMap v) const; + EvalGraphType operator()(AST::SBG v) const; + EvalGraphType operator()(AST::DSBG v) const; + + private: + unsigned int nmbr_dims_; + mutable VarEnv env_; }; } // namespace Eval diff --git a/eval/visitors/eval_le.hpp b/eval/visitors/eval_le.hpp index 862671a..081775a 100755 --- a/eval/visitors/eval_le.hpp +++ b/eval/visitors/eval_le.hpp @@ -26,7 +26,6 @@ #include "eval/visitors/eval_nat.hpp" #include "eval/visitors/eval_rat.hpp" -#include "sbg/lexp.hpp" namespace SBG { diff --git a/eval/visitors/eval_linear.cpp b/eval/visitors/eval_linear.cpp deleted file mode 100755 index 459574b..0000000 --- a/eval/visitors/eval_linear.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_linear.hpp" - -namespace SBG { - -namespace Eval { - -LinearBaseType EvalLinear::operator()(Util::NAT v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a NAT"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(Util::MD_NAT v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a MD_NAT"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(Util::RATIONAL v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a RATIONAL"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::Interval v) const -{ - Util::ERROR("EvalLinear: trying to evaluate an Interval"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::SetPiece v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a SetPiece"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::UnordSet v) const -{ - Util::ERROR("EvalLinear: trying to evaluate an UnordSet"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::OrdSet v) const -{ - Util::ERROR("EvalLinear: trying to evaluate an OrdSet"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::LExp v) const { return LinearBaseType(v); } - -LinearBaseType EvalLinear::operator()(LIB::Exp v) const { return LinearBaseType(v); } - -LinearBaseType EvalLinear::operator()(LIB::BaseMap v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a BaseMap"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::CanonMap v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a CanonMap"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::BasePWMap v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a BasePWMap"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::CanonPWMap v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a CanonPWMap"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::BaseSBG v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a BaseSBG"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::CanonSBG v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a CanonSBG"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::BaseDSBG v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a BaseDSBG"); - return LinearBaseType(); -} - -LinearBaseType EvalLinear::operator()(LIB::CanonDSBG v) const -{ - Util::ERROR("EvalLinear: trying to evaluate a CanonDSBG"); - return LinearBaseType(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_linear.hpp b/eval/visitors/eval_linear.hpp deleted file mode 100755 index 4cc15b2..0000000 --- a/eval/visitors/eval_linear.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/** @file eval_linear.hpp - - @brief Linear base type evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_LINEAR -#define AST_VISITOR_EVAL_LINEAR - -#include - -#include "eval/defs.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalLinear : public boost::static_visitor { - public: - LinearBaseType operator()(Util::NAT v) const; - LinearBaseType operator()(Util::MD_NAT v) const; - LinearBaseType operator()(Util::RATIONAL v) const; - LinearBaseType operator()(LIB::Interval v) const; - LinearBaseType operator()(LIB::SetPiece v) const; - LinearBaseType operator()(LIB::UnordSet v) const; - LinearBaseType operator()(LIB::OrdSet v) const; - LinearBaseType operator()(LIB::LExp v) const; - LinearBaseType operator()(LIB::Exp v) const; - LinearBaseType operator()(LIB::BaseMap v) const; - LinearBaseType operator()(LIB::CanonMap v) const; - LinearBaseType operator()(LIB::BasePWMap v) const; - LinearBaseType operator()(LIB::CanonPWMap v) const; - LinearBaseType operator()(LIB::BaseSBG v) const; - LinearBaseType operator()(LIB::CanonSBG v) const; - LinearBaseType operator()(LIB::BaseDSBG v) const; - LinearBaseType operator()(LIB::CanonDSBG v) const; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_map.cpp b/eval/visitors/eval_map.cpp old mode 100755 new mode 100644 index 8a8af62..b43c512 --- a/eval/visitors/eval_map.cpp +++ b/eval/visitors/eval_map.cpp @@ -23,90 +23,171 @@ namespace SBG { namespace Eval { -MapBaseType EvalMap::operator()(Util::NAT v) const +EvalMap::EvalMap() : nmbr_dims_(), env_() {} +EvalMap::EvalMap(unsigned int nmbr_dims, VarEnv env) : nmbr_dims_(nmbr_dims), env_(env) {} + +LIB::SBGMap EvalMap::operator()(AST::Natural v) const { - Util::ERROR("EvalMap: trying to evaluate a NAT"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a Natural"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(Util::MD_NAT v) const +LIB::SBGMap EvalMap::operator()(AST::MDNatural v) const { - Util::ERROR("EvalMap: trying to evaluate a MD_NAT"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a MDNatural"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(Util::RATIONAL v) const -{ - Util::ERROR("EvalMap: trying to evaluate a RATIONAL"); - return MapBaseType(); +LIB::SBGMap EvalMap::operator()(AST::Rational v) const +{ + Util::ERROR("EvalMap: trying to evaluate a Rational"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::Boolean v) const +{ + Util::ERROR("EvalMap: trying to evaluate a Boolean"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(Util::VariableName v) const +{ + MaybeEBT v_opt = env_[v]; + if (v_opt) { + ExprBaseType value = *v_opt; + if (is(value)) + return boost::get(value); + + else { + Util::ERROR("EvalMap: variable %s is not a linear expression", v.c_str()); + return LIB::SBGMap(); + } + } + + Util::ERROR("EvalMap: variable %s not defined", v.c_str()); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::Interval v) const +LIB::SBGMap EvalMap::operator()(AST::UnaryOp v) const { + Util::ERROR("EvalMap: trying to evaluate an arithmetic UnaryOp"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::BinOp v) const +{ + Util::ERROR("EvalMap: trying to evaluate an arithmetic BinOp"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::Call v) const +{ + Util::ERROR("EvalMap: trying to evaluate a Call"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::Interval v) const +{ Util::ERROR("EvalMap: trying to evaluate an Interval"); - return MapBaseType(); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::SetPiece v) const +LIB::SBGMap EvalMap::operator()(AST::InterUnaryOp v) const { - Util::ERROR("EvalMap: trying to evaluate a SetPiece"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate an InterUnaryOp"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::UnordSet v) const +LIB::SBGMap EvalMap::operator()(AST::InterBinOp v) const { - Util::ERROR("EvalMap: trying to evaluate an UnordSet"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate an InterBinOp"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::OrdSet v) const +LIB::SBGMap EvalMap::operator()(AST::MultiDimInter v) const +{ + Util::ERROR("EvalMap: trying to evaluate an MultiDimInter"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::MDInterUnaryOp v) const +{ + Util::ERROR("EvalMap: trying to evaluate an MDInterUnaryOp"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::MDInterBinOp v) const +{ + Util::ERROR("EvalMap: trying to evaluate an MDInterBinOp"); + return LIB::SBGMap(); +} + +LIB::SBGMap EvalMap::operator()(AST::Set v) const { - Util::ERROR("EvalMap: trying to evaluate an OrdSet"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a Set"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::LExp v) const +LIB::SBGMap EvalMap::operator()(AST::SetUnaryOp v) const { - Util::ERROR("EvalMap: trying to evaluate a LExp"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a SetUnaryOp"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::Exp v) const +LIB::SBGMap EvalMap::operator()(AST::SetBinOp v) const { - Util::ERROR("EvalMap: trying to evaluate an Exp"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a SetBinOp"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::BaseMap v) const { return MapBaseType(v); } +LIB::SBGMap EvalMap::operator()(AST::LinearExp v) const +{ + Util::ERROR("EvalMap: trying to evaluate a LinearExp"); + return LIB::SBGMap(); +} -MapBaseType EvalMap::operator()(LIB::CanonMap v) const { return MapBaseType(v); } +LIB::SBGMap EvalMap::operator()(AST::LExpBinOp v) const +{ + Util::ERROR("EvalMap: trying to evaluate a LExpBinOp"); + return LIB::SBGMap(); +} -MapBaseType EvalMap::operator()(LIB::BasePWMap v) const { return MapBaseType(v); } +LIB::SBGMap EvalMap::operator()(AST::MDLExp v) const +{ + Util::ERROR("EvalMap: trying to evaluate a MDLExp"); + return LIB::SBGMap(); +} -MapBaseType EvalMap::operator()(LIB::CanonPWMap v) const { return MapBaseType(v); } +LIB::SBGMap EvalMap::operator()(AST::MDLExpBinOp v) const +{ + Util::ERROR("EvalMap: trying to evaluate a MDLExpBinOp"); + return LIB::SBGMap(); +} -MapBaseType EvalMap::operator()(LIB::BaseSBG v) const +LIB::SBGMap EvalMap::operator()(AST::LinearMap v) const { - Util::ERROR("EvalMap: trying to evaluate a a BaseSBG"); - return MapBaseType(); + EvalSet visit_set(nmbr_dims_, env_); + EvalMDLE visit_mdle(env_); + + return LIB::SBGMap(Apply(visit_set, v.dom()), Apply(visit_mdle, v.lexp())); } -MapBaseType EvalMap::operator()(LIB::CanonSBG v) const +LIB::SBGMap EvalMap::operator()(AST::PWLMap v) const { - Util::ERROR("EvalMap: trying to evaluate a CanonSBG"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a PWLMap"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::BaseDSBG v) const +LIB::SBGMap EvalMap::operator()(AST::SBG v) const { - Util::ERROR("EvalMap: trying to evaluate a a BaseDSBG"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a SBG"); + return LIB::SBGMap(); } -MapBaseType EvalMap::operator()(LIB::CanonDSBG v) const +LIB::SBGMap EvalMap::operator()(AST::DSBG v) const { - Util::ERROR("EvalMap: trying to evaluate a CanonDSBG"); - return MapBaseType(); + Util::ERROR("EvalMap: trying to evaluate a DSBG"); + return LIB::SBGMap(); } } // namespace Eval diff --git a/eval/visitors/eval_map.hpp b/eval/visitors/eval_map.hpp old mode 100755 new mode 100644 index 79dca14..365e0bc --- a/eval/visitors/eval_map.hpp +++ b/eval/visitors/eval_map.hpp @@ -1,6 +1,6 @@ /** @file eval_map.hpp - @brief Map base type evaluator + @brief Linear map expression evaluator
@@ -24,31 +24,48 @@ #ifndef AST_VISITOR_EVAL_MAP #define AST_VISITOR_EVAL_MAP -#include "eval/defs.hpp" +#include "eval/visitors/eval_mdle.hpp" +#include "eval/visitors/eval_set.hpp" +#include "sbg/map.hpp" namespace SBG { namespace Eval { -struct EvalMap : public boost::static_visitor { +struct EvalMap : public boost::static_visitor { public: - MapBaseType operator()(Util::NAT v) const; - MapBaseType operator()(Util::MD_NAT v) const; - MapBaseType operator()(Util::RATIONAL v) const; - MapBaseType operator()(LIB::Interval v) const; - MapBaseType operator()(LIB::SetPiece v) const; - MapBaseType operator()(LIB::UnordSet v) const; - MapBaseType operator()(LIB::OrdSet v) const; - MapBaseType operator()(LIB::LExp v) const; - MapBaseType operator()(LIB::Exp v) const; - MapBaseType operator()(LIB::BaseMap v) const; - MapBaseType operator()(LIB::CanonMap v) const; - MapBaseType operator()(LIB::BasePWMap v) const; - MapBaseType operator()(LIB::CanonPWMap v) const; - MapBaseType operator()(LIB::BaseSBG v) const; - MapBaseType operator()(LIB::CanonSBG v) const; - MapBaseType operator()(LIB::BaseDSBG v) const; - MapBaseType operator()(LIB::CanonDSBG v) const; + EvalMap(); + EvalMap(unsigned int nmbr_dims_, VarEnv env); + + LIB::SBGMap operator()(AST::Natural v) const; + LIB::SBGMap operator()(AST::MDNatural v) const; + LIB::SBGMap operator()(AST::Rational v) const; + LIB::SBGMap operator()(AST::Boolean v) const; + LIB::SBGMap operator()(Util::VariableName v) const; + LIB::SBGMap operator()(AST::UnaryOp v) const; + LIB::SBGMap operator()(AST::BinOp v) const; + LIB::SBGMap operator()(AST::Call v) const; + LIB::SBGMap operator()(AST::Interval v) const; + LIB::SBGMap operator()(AST::InterUnaryOp v) const; + LIB::SBGMap operator()(AST::InterBinOp v) const; + LIB::SBGMap operator()(AST::MultiDimInter v) const; + LIB::SBGMap operator()(AST::MDInterUnaryOp v) const; + LIB::SBGMap operator()(AST::MDInterBinOp v) const; + LIB::SBGMap operator()(AST::Set v) const; + LIB::SBGMap operator()(AST::SetUnaryOp v) const; + LIB::SBGMap operator()(AST::SetBinOp v) const; + LIB::SBGMap operator()(AST::LinearExp v) const; + LIB::SBGMap operator()(AST::LExpBinOp v) const; + LIB::SBGMap operator()(AST::MDLExp v) const; + LIB::SBGMap operator()(AST::MDLExpBinOp v) const; + LIB::SBGMap operator()(AST::LinearMap v) const; + LIB::SBGMap operator()(AST::PWLMap v) const; + LIB::SBGMap operator()(AST::SBG v) const; + LIB::SBGMap operator()(AST::DSBG v) const; + + private: + unsigned int nmbr_dims_; + mutable VarEnv env_; }; } // namespace Eval diff --git a/eval/visitors/eval_mdi.cpp b/eval/visitors/eval_mdi.cpp index 6f929cd..d70938c 100755 --- a/eval/visitors/eval_mdi.cpp +++ b/eval/visitors/eval_mdi.cpp @@ -109,7 +109,7 @@ LIB::MultiDimInter EvalMDI::operator()(AST::MultiDimInter v) const LIB::MultiDimInter res; EvalInterval visit_inter(env_); - BOOST_FOREACH (AST::Expr ith, v.intervals()) res.emplaceBack(Apply(visit_inter, ith)); + for (AST::Expr ith : v.intervals()) res.emplaceBack(Apply(visit_inter, ith)); return res; } diff --git a/eval/visitors/eval_mdle.cpp b/eval/visitors/eval_mdle.cpp index 2001839..9a34bec 100755 --- a/eval/visitors/eval_mdle.cpp +++ b/eval/visitors/eval_mdle.cpp @@ -157,7 +157,7 @@ LIB::Exp EvalMDLE::operator()(AST::MDLExp v) const LIB::Exp res; EvalLE visit_le(env_); - BOOST_FOREACH (AST::Expr le, v.exps()) + for (AST::Expr le : v.exps()) res.emplaceBack(Apply(visit_le, le)); return LIB::Exp(res); diff --git a/eval/visitors/eval_mdle.hpp b/eval/visitors/eval_mdle.hpp index 7279ff2..8c9e018 100755 --- a/eval/visitors/eval_mdle.hpp +++ b/eval/visitors/eval_mdle.hpp @@ -25,7 +25,6 @@ #define AST_VISITOR_EVAL_MDLE #include "eval/visitors/eval_le.hpp" -#include "sbg/multidim_lexp.hpp" namespace SBG { diff --git a/eval/visitors/eval_mdnat.cpp b/eval/visitors/eval_mdnat.cpp index c76d309..1c97bea 100755 --- a/eval/visitors/eval_mdnat.cpp +++ b/eval/visitors/eval_mdnat.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include "eval/visitors/eval_nat.hpp" +#include "eval/visitors/eval_mdnat.hpp" namespace SBG { @@ -35,9 +35,10 @@ Util::MD_NAT EvalMDNat::operator()(AST::Natural v) const Util::MD_NAT EvalMDNat::operator()(AST::MDNatural v) const { return v; } Util::MD_NAT EvalMDNat::operator()(AST::Rational v) const -{ - if (v.denominator() == 1) - return v.numerator(); +{ + EvalNat visit_nat(env_); + if (Apply(visit_nat, v.den()) == 1) + return Util::MD_NAT(Apply(visit_nat, v.num())); Util::ERROR("EvalMDNat: trying to evaluate a Rational"); return 0; @@ -71,26 +72,8 @@ Util::MD_NAT EvalMDNat::operator()(AST::UnaryOp v) const Util::MD_NAT EvalMDNat::operator()(AST::BinOp v) const { - AST::Expr l = v.left(), r = v.right(); - switch (v.op()) { - case AST::Op::add: - return ApplyThis(l) + ApplyThis(r); - - case AST::Op::sub: - return ApplyThis(l) - ApplyThis(r); - - case AST::Op::mult: - return ApplyThis(l) * ApplyThis(r); - - case AST::Op::expo: - return pow(ApplyThis(l), ApplyThis(r)); - - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalMDNat: BinOp %s not supported.", ss.str().c_str()); - return 0; - } + Util::ERROR("EvalMDNat: trying to evaluate a BinOp"); + return 0; } Util::MD_NAT EvalMDNat::operator()(AST::Call v) const diff --git a/eval/visitors/eval_natbt.cpp b/eval/visitors/eval_natbt.cpp deleted file mode 100755 index c78c35c..0000000 --- a/eval/visitors/eval_natbt.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_natbt.hpp" - -namespace SBG { - -namespace Eval { - -NatBaseType EvalNatBT::operator()(Util::NAT v) const { return NatBaseType(v); } - -NatBaseType EvalNatBT::operator()(Util::MD_NAT v) const { return NatBaseType(v); } - -NatBaseType EvalNatBT::operator()(Util::RATIONAL v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a RATIONAL"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::Interval v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate an Interval"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::SetPiece v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a SetPiece"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::UnordSet v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate an UnordSet"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::OrdSet v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate an OrdSet"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::LExp v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a LExp"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::Exp v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate an Exp"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::BaseMap v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a BaseMap"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::CanonMap v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a CanonMap"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::BasePWMap v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a BasePWMap"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::CanonPWMap v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a CanonPWMap"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::BaseSBG v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a BaseSBG"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::CanonSBG v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a CanonSBG"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::BaseDSBG v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a BaseDSBG"); - return NatBaseType(); -} - -NatBaseType EvalNatBT::operator()(LIB::CanonDSBG v) const -{ - Util::ERROR("EvalNatBT: trying to evaluate a CanonDSBG"); - return NatBaseType(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_natbt.hpp b/eval/visitors/eval_natbt.hpp deleted file mode 100755 index f50530b..0000000 --- a/eval/visitors/eval_natbt.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** @file eval_natbt.hpp - - @brief Natural base type evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_NATBT -#define AST_VISITOR_EVAL_NATBT - -#include "eval/defs.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalNatBT : public boost::static_visitor { - public: - NatBaseType operator()(Util::NAT v) const; - NatBaseType operator()(Util::MD_NAT v) const; - NatBaseType operator()(Util::RATIONAL v) const; - NatBaseType operator()(LIB::Interval v) const; - NatBaseType operator()(LIB::SetPiece v) const; - NatBaseType operator()(LIB::UnordSet v) const; - NatBaseType operator()(LIB::OrdSet v) const; - NatBaseType operator()(LIB::LExp v) const; - NatBaseType operator()(LIB::Exp v) const; - NatBaseType operator()(LIB::BaseMap v) const; - NatBaseType operator()(LIB::CanonMap v) const; - NatBaseType operator()(LIB::BasePWMap v) const; - NatBaseType operator()(LIB::CanonPWMap v) const; - NatBaseType operator()(LIB::BaseSBG v) const; - NatBaseType operator()(LIB::CanonSBG v) const; - NatBaseType operator()(LIB::BaseDSBG v) const; - NatBaseType operator()(LIB::CanonDSBG v) const; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_ord_set.cpp b/eval/visitors/eval_ord_set.cpp deleted file mode 100755 index b64fc5e..0000000 --- a/eval/visitors/eval_ord_set.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_ord_set.hpp" - -namespace SBG { - -namespace Eval { - -EvalOrdSet::EvalOrdSet() : env_() {} -EvalOrdSet::EvalOrdSet(VarEnv env) : env_(env) {} - -LIB::OrdSet EvalOrdSet::operator()(AST::Natural v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a Natural"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a MDNatural"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::Rational v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a Rational"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a Boolean"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalOrdSet: variable %s is not a set", v.c_str()); - return LIB::OrdSet(); - } - } - - Util::ERROR("EvalOrdSet: variable %s not defined", v.c_str()); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an arithmetic UnaryOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an arithmetic BinOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::Call v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a Call"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::Interval v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an Interval"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an InterUnaryOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an InterBinOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an MultiDimInter"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an MDInterUnaryOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate an MDInterBinOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::Set v) const -{ - LIB::OrdSet res; - - EvalMDI mdi_visit(env_); - BOOST_FOREACH (AST::Expr e, v.pieces()) res.emplace_hint(res.end(), Apply(mdi_visit, e)); - - return res; -} - -LIB::OrdSet EvalOrdSet::operator()(AST::SetUnaryOp v) const -{ - AST::Expr e = v.e(); - switch (v.op()) { - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalOrdSet: SetUnaryOp %s not supported.", ss.str().c_str()); - return LIB::OrdSet(); - } -} - -LIB::OrdSet EvalOrdSet::operator()(AST::SetBinOp v) const -{ - AST::Expr l = v.left(), r = v.right(); - switch (v.op()) { - case AST::ContainerOp::cap: - return intersection(ApplyThis(l), ApplyThis(r)); - - case AST::ContainerOp::diff: - return difference(ApplyThis(l), ApplyThis(r)); - - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalOrdSet: SetBinOp %s not supported.", ss.str().c_str()); - return LIB::OrdSet(); - } -} - -LIB::OrdSet EvalOrdSet::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a LinearExp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a LExpBinOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a MDLExp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a MDLExpBinOp"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a LinearMap"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a PWLMap"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::SBG v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a SBG"); - return LIB::OrdSet(); -} - -LIB::OrdSet EvalOrdSet::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalOrdSet: trying to evaluate a DSBG"); - return LIB::OrdSet(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_ord_set.hpp b/eval/visitors/eval_ord_set.hpp deleted file mode 100755 index 8eeae68..0000000 --- a/eval/visitors/eval_ord_set.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/** @file eval_ord_set.hpp - - @brief Ordered set expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_ORD_SET -#define AST_VISITOR_EVAL_ORD_SET - -#include "eval/visitors/eval_mdi.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalOrdSet : public boost::static_visitor { - public: - EvalOrdSet(); - EvalOrdSet(VarEnv env); - - LIB::OrdSet operator()(AST::Natural v) const; - LIB::OrdSet operator()(AST::MDNatural v) const; - LIB::OrdSet operator()(AST::Rational v) const; - LIB::OrdSet operator()(AST::Boolean v) const; - LIB::OrdSet operator()(Util::VariableName v) const; - LIB::OrdSet operator()(AST::UnaryOp v) const; - LIB::OrdSet operator()(AST::BinOp v) const; - LIB::OrdSet operator()(AST::Call v) const; - LIB::OrdSet operator()(AST::Interval v) const; - LIB::OrdSet operator()(AST::InterUnaryOp v) const; - LIB::OrdSet operator()(AST::InterBinOp v) const; - LIB::OrdSet operator()(AST::MultiDimInter v) const; - LIB::OrdSet operator()(AST::MDInterUnaryOp v) const; - LIB::OrdSet operator()(AST::MDInterBinOp v) const; - LIB::OrdSet operator()(AST::Set v) const; - LIB::OrdSet operator()(AST::SetUnaryOp v) const; - LIB::OrdSet operator()(AST::SetBinOp v) const; - LIB::OrdSet operator()(AST::LinearExp v) const; - LIB::OrdSet operator()(AST::LExpBinOp v) const; - LIB::OrdSet operator()(AST::MDLExp v) const; - LIB::OrdSet operator()(AST::MDLExpBinOp v) const; - LIB::OrdSet operator()(AST::LinearMap v) const; - LIB::OrdSet operator()(AST::PWLMap v) const; - LIB::OrdSet operator()(AST::SBG v) const; - LIB::OrdSet operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/eval_pwmap.cpp b/eval/visitors/eval_pwmap.cpp new file mode 100755 index 0000000..04c1e96 --- /dev/null +++ b/eval/visitors/eval_pwmap.cpp @@ -0,0 +1,197 @@ +/******************************************************************************* + + 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 . + + ******************************************************************************/ + +#include "eval/visitors/eval_pwmap.hpp" + +namespace SBG { + +namespace Eval { + +EvalPWMap::EvalPWMap() : nmbr_dims_(), env_() {} +EvalPWMap::EvalPWMap(unsigned int nmbr_dims, VarEnv env) : nmbr_dims_(nmbr_dims), env_(env) {} + +LIB::PWMap EvalPWMap::operator()(AST::Natural v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a Natural"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MDNatural v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a MDNatural"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::Rational v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a Rational"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::Boolean v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a Boolean"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(Util::VariableName v) const +{ + MaybeEBT v_opt = env_[v]; + if (v_opt) { + ExprBaseType value = *v_opt; + if (is(value)) + return boost::get(value); + + else { + Util::ERROR("EvalPWMap: variable %s is not a linear expression", v.c_str()); + return LIB::PWMap(); + } + } + + Util::ERROR("EvalPWMap: variable %s not defined", v.c_str()); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::UnaryOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an arithmetic UnaryOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::BinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an arithmetic BinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::Call v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a Call"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::Interval v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an Interval"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::InterUnaryOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an InterUnaryOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::InterBinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an InterBinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MultiDimInter v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an MultiDimInter"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MDInterUnaryOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an MDInterUnaryOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MDInterBinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate an MDInterBinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::Set v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a Set"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::SetUnaryOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a SetUnaryOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::SetBinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a SetBinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::LinearExp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a LinearExp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::LExpBinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a LExpBinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MDLExp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a MDLExp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::MDLExpBinOp v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a MDLExpBinOp"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::LinearMap v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a LinearMap"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::PWLMap v) const +{ + LIB::PWMap res; + + EvalMap visit_map(nmbr_dims_, env_); + for (AST::Expr sbgmap : v.maps()) res.emplaceBack(Apply(visit_map, sbgmap)); + + return res; +} + +LIB::PWMap EvalPWMap::operator()(AST::SBG v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a SBG"); + return LIB::PWMap(); +} + +LIB::PWMap EvalPWMap::operator()(AST::DSBG v) const +{ + Util::ERROR("EvalPWMap: trying to evaluate a DSBG"); + return LIB::PWMap(); +} + +} // namespace Eval + +} // namespace SBG diff --git a/eval/visitors/eval_pwmap.hpp b/eval/visitors/eval_pwmap.hpp new file mode 100755 index 0000000..5e6062d --- /dev/null +++ b/eval/visitors/eval_pwmap.hpp @@ -0,0 +1,73 @@ +/** @file eval_pwmap.hpp + + @brief PWLMap AST expression evaluator + +
+ + 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 . + + ******************************************************************************/ + +#ifndef AST_VISITOR_EVAL_PWMAP +#define AST_VISITOR_EVAL_PWMAP + +#include "eval/visitors/eval_map.hpp" + +namespace SBG { + +namespace Eval { + +struct EvalPWMap : public boost::static_visitor { + public: + EvalPWMap(); + EvalPWMap(unsigned int nmbr_dims_, VarEnv env); + + LIB::PWMap operator()(AST::Natural v) const; + LIB::PWMap operator()(AST::MDNatural v) const; + LIB::PWMap operator()(AST::Rational v) const; + LIB::PWMap operator()(AST::Boolean v) const; + LIB::PWMap operator()(Util::VariableName v) const; + LIB::PWMap operator()(AST::UnaryOp v) const; + LIB::PWMap operator()(AST::BinOp v) const; + LIB::PWMap operator()(AST::Call v) const; + LIB::PWMap operator()(AST::Interval v) const; + LIB::PWMap operator()(AST::InterUnaryOp v) const; + LIB::PWMap operator()(AST::InterBinOp v) const; + LIB::PWMap operator()(AST::MultiDimInter v) const; + LIB::PWMap operator()(AST::MDInterUnaryOp v) const; + LIB::PWMap operator()(AST::MDInterBinOp v) const; + LIB::PWMap operator()(AST::Set v) const; + LIB::PWMap operator()(AST::SetUnaryOp v) const; + LIB::PWMap operator()(AST::SetBinOp v) const; + LIB::PWMap operator()(AST::LinearExp v) const; + LIB::PWMap operator()(AST::LExpBinOp v) const; + LIB::PWMap operator()(AST::MDLExp v) const; + LIB::PWMap operator()(AST::MDLExpBinOp v) const; + LIB::PWMap operator()(AST::LinearMap v) const; + LIB::PWMap operator()(AST::PWLMap v) const; + LIB::PWMap operator()(AST::SBG v) const; + LIB::PWMap operator()(AST::DSBG v) const; + + private: + unsigned int nmbr_dims_; + mutable VarEnv env_; +}; + +} // namespace Eval + +} // namespace SBG + +#endif diff --git a/eval/visitors/eval_set.cpp b/eval/visitors/eval_set.cpp new file mode 100644 index 0000000..a3549db --- /dev/null +++ b/eval/visitors/eval_set.cpp @@ -0,0 +1,225 @@ +/******************************************************************************* + + 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 . + + ******************************************************************************/ + +#include "eval/visitors/eval_set.hpp" + +namespace SBG { + +namespace Eval { + +EvalSet::EvalSet() : nmbr_dims_(), env_() {} +EvalSet::EvalSet(unsigned int nmbr_dims, VarEnv env) : nmbr_dims_(nmbr_dims), env_(env) {} + +LIB::Set EvalSet::operator()(AST::Natural v) const +{ + Util::ERROR("EvalSet: trying to evaluate a Natural"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MDNatural v) const +{ + Util::ERROR("EvalSet: trying to evaluate a MDNatural"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::Rational v) const +{ + Util::ERROR("EvalSet: trying to evaluate a Rational"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::Boolean v) const +{ + Util::ERROR("EvalSet: trying to evaluate a Boolean"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(Util::VariableName v) const +{ + MaybeEBT v_opt = env_[v]; + if (v_opt) { + ExprBaseType value = *v_opt; + if (is(value)) + return boost::get(value); + + else { + Util::ERROR("EvalSet: variable %s is not a set", v.c_str()); + return LIB::Set(); + } + } + + Util::ERROR("EvalSet: variable %s not defined", v.c_str()); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::UnaryOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an arithmetic UnaryOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::BinOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an arithmetic BinOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::Call v) const +{ + Util::ERROR("EvalSet: trying to evaluate a Call"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::Interval v) const +{ + Util::ERROR("EvalSet: trying to evaluate an Interval"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::InterUnaryOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an InterUnaryOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::InterBinOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an InterBinOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MultiDimInter v) const +{ + Util::ERROR("EvalSet: trying to evaluate an MultiDimInter"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MDInterUnaryOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an MDInterUnaryOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MDInterBinOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate an MDInterBinOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::Set v) const +{ + EvalMDI mdi_visit(env_); + + if (nmbr_dims_ == 1) { + LIB::OrdSet ord_res; + for (AST::Expr e : v.pieces()) ord_res.emplace_hint(ord_res.end(), Apply(mdi_visit, e)); + + return ord_res; + } + + LIB::UnordSet unord_res; + for (AST::Expr e : v.pieces()) unord_res.emplace_hint(unord_res.end(), Apply(mdi_visit, e)); + + return unord_res; +} + +LIB::Set EvalSet::operator()(AST::SetUnaryOp v) const +{ + AST::Expr e = v.e(); + switch (v.op()) { + default: + std::stringstream ss; + ss << v.op(); + Util::ERROR("EvalSet: SetUnaryOp %s not supported.", ss.str().c_str()); + return LIB::Set(); + } +} + +LIB::Set EvalSet::operator()(AST::SetBinOp v) const +{ + LIB::Set l = ApplyThis(v.left()), r = ApplyThis(v.right()); + switch (v.op()) { + case AST::ContainerOp::cap: + return intersection(l, r); + + case AST::ContainerOp::cup: + return cup(l, r); + + case AST::ContainerOp::diff: + return difference(l, r); + + default: + std::stringstream ss; + ss << v.op(); + Util::ERROR("EvalSet: SetBinOp %s not supported.", ss.str().c_str()); + return LIB::Set(); + } +} + +LIB::Set EvalSet::operator()(AST::LinearExp v) const +{ + Util::ERROR("EvalSet: trying to evaluate a LinearExp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::LExpBinOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate a LExpBinOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MDLExp v) const +{ + Util::ERROR("EvalSet: trying to evaluate a MDLExp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::MDLExpBinOp v) const +{ + Util::ERROR("EvalSet: trying to evaluate a MDLExpBinOp"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::LinearMap v) const +{ + Util::ERROR("EvalSet: trying to evaluate a LinearMap"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::PWLMap v) const +{ + Util::ERROR("EvalSet: trying to evaluate a PWLMap"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::SBG v) const +{ + Util::ERROR("EvalSet: trying to evaluate a SBG"); + return LIB::Set(); +} + +LIB::Set EvalSet::operator()(AST::DSBG v) const +{ + Util::ERROR("EvalSet: trying to evaluate a DSBG"); + return LIB::Set(); +} + +} // namespace Eval + +} // namespace SBG diff --git a/eval/visitors/eval_set.hpp b/eval/visitors/eval_set.hpp new file mode 100644 index 0000000..24cd50a --- /dev/null +++ b/eval/visitors/eval_set.hpp @@ -0,0 +1,73 @@ +/** @file eval_set.hpp + + @brief Set expression evaluator + +
+ + 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 . + + ******************************************************************************/ + +#ifndef AST_VISITOR_EVAL_SET +#define AST_VISITOR_EVAL_SET + +#include "eval/visitors/eval_mdi.hpp" + +namespace SBG { + +namespace Eval { + +struct EvalSet : public boost::static_visitor { + public: + EvalSet(); + EvalSet(unsigned int nmbr_dims, VarEnv env); + + LIB::Set operator()(AST::Natural v) const; + LIB::Set operator()(AST::MDNatural v) const; + LIB::Set operator()(AST::Rational v) const; + LIB::Set operator()(AST::Boolean v) const; + LIB::Set operator()(Util::VariableName v) const; + LIB::Set operator()(AST::UnaryOp v) const; + LIB::Set operator()(AST::BinOp v) const; + LIB::Set operator()(AST::Call v) const; + LIB::Set operator()(AST::Interval v) const; + LIB::Set operator()(AST::InterUnaryOp v) const; + LIB::Set operator()(AST::InterBinOp v) const; + LIB::Set operator()(AST::MultiDimInter v) const; + LIB::Set operator()(AST::MDInterUnaryOp v) const; + LIB::Set operator()(AST::MDInterBinOp v) const; + LIB::Set operator()(AST::Set v) const; + LIB::Set operator()(AST::SetUnaryOp v) const; + LIB::Set operator()(AST::SetBinOp v) const; + LIB::Set operator()(AST::LinearExp v) const; + LIB::Set operator()(AST::LExpBinOp v) const; + LIB::Set operator()(AST::MDLExp v) const; + LIB::Set operator()(AST::MDLExpBinOp v) const; + LIB::Set operator()(AST::LinearMap v) const; + LIB::Set operator()(AST::PWLMap v) const; + LIB::Set operator()(AST::SBG v) const; + LIB::Set operator()(AST::DSBG v) const; + + private: + unsigned int nmbr_dims_; + mutable VarEnv env_; +}; + +} // namespace Eval + +} // namespace SBG + +#endif diff --git a/eval/visitors/eval_unord_set.cpp b/eval/visitors/eval_unord_set.cpp deleted file mode 100755 index 09585ce..0000000 --- a/eval/visitors/eval_unord_set.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - - 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 . - - ******************************************************************************/ - -#include "eval/visitors/eval_unord_set.hpp" - -namespace SBG { - -namespace Eval { - -EvalUnordSet::EvalUnordSet() : env_() {} -EvalUnordSet::EvalUnordSet(VarEnv env) : env_(env) {} - -LIB::UnordSet EvalUnordSet::operator()(AST::Natural v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a Natural"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MDNatural v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a MDNatural"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::Rational v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a Rational"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::Boolean v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a Boolean"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(Util::VariableName v) const -{ - MaybeEBT v_opt = env_[v]; - if (v_opt) { - ExprBaseType value = *v_opt; - if (is(value)) - return boost::get(value); - - else { - Util::ERROR("EvalUnordSet: variable %s is not a set", v.c_str()); - return LIB::UnordSet(); - } - } - - Util::ERROR("EvalUnordSet: variable %s not defined", v.c_str()); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::UnaryOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an arithmetic UnaryOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::BinOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an arithmetic BinOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::Call v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a Call"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::Interval v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an Interval"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::InterUnaryOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an InterUnaryOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::InterBinOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an InterBinOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an MultiDimInter"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MDInterUnaryOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an MDInterUnaryOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MDInterBinOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate an MDInterBinOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::Set v) const -{ - LIB::UnordSet res; - - EvalMDI mdi_visit(env_); - BOOST_FOREACH (AST::Expr e, v.pieces()) res.emplace_hint(res.end(), Apply(mdi_visit, e)); - - return res; -} - -LIB::UnordSet EvalUnordSet::operator()(AST::SetUnaryOp v) const -{ - AST::Expr e = v.e(); - switch (v.op()) { - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalUnordSet: SetUnaryOp %s not supported.", ss.str().c_str()); - return LIB::UnordSet(); - } -} - -LIB::UnordSet EvalUnordSet::operator()(AST::SetBinOp v) const -{ - AST::Expr l = v.left(), r = v.right(); - switch (v.op()) { - case AST::ContainerOp::cap: - return intersection(ApplyThis(l), ApplyThis(r)); - - case AST::ContainerOp::diff: - return difference(ApplyThis(l), ApplyThis(r)); - - default: - std::stringstream ss; - ss << v.op(); - Util::ERROR("EvalUnordSet: SetBinOp %s not supported.", ss.str().c_str()); - return LIB::UnordSet(); - } -} - -LIB::UnordSet EvalUnordSet::operator()(AST::LinearExp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a LinearExp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::LExpBinOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a LExpBinOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MDLExp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a MDLExp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::MDLExpBinOp v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a MDLExpBinOp"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::LinearMap v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a LinearMap"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::PWLMap v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a PWLMap"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::SBG v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a SBG"); - return LIB::UnordSet(); -} - -LIB::UnordSet EvalUnordSet::operator()(AST::DSBG v) const -{ - Util::ERROR("EvalUnordSet: trying to evaluate a DSBG"); - return LIB::UnordSet(); -} - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/eval_unord_set.hpp b/eval/visitors/eval_unord_set.hpp deleted file mode 100755 index e1eebf6..0000000 --- a/eval/visitors/eval_unord_set.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/** @file eval_unord_set.hpp - - @brief Unordered set expression evaluator - -
- - 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 . - - ******************************************************************************/ - -#ifndef AST_VISITOR_EVAL_UNORD_SET -#define AST_VISITOR_EVAL_UNORD_SET - -#include "eval/visitors/eval_mdi.hpp" - -namespace SBG { - -namespace Eval { - -struct EvalUnordSet : public boost::static_visitor { - public: - EvalUnordSet(); - EvalUnordSet(VarEnv env); - - LIB::UnordSet operator()(AST::Natural v) const; - LIB::UnordSet operator()(AST::MDNatural v) const; - LIB::UnordSet operator()(AST::Rational v) const; - LIB::UnordSet operator()(AST::Boolean v) const; - LIB::UnordSet operator()(Util::VariableName v) const; - LIB::UnordSet operator()(AST::UnaryOp v) const; - LIB::UnordSet operator()(AST::BinOp v) const; - LIB::UnordSet operator()(AST::Call v) const; - LIB::UnordSet operator()(AST::Interval v) const; - LIB::UnordSet operator()(AST::InterUnaryOp v) const; - LIB::UnordSet operator()(AST::InterBinOp v) const; - LIB::UnordSet operator()(AST::MultiDimInter v) const; - LIB::UnordSet operator()(AST::MDInterUnaryOp v) const; - LIB::UnordSet operator()(AST::MDInterBinOp v) const; - LIB::UnordSet operator()(AST::Set v) const; - LIB::UnordSet operator()(AST::SetUnaryOp v) const; - LIB::UnordSet operator()(AST::SetBinOp v) const; - LIB::UnordSet operator()(AST::LinearExp v) const; - LIB::UnordSet operator()(AST::LExpBinOp v) const; - LIB::UnordSet operator()(AST::MDLExp v) const; - LIB::UnordSet operator()(AST::MDLExpBinOp v) const; - LIB::UnordSet operator()(AST::LinearMap v) const; - LIB::UnordSet operator()(AST::PWLMap v) const; - LIB::UnordSet operator()(AST::SBG v) const; - LIB::UnordSet operator()(AST::DSBG v) const; - - private: - mutable VarEnv env_; -}; - -} // namespace Eval - -} // namespace SBG - -#endif diff --git a/eval/visitors/program_visitor.cpp b/eval/visitors/program_visitor.cpp index 8ac7b3b..a7bbf4f 100755 --- a/eval/visitors/program_visitor.cpp +++ b/eval/visitors/program_visitor.cpp @@ -31,7 +31,7 @@ ProgramIO ProgramVisitor::operator()(AST::Program p) const AST::IsConfig cfg_visit; StmVisitor stm_visit; - BOOST_FOREACH (AST::Statement s, p.stms()) { + for (AST::Statement s : p.stms()) { if (Apply(cfg_visit, s)) { AST::ConfigDims cfg = boost::get(s); result.set_nmbr_dims(cfg.nmbr_dims()); @@ -43,9 +43,9 @@ ProgramIO ProgramVisitor::operator()(AST::Program p) const } } - EvalExpression eval_expr(result.nmbr_dims(), stm_visit.env()); - BOOST_FOREACH (AST::Expr e, p.exprs()) { - ExprBaseType expr_res = Apply(eval_expr, e); + EvalExpression visit_expr(result.nmbr_dims(), stm_visit.env()); + for (AST::Expr e : p.exprs()) { + ExprBaseType expr_res = Apply(visit_expr, e); result.exprs_ref().push_back(ExprEval(e, expr_res)); } diff --git a/eval/visitors/stm_visitor.cpp b/eval/visitors/stm_visitor.cpp index 8ff9f10..929a437 100755 --- a/eval/visitors/stm_visitor.cpp +++ b/eval/visitors/stm_visitor.cpp @@ -29,8 +29,8 @@ VarEnv StmVisitor::env() { return env_; } void StmVisitor::operator()(AST::Assign asgn) const { - EvalExpression eval_expr(env_); - env_.insert(asgn.l(), Apply(eval_expr, asgn.r())); + EvalExpression visit_expr(env_); + env_.insert(asgn.l(), Apply(visit_expr, asgn.r())); return; } diff --git a/sbg/Makefile.include b/sbg/Makefile.include index afe3a19..725eb9d 100755 --- a/sbg/Makefile.include +++ b/sbg/Makefile.include @@ -9,12 +9,14 @@ SBG_ROOT := sbg $(SBG_ROOT)/multidim_inter.cpp \ $(SBG_ROOT)/ord_pw_mdinter.cpp \ $(SBG_ROOT)/unord_pw_mdinter.cpp \ + $(SBG_ROOT)/set.cpp \ $(SBG_ROOT)/lexp.cpp \ $(SBG_ROOT)/multidim_lexp.cpp \ $(SBG_ROOT)/map.cpp \ + $(SBG_ROOT)/pw_map.cpp \ $(SBG_ROOT)/sbg.cpp \ $(SBG_ROOT)/sbg_algorithms.cpp \ - $(SBG_ROOT)/info.cpp + $(SBG_ROOT)/info.cpp # Objects SBG_OBJ=$(addprefix $(BUILD_DIR)/, $(SBG_SRC:.cpp=.o)) diff --git a/sbg/info.cpp b/sbg/info.cpp index fd930a8..5396a5f 100755 --- a/sbg/info.cpp +++ b/sbg/info.cpp @@ -53,7 +53,7 @@ std::ostream &operator<<(std::ostream &out, const DeclRanged &dr) std::ostream &operator<<(std::ostream &out, const DeclsRanged &ddr) { - BOOST_FOREACH (DeclRanged dr, ddr) out << dr << "\n"; + for (DeclRanged dr : ddr) out << dr << "\n"; return out; } @@ -72,7 +72,7 @@ std::ostream &operator<<(std::ostream &out, const VertexInfo &vi) std::ostream &operator<<(std::ostream &out, const VerticesInfo &vvi) { - BOOST_FOREACH (VertexInfo vi, vvi) out << vi << "\n"; + for (VertexInfo vi : vvi) out << vi << "\n"; return out; } @@ -107,7 +107,7 @@ std::ostream &operator<<(std::ostream &out, const UseRanged &ur) std::ostream &operator<<(std::ostream &out, const UsesRanged &uur) { - BOOST_FOREACH (UseRanged ur, uur) out << ur; + for (UseRanged ur : uur) out << ur; return out; } @@ -153,7 +153,7 @@ std::ostream &operator<<(std::ostream &out, const EdgeInfo &ei) std::ostream &operator<<(std::ostream &out, const EdgesInfo &eei) { - BOOST_FOREACH (EdgeInfo ei, eei) out << ei << "\n"; + for (EdgeInfo ei : eei) out << ei << "\n"; return out; } diff --git a/sbg/interval.hpp b/sbg/interval.hpp index 2eef696..8a12fd0 100755 --- a/sbg/interval.hpp +++ b/sbg/interval.hpp @@ -35,7 +35,6 @@ #include #include -#include #include #include "util/defs.hpp" diff --git a/sbg/map.cpp b/sbg/map.cpp index cd7ac88..17d2173 100755 --- a/sbg/map.cpp +++ b/sbg/map.cpp @@ -39,7 +39,10 @@ bool compatible(Interval i, LExp le) bool compatible(SetPiece mdi, Exp mdle) { - if (isEmpty(mdi)) return true; + if (isEmpty(mdi)) { + Util::ERROR("LIB::SBGMap::compatible: empty mdis not allowed"); + return false; + } if (mdi.size() == mdle.size()) { parallel_foreach2 (mdi.intervals_ref(), mdle.exps_ref()) { @@ -52,20 +55,31 @@ bool compatible(SetPiece mdi, Exp mdle) return true; } -template -SBGMap::SBGMap() : dom_(Set()), exp_(Exp()) {} -template -SBGMap::SBGMap(Interval i, LExp le) : dom_(Set(SetPiece(i))), exp_(Exp(le)) {} -template -SBGMap::SBGMap(Set dom, Exp exp) : dom_(dom), exp_(exp) { - BOOST_FOREACH (SetPiece mdi, dom) compatible(mdi, exp); +SBGMap::SBGMap() : dom_(Set()), exp_(Exp()) {} +SBGMap::SBGMap(Interval i, LExp le) : dom_(), exp_() { + if (compatible(i, le)) { + set_dom(Set(SetPiece(i))); + set_exp(Exp(le)); + } +} +SBGMap::SBGMap(SetPiece mdi, Exp mdle) : dom_(), exp_() { + if (compatible(mdi, mdle)) { + set_dom(Set(mdi)); + set_exp(mdle); + } +} +SBGMap::SBGMap(Set dom, Exp exp) : dom_(dom), exp_(exp) { + auto f = [exp](SetPiece mdi) { + compatible(mdi, exp); + return; + }; + foreach(f, dom); } -member_imp_temp(template, SBGMap, Set, dom); -member_imp_temp(template, SBGMap, Exp, exp); +member_imp(SBGMap, Set, dom); +member_imp(SBGMap, Exp, exp); -template -bool SBGMap::operator==(const SBGMap &other) const +bool SBGMap::operator==(const SBGMap &other) const { if (dom() == other.dom()) { if (cardinal(dom()) == 1) { @@ -78,11 +92,9 @@ bool SBGMap::operator==(const SBGMap &other) const return false; } -template -bool SBGMap::operator!=(const SBGMap &other) const { return !(*this == other); } +bool SBGMap::operator!=(const SBGMap &other) const { return !(*this == other); } -template -std::ostream &operator<<(std::ostream &out, const SBGMap &sbgmap) +std::ostream &operator<<(std::ostream &out, const SBGMap &sbgmap) { out << sbgmap.dom() << " ↦ " << sbgmap.exp(); @@ -91,8 +103,7 @@ std::ostream &operator<<(std::ostream &out, const SBGMap &sbgmap) // SBGMap functions ------------------------------------------------------------ -template -SBGMap restrict(Set subdom, SBGMap sbgmap) +SBGMap restrict(Set subdom, SBGMap sbgmap) { Set restricted_dom = intersection(sbgmap.dom_ref(), subdom); return SBGMap(restricted_dom, sbgmap.exp()); @@ -149,33 +160,27 @@ SetPiece image(SetPiece mdi, Exp mdle) return SetPiece(); } -template -Set image(SBGMap sbgmap) { return image(sbgmap.dom(), sbgmap);} +Set image(SBGMap sbgmap) { return image(sbgmap.dom(), sbgmap);} -template -Set image(Set subdom, SBGMap sbgmap) +Set image(Set subdom, SBGMap sbgmap) { Set res; Exp le = sbgmap.exp(); Set capdom = intersection(sbgmap.dom_ref(), subdom); - if (isEmpty(capdom)) return Set(); - else { - BOOST_FOREACH (SetPiece atom, capdom) { - SetPiece new_atom = image(atom, le); - res.emplace(new_atom); - } - } + auto f = [le, &res](SetPiece atom) { + SetPiece new_atom = image(atom, le); + res.emplace(new_atom); + }; + foreach(f, capdom); return res; } -template -Set preImage(SBGMap sbgmap) { return sbgmap.dom(); } +Set preImage(SBGMap sbgmap) { return sbgmap.dom(); } -template -Set preImage(Set subcodom, SBGMap sbgmap) +Set preImage(Set subcodom, SBGMap sbgmap) { SBGMap inv(image(sbgmap), inverse(sbgmap.exp())); Set im = image(sbgmap); @@ -185,8 +190,7 @@ Set preImage(Set subcodom, SBGMap sbgmap) return intersection(sbgmap.dom_ref(), inv_im); } -template -SBGMap composition(SBGMap sbgmap1, SBGMap sbgmap2) +SBGMap composition(SBGMap sbgmap1, SBGMap sbgmap2) { Set dom1 = sbgmap1.dom(), im2 = image(sbgmap2); Set res_dom = intersection(im2, dom1); @@ -198,23 +202,20 @@ SBGMap composition(SBGMap sbgmap1, SBGMap sbgmap2) // Extra functions ------------------------------------------------------------- -template -SBGMap minInv(Set d, SBGMap sbgmap) +SBGMap minInv(Set d, SBGMap sbgmap) { Set dom = sbgmap.dom(), res_dom = image(restrict(d, sbgmap)); Exp e = sbgmap.exp(); if (cardinal(dom) == 1 || isConstant(e)) - return SBGMap(res_dom, Exp(minElem(sbgmap.dom()))); + return SBGMap(res_dom, Exp(minElem(sbgmap.dom()))); - return SBGMap(res_dom, inverse(e)); + return SBGMap(res_dom, inverse(e)); } -template -SBGMap minInv(SBGMap sbgmap) { return minInv(sbgmap.dom(), sbgmap); } +SBGMap minInv(SBGMap sbgmap) { return minInv(sbgmap.dom(), sbgmap); } -template -bool isId(SBGMap sbgmap) +bool isId(SBGMap sbgmap) { if (cardinal(sbgmap.dom()) == 1) return sbgmap.dom() == image(sbgmap); @@ -222,11 +223,9 @@ bool isId(SBGMap sbgmap) } // Function should be called on a non-empty sbgmap -template -unsigned int nmbrDims(SBGMap sbgmap) { return sbgmap.dom().size(); } +unsigned int nmbrDims(SBGMap sbgmap) { return sbgmap.dom().size(); } -template -std::size_t hash_value(const SBGMap &sbgmap) +std::size_t hash_value(const SBGMap &sbgmap) { std::size_t seed = 0; boost::hash_combine(seed, sbgmap.dom()); @@ -235,36 +234,6 @@ std::size_t hash_value(const SBGMap &sbgmap) return seed; } -// Template instantiations ----------------------------------------------------- - -template struct SBGMap; -template std::ostream &operator<<(std::ostream &out, const BaseMap &sbgmap); -template BaseMap restrict(UnordSet subdom, BaseMap sbgmap); -template UnordSet image(BaseMap sbgmap); -template UnordSet image(UnordSet subdom, BaseMap sbgmap); -template UnordSet preImage(BaseMap sbgmap); -template UnordSet preImage(UnordSet subdom, BaseMap sbgmap); -template BaseMap composition(BaseMap sbgmap1, BaseMap sbgmap2); -template BaseMap minInv(UnordSet im, BaseMap sbgmap); -template BaseMap minInv(BaseMap sbgmap); -template bool isId(BaseMap sbgmap); -template unsigned int nmbrDims(BaseMap sbgmap); -template std::size_t hash_value(const BaseMap &sbgmap); - -template struct SBGMap; -template std::ostream &operator<<(std::ostream &out, const CanonMap &sbgmap); -template CanonMap restrict(OrdSet subdom, CanonMap sbgmap); -template OrdSet image(CanonMap sbgmap); -template OrdSet image(OrdSet subdom, CanonMap sbgmap); -template OrdSet preImage(CanonMap sbgmap); -template OrdSet preImage(OrdSet subdom, CanonMap sbgmap); -template CanonMap composition(CanonMap sbgmap1, CanonMap sbgmap2); -template CanonMap minInv(OrdSet im, CanonMap sbgmap); -template CanonMap minInv(CanonMap sbgmap); -template bool isId(CanonMap sbgmap); -template unsigned int nmbrDims(CanonMap sbgmap); -template std::size_t hash_value(const CanonMap &sbgmap); - } // namespace LIB } // namespace SBG diff --git a/sbg/map.hpp b/sbg/map.hpp index a0247ef..b0605cf 100755 --- a/sbg/map.hpp +++ b/sbg/map.hpp @@ -27,13 +27,8 @@ #ifndef SBG_MAP_HPP #define SBG_MAP_HPP -#include - -#include "sbg/multidim_inter.hpp" #include "sbg/multidim_lexp.hpp" -#include "sbg/ord_pw_mdinter.hpp" -#include "sbg/unord_pw_mdinter.hpp" -#include "util/debug.hpp" +#include "sbg/set.hpp" namespace SBG { @@ -43,68 +38,48 @@ bool compatible(SetPiece mdi, Exp mdle); // Non-optimized implementation ------------------------------------------------ -template struct SBGMap { - typedef typename Set::iterator SetIt; - member_class(Set, dom); member_class(Exp, exp); SBGMap(); SBGMap(Interval i, LExp le); + SBGMap(SetPiece mdi, Exp mdle); SBGMap(Set dom, Exp exp); eq_class(SBGMap); neq_class(SBGMap); }; -template -std::ostream &operator<<(std::ostream &out, const SBGMap &sbgmap); +std::ostream &operator<<(std::ostream &out, const SBGMap &sbgmap); /** * @brief Traditional map operations. */ -template -SBGMap restrict(Set subdom, SBGMap sbgmap); +SBGMap restrict(Set subdom, SBGMap sbgmap); Interval image(Interval i, LExp le); SetPiece image(SetPiece mdi, Exp le); +Set image(SBGMap sbgmap); +Set image(Set subdom, SBGMap sbgmap); -template -Set image(SBGMap sbgmap); - -template -Set image(Set subdom, SBGMap sbgmap); +Set preImage(SBGMap sbgmap); +Set preImage(Set subcodom, SBGMap sbgmap); -template -Set preImage(SBGMap sbgmap); - -template -Set preImage(Set subcodom, SBGMap sbgmap); - -template -SBGMap composition(SBGMap sbgmap1, SBGMap sbgmap2); +SBGMap composition(SBGMap sbgmap1, SBGMap sbgmap2); /** * @brief Extra operations. */ -template -SBGMap minInv(Set im, SBGMap sbgmap); -template -SBGMap minInv(SBGMap sbgmap); - -template -bool isId(SBGMap sbgmap); +SBGMap minInv(Set im, SBGMap sbgmap); +SBGMap minInv(SBGMap sbgmap); -template -unsigned int nmbrDims(SBGMap sbgmap); +bool isId(SBGMap sbgmap); -template -std::size_t hash_value(const SBGMap &sbgmap); +unsigned int nmbrDims(SBGMap sbgmap); -typedef SBGMap BaseMap; -typedef SBGMap CanonMap; +std::size_t hash_value(const SBGMap &sbgmap); } // namespace LIB diff --git a/sbg/multidim_inter.cpp b/sbg/multidim_inter.cpp index b91b124..ae659bd 100755 --- a/sbg/multidim_inter.cpp +++ b/sbg/multidim_inter.cpp @@ -25,7 +25,7 @@ namespace LIB { MultiDimInter::MultiDimInter() : intervals_() {} MultiDimInter::MultiDimInter(MD_NAT x) : intervals_() { - BOOST_FOREACH (NAT xi, x) + for (NAT xi : x) emplaceBack(Interval(xi, 1, xi)); } MultiDimInter::MultiDimInter(Interval i) : intervals_() { emplaceBack(i); } @@ -45,10 +45,7 @@ void MultiDimInter::emplaceBack(Interval i) { if (!isEmpty(i)) intervals_ref().emplace_back(i); - else { - InterVector aux; - set_intervals(aux); - } + else set_intervals(InterVector()); } Interval &MultiDimInter::operator[](std::size_t n) { return intervals_ref()[n]; } @@ -104,7 +101,7 @@ unsigned int cardinal(MultiDimInter mdi) { unsigned int res = 1; - BOOST_FOREACH (Interval i, mdi) + for (Interval i : mdi) res *= cardinal(i); return res; @@ -135,7 +132,7 @@ Util::MD_NAT minElem(MultiDimInter mdi) { MD_NAT res; - BOOST_FOREACH (Interval i, mdi) + for (Interval i : mdi) res.emplace_back(minElem(i)); return res; @@ -145,7 +142,7 @@ Util::MD_NAT maxElem(MultiDimInter mdi) { MD_NAT res; - BOOST_FOREACH (Interval i, mdi) + for (Interval i : mdi) res.emplace_back(maxElem(i)); return res; diff --git a/sbg/multidim_lexp.cpp b/sbg/multidim_lexp.cpp index 677703c..8e51c64 100755 --- a/sbg/multidim_lexp.cpp +++ b/sbg/multidim_lexp.cpp @@ -24,7 +24,7 @@ namespace SBG { namespace LIB { MDLExp::MDLExp() : exps_() {} -MDLExp::MDLExp(Util::MD_NAT x) { BOOST_FOREACH (Util::NAT xi, x) emplaceBack(LExp(0, Util::RATIONAL(xi))); } +MDLExp::MDLExp(Util::MD_NAT x) { for (Util::NAT xi : x) emplaceBack(LExp(0, Util::RATIONAL(xi))); } MDLExp::MDLExp(unsigned int dimensions) : exps_() { for (unsigned int j = 0; j < dimensions; j++) emplaceBack(LExp()); } @@ -141,14 +141,14 @@ MDLExp inverse(MDLExp mdle) { MDLExp res; - BOOST_FOREACH (LExp le, mdle) res.emplaceBack(inverse(le)); + for (LExp le : mdle) res.emplaceBack(inverse(le)); return res; } bool isId(MDLExp mdle) { - BOOST_FOREACH (LExp le, mdle) + for (LExp le : mdle) if (!isId(le)) return false; return true; @@ -156,7 +156,7 @@ bool isId(MDLExp mdle) bool isConstant(MDLExp mdle) { - BOOST_FOREACH (LExp le, mdle) + for (LExp le : mdle) if (!isConstant(le)) return false; return true; diff --git a/sbg/multidim_lexp.hpp b/sbg/multidim_lexp.hpp index 390c379..aacbd75 100755 --- a/sbg/multidim_lexp.hpp +++ b/sbg/multidim_lexp.hpp @@ -24,8 +24,6 @@ #ifndef SBG_MULTIDIM_LEXP_HPP #define SBG_MULTIDIM_LEXP_HPP -#include - #include "lexp.hpp" namespace SBG { diff --git a/sbg/ord_pw_mdinter.cpp b/sbg/ord_pw_mdinter.cpp index 5400f2e..201dc9a 100755 --- a/sbg/ord_pw_mdinter.cpp +++ b/sbg/ord_pw_mdinter.cpp @@ -53,29 +53,32 @@ std::ostream &operator<<(std::ostream &out, const MDInterOrdSet &ii) // OrdPWMDInter ------------------------------------------------------------------ OrdPWMDInter::OrdPWMDInter() : pieces_() {} -OrdPWMDInter::OrdPWMDInter(Interval i) : pieces_() { pieces_ref().insert(SetPiece(i)); } +OrdPWMDInter::OrdPWMDInter(Interval i) : pieces_() { emplaceBack(SetPiece(i)); } OrdPWMDInter::OrdPWMDInter(SetPiece mdi) : pieces_() { - if (isUnidim(mdi)) pieces_ref().insert(mdi); + if (isUnidim(mdi)) emplaceBack(mdi); else Util::ERROR("LIB::OrdPWMDInter: piece should be uni-dimensional"); } OrdPWMDInter::OrdPWMDInter(MDInterOrdSet ii) : pieces_() { if (!ii.empty()) { - BOOST_FOREACH (SetPiece mdi, ii) + for (SetPiece mdi : ii) { if (!isUnidim(mdi)) Util::ERROR("LIB::OrdPWMDInter: piece should be uni-dimensional"); - - set_pieces(ii); + emplaceBack(mdi); + } } - } member_imp(OrdPWMDInter, MDInterOrdSet, pieces); std::size_t OrdPWMDInter::size() { return pieces().size(); } -void OrdPWMDInter::emplace(SetPiece mdi) { pieces_ref().emplace(mdi); } -void OrdPWMDInter::emplace_hint(MDInterOrdSetIt it, SetPiece mdi) { pieces_ref().emplace_hint(it, mdi); } -void OrdPWMDInter::emplaceBack(SetPiece mdi) { pieces_ref().emplace_hint(pieces_ref().cend(), mdi); } +void OrdPWMDInter::emplace(SetPiece mdi) { + if (!isEmpty(mdi)) pieces_ref().emplace(mdi); +} +void OrdPWMDInter::emplace_hint(MDInterOrdSetIt it, SetPiece mdi) { + if (!isEmpty(mdi)) pieces_ref().emplace_hint(it, mdi); +} +void OrdPWMDInter::emplaceBack(SetPiece mdi) { emplace_hint(end(), mdi); } OrdPWMDInter::iterator OrdPWMDInter::begin() { return pieces_ref().begin(); } OrdPWMDInter::iterator OrdPWMDInter::end() { return pieces_ref().end(); } @@ -111,7 +114,7 @@ unsigned int cardinal(OrdPWMDInter pwi) { unsigned int result = 0; - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) result += cardinal(mdi); return result; @@ -121,7 +124,7 @@ bool isEmpty(OrdPWMDInter pwi) { return pwi.pieces().empty(); } bool isMember(MD_NAT x, OrdPWMDInter pwi) { - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) if (isMember(x, mdi)) return true; return false; @@ -179,20 +182,20 @@ OrdPWMDInter cup(OrdPWMDInter pwi1, OrdPWMDInter pwi2) if (pwi1.pieces_ref() == pwi2.pieces_ref()) return pwi1; if (maxElem(pwi1) <= minElem(pwi2)) { - BOOST_FOREACH (SetPiece mdi1, pwi1) + for (SetPiece mdi1 : pwi1) un.emplaceBack(mdi1); - BOOST_FOREACH (SetPiece mdi2, pwi2) + for (SetPiece mdi2 : pwi2) un.emplaceBack(mdi2); return OrdPWMDInter(un); } if (maxElem(pwi2) <= minElem(pwi1)) { - BOOST_FOREACH (SetPiece mdi2, pwi2) + for (SetPiece mdi2 : pwi2) un.emplaceBack(mdi2); - BOOST_FOREACH (SetPiece mdi1, pwi1) + for (SetPiece mdi1 : pwi1) un.emplaceBack(mdi1); return OrdPWMDInter(un); @@ -204,9 +207,9 @@ OrdPWMDInter cup(OrdPWMDInter pwi1, OrdPWMDInter pwi2) // one with least quantity of them. OrdPWMDInter lt_pieces, gt_pieces; int c_size1 = 0, c_size2 = 0; - BOOST_FOREACH (SetPiece mdi1, pwi1) + for (SetPiece mdi1 : pwi1) c_size1 += mdi1.begin()->step(); - BOOST_FOREACH (SetPiece mdi2, pwi2) + for (SetPiece mdi2 : pwi2) c_size2 += mdi2.begin()->step(); if (c_size1 < c_size2) { @@ -224,10 +227,10 @@ OrdPWMDInter cup(OrdPWMDInter pwi1, OrdPWMDInter pwi2) return concatenation(lt_pieces, diff); else { - BOOST_FOREACH (SetPiece mdi, lt_pieces) + for (SetPiece mdi : lt_pieces) un.emplace(mdi); - BOOST_FOREACH (SetPiece mdi, diff) + for (SetPiece mdi : diff) un.emplace(mdi); } @@ -282,7 +285,7 @@ OrdPWMDInter complement(OrdPWMDInter pwi) ++first_it; MDInterOrdSet second(first_it, pwi.end()); - BOOST_FOREACH (SetPiece mdi, second) { + for (SetPiece mdi : second) { OrdPWMDInter c = complementAtom(OrdPWMDInter(mdi)); res = intersection(res, c); } @@ -296,7 +299,7 @@ OrdPWMDInter difference(OrdPWMDInter pwi1, OrdPWMDInter pwi2) { return intersect bool isCompact(MDInterOrdSet ii) { - BOOST_FOREACH (SetPiece mdi, ii) + for (SetPiece mdi : ii) if (mdi.begin()->step() != 1) return false; @@ -346,9 +349,9 @@ OrdPWMDInter concatenation(OrdPWMDInter pwi1, OrdPWMDInter pwi2) if (optConds(pwi1.pieces()) && optConds(pwi2.pieces())) res = traverse(pwi1, pwi2, &least); else { - BOOST_FOREACH (SetPiece mdi1, pwi1) res.emplace(mdi1); + for (SetPiece mdi1 : pwi1) res.emplace(mdi1); - BOOST_FOREACH (SetPiece mdi2, pwi2) res.emplace(mdi2); + for (SetPiece mdi2 : pwi2) res.emplace(mdi2); } return res; @@ -358,7 +361,7 @@ OrdPWMDInter filterSet(bool (*f)(SetPiece), OrdPWMDInter pwi) { OrdPWMDInter res; - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) if (f(mdi)) res.emplaceBack(mdi); return res; @@ -368,7 +371,7 @@ OrdPWMDInter offset(Util::MD_NAT off, OrdPWMDInter pwi) { OrdPWMDInter res; - BOOST_FOREACH (SetPiece mdi, pwi) res.emplaceBack(offset(off, mdi)); + for (SetPiece mdi : pwi) res.emplaceBack(offset(off, mdi)); return res; } @@ -398,8 +401,8 @@ MDInterOrdSet boundedTraverse(OrdPWMDInter pwi1, OrdPWMDInter pwi2, SetPiece (*f } else { - BOOST_FOREACH (SetPiece mdi1, pwi1) - BOOST_FOREACH (SetPiece mdi2, pwi2) { + for (SetPiece mdi1 : pwi1) + for (SetPiece mdi2 : pwi2) { SetPiece funci = func(mdi1, mdi2); if (!isEmpty(funci)) result.emplace_hint(result.cend(), funci); @@ -446,8 +449,8 @@ MDInterOrdSet traverse(OrdPWMDInter pwi1, OrdPWMDInter pwi2, SetPiece (*func)(Se } else { - BOOST_FOREACH (SetPiece mdi1, pwi1) - BOOST_FOREACH (SetPiece mdi2, pwi2) { + for (SetPiece mdi1 : pwi1) + for (SetPiece mdi2 : pwi2) { SetPiece funci = func(mdi1, mdi2); if (!isEmpty(funci)) result.emplace_hint(result.cend(), funci); @@ -457,6 +460,13 @@ MDInterOrdSet traverse(OrdPWMDInter pwi1, OrdPWMDInter pwi2, SetPiece (*func)(Se return result; } +void foreach(OrdPWMDInter pwi, void (*f)(SetPiece)) +{ + for (SetPiece mdi : pwi) f(mdi); + + return; +} + std::size_t hash_value(const OrdPWMDInter &pwi) { OrdPWMDInter aux_pwi = pwi; diff --git a/sbg/ord_pw_mdinter.hpp b/sbg/ord_pw_mdinter.hpp index 7a2ca7a..f02148c 100755 --- a/sbg/ord_pw_mdinter.hpp +++ b/sbg/ord_pw_mdinter.hpp @@ -163,6 +163,8 @@ MDInterOrdSet boundedTraverse(OrdPWMDInter pwi1, OrdPWMDInter pwi2, SetPiece (*f */ MDInterOrdSet traverse(OrdPWMDInter pwi1, OrdPWMDInter pwi2, SetPiece (*func)(SetPiece, SetPiece)); +void foreach(OrdPWMDInter pwi, void (*f)(SetPiece)); + std::size_t hash_value(const OrdPWMDInter &pwi); typedef OrdPWMDInter OrdSet; diff --git a/sbg/pw_map.cpp b/sbg/pw_map.cpp index c222c0d..b971ffe 100755 --- a/sbg/pw_map.cpp +++ b/sbg/pw_map.cpp @@ -25,30 +25,22 @@ namespace LIB { // Type definitions ------------------------------------------------------------ -template -LTMap::LTMap() {} - -template -bool LTMap::operator()(const SBGMap &x, const SBGMap &y) const -{ - return true; -} - -template -std::ostream &operator<<(std::ostream &out, const MapSet &ms) +std::ostream &operator<<(std::ostream &out, const MapSet &ms) { - MapSet aux = ms; + MapSet aux = ms; int sz = aux.size(); out << "<<"; if (sz > 0) { auto it = aux.begin(); + SBGMap aux_map = *it; for (int i = 0; i < sz - 1; ++i) { - if (!isEmpty(it->dom_ref())) + if (!isEmpty(aux_map.dom_ref())) out << *it << ", "; ++it; + aux_map = *it; } - if (!isEmpty(it->dom_ref())) + if (!isEmpty(aux_map.dom_ref())) out << *it; } out << ">>"; @@ -58,73 +50,59 @@ std::ostream &operator<<(std::ostream &out, const MapSet &ms) // PWMap ----------------------------------------------------------------------- -template -PWMap::PWMap() : maps_() {} -template -PWMap::PWMap(Set s) : maps_() { +PWMap::PWMap() : maps_() {} +PWMap::PWMap(Set s) : maps_() { if (!isEmpty(s)) { unsigned int dims = s[0].size(); - SBGMap sbg_map(s, Exp(dims)); + SBGMap sbg_map(s, Exp(dims)); maps_ref().emplace(sbg_map); } } -template -PWMap::PWMap(SBGMap sm) : maps_() { +PWMap::PWMap(SBGMap sm) : maps_() { if (!isEmpty(sm.dom())) maps_ref().emplace(sm); } -template -PWMap::PWMap(MapSet maps) : maps_(maps) {} +PWMap::PWMap(MapSet maps) : maps_(maps) { + for (SBGMap sbgmap : maps) emplaceBack(sbgmap); +} -member_imp_temp(template, PWMap, MapSet, maps); +member_imp(PWMap, MapSet, maps); -template -typename PWMap::iterator PWMap::begin() { return maps_ref().begin(); } -template -typename PWMap::iterator PWMap::end() { return maps_ref().end(); } +typename PWMap::iterator PWMap::begin() { return maps_ref().begin(); } +typename PWMap::iterator PWMap::end() { return maps_ref().end(); } -template -std::size_t PWMap::size() { return maps_ref().size(); } +std::size_t PWMap::size() { return maps_ref().size(); } -template -void PWMap::emplace(SBGMap m) { if (!isEmpty(m.dom())) maps_ref().emplace(m); } -template -void PWMap::emplace_hint(MapSetIt it, SBGMap m) { if(!isEmpty(m.dom())) maps_ref().emplace_hint(it, m); } -template -void PWMap::emplaceBack(SBGMap m) { maps_ref().emplace_hint(maps_ref().end(), m); } -template -SBGMap &PWMap::operator[](std::size_t n) { - auto first = maps_ref().begin(); - for (unsigned int j = 0; j < n; j++) first++; - return *first; +void PWMap::emplace(SBGMap m) { if (!isEmpty(m.dom())) maps_ref().emplace(m); } +void PWMap::emplace_hint(PWMap::iterator it, SBGMap m) { + if(!isEmpty(m.dom())) maps_ref().emplace_hint(it, m); } +void PWMap::emplaceBack(SBGMap m) { emplace_hint(maps_ref().end(), m); } -template -PWMap PWMap::operator+(const PWMap &pw) +PWMap PWMap::operator+(const PWMap &pw) { - PWMap res; + PWMap res; - PWMap aux1 = *this, aux2 = pw; - BOOST_FOREACH (SBGMap sbgmap1, aux1.maps()) { - BOOST_FOREACH (SBGMap sbgmap2, aux2.maps()) { + PWMap aux1 = *this, aux2 = pw; + for (SBGMap sbgmap1 : aux1) { + for (SBGMap sbgmap2 : aux2) { Set ith_dom = intersection(sbgmap1.dom(), sbgmap2.dom()); Exp ith_exp = sbgmap1.exp() + sbgmap2.exp(); - if (!isEmpty(ith_dom)) res.emplaceBack(SBGMap(ith_dom, ith_exp)); + res.emplaceBack(SBGMap(ith_dom, ith_exp)); } } return res; } -template -bool PWMap::operator==(const PWMap &other) const +bool PWMap::operator==(const PWMap &other) const { if (!(dom(*this) == dom(other))) return false; if (maps() == other.maps()) return true; - BOOST_FOREACH (SBGMap sbgmap1, maps()) { - BOOST_FOREACH (SBGMap sbgmap2, other.maps()) { + for (SBGMap sbgmap1 : maps()) { + for (SBGMap sbgmap2 : other.maps()) { Set cap_dom = intersection(sbgmap1.dom_ref(), sbgmap2.dom_ref()); if (!isEmpty(cap_dom)) { @@ -150,11 +128,9 @@ bool PWMap::operator==(const PWMap &other) const return true; } -template -bool PWMap::operator!=(const PWMap &other) const { return !(*this == other); } +bool PWMap::operator!=(const PWMap &other) const { return !(*this == other); } -template -std::ostream &operator<<(std::ostream &out, const PWMap &pw) +std::ostream &operator<<(std::ostream &out, const PWMap &pw) { out << pw.maps(); @@ -163,36 +139,32 @@ std::ostream &operator<<(std::ostream &out, const PWMap &pw) // PWMap functions ------------------------------------------------------------- -template -bool isEmpty(PWMap pw) { return pw.maps().empty(); } +bool isEmpty(PWMap pw) { return pw.maps().empty(); } -template -Set dom(PWMap pw) +Set dom(PWMap pw) { Set res; - BOOST_FOREACH (SBGMap sbgmap, pw) - res = concatenation(res, sbgmap.dom()); + if (!isEmpty(pw)) + for (SBGMap sbgmap : pw) res = concatenation(res, sbgmap.dom()); return res; } -template -PWMap restrict(Set subdom, PWMap pw) +PWMap restrict(Set subdom, PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw) res.emplaceBack(restrict(subdom, sbgmap)); + for (SBGMap sbgmap : pw) res.emplaceBack(restrict(subdom, sbgmap)); return PWMap(res); } -template -Set image(PWMap pw) +Set image(PWMap pw) { Set res; - BOOST_FOREACH (SBGMap sbgmap, pw) { + for (SBGMap sbgmap : pw) { Set ith = image(sbgmap); res = cup(res, ith); } @@ -200,22 +172,19 @@ Set image(PWMap pw) return res; } -template -Set image(Set subdom, PWMap pw) +Set image(Set subdom, PWMap pw) { PWMap restricted = restrict(subdom, pw); return image(restricted); } -template -Set preImage(PWMap pw) { return dom(pw); } +Set preImage(PWMap pw) { return dom(pw); } -template -Set preImage(Set subcodom, PWMap pw) +Set preImage(Set subcodom, PWMap pw) { Set res; - BOOST_FOREACH (SBGMap sbgmap, pw) { + for (SBGMap sbgmap : pw) { Set ith = preImage(subcodom, sbgmap); res = cup(res, ith); } @@ -223,18 +192,17 @@ Set preImage(Set subcodom, PWMap pw) return res; } -template -PWMap composition(PWMap pw1, PWMap pw2) +PWMap composition(PWMap pw1, PWMap pw2) { - PWMap res; + PWMap res; Set im = image(pw2), new_dom = preImage(im, pw2); PWMap map2 = restrict(new_dom, pw2); - PWMap aux1 = normalize(pw1), aux2 = normalize(map2); - //PWMap aux1 = pw1, aux2 = map2; - BOOST_FOREACH (SBGMap sbgmap1, aux1) { - BOOST_FOREACH (SBGMap sbgmap2, aux2) { + PWMap aux1 = normalize(pw1), aux2 = normalize(map2); + //PWMap aux1 = pw1, aux2 = map2; + for (SBGMap sbgmap1 : aux1) { + for (SBGMap sbgmap2 : aux2) { SBGMap ith = composition(sbgmap1, sbgmap2); if (!isEmpty(ith.dom_ref())) res.emplaceBack(ith); @@ -244,10 +212,9 @@ PWMap composition(PWMap pw1, PWMap pw2) return res; } -template -PWMap mapInf(PWMap pw, unsigned int n) +PWMap mapInf(PWMap pw, unsigned int n) { - PWMap res = pw, old_res; + PWMap res = pw, old_res; Set pw_dom = dom(pw); if (!isEmpty(pw_dom)) { @@ -270,25 +237,22 @@ PWMap mapInf(PWMap pw, unsigned int n) return res; } -template -PWMap mapInf(PWMap pw) { return mapInf(pw, 0); } +PWMap mapInf(PWMap pw) { return mapInf(pw, 0); } // Extra operations ------------------------------------------------------------ // !!! pw1 and pw2 should be domain-disjoint -template -PWMap concatenation(PWMap pw1, PWMap pw2) +PWMap concatenation(PWMap pw1, PWMap pw2) { - MapSet res; + MapSet res; - BOOST_FOREACH (SBGMap sbgmap1, pw1.maps()) res.emplace_hint(res.end(), sbgmap1); - BOOST_FOREACH (SBGMap sbgmap2, pw2.maps()) res.emplace_hint(res.end(), sbgmap2); + for (SBGMap sbgmap1 : pw1) res.emplace_hint(res.end(), sbgmap1); + for (SBGMap sbgmap2 : pw2) res.emplace_hint(res.end(), sbgmap2); return PWMap(res); } -template -PWMap combine(PWMap pw1, PWMap pw2) +PWMap combine(PWMap pw1, PWMap pw2) { PWMap res = pw1; @@ -297,7 +261,7 @@ PWMap combine(PWMap pw1, PWMap pw2) if (isEmpty(pw2)) return pw1; Set dom1 = dom(pw1); - BOOST_FOREACH (SBGMap sbgmap2, pw2) { + for (SBGMap sbgmap2 : pw2) { Set dom2 = sbgmap2.dom(), new_dom = difference(dom2, dom1); res.emplaceBack(SBGMap(new_dom, sbgmap2.exp())); } @@ -305,10 +269,9 @@ PWMap combine(PWMap pw1, PWMap pw2) return res; } -template -PWMap reduce(Interval i, LExp le) +PWMap reduce(Interval i, LExp le, std::size_t imp) { - PWMap res; + PWMap res; if (!isEmpty(i)) { Util::RATIONAL zero(0, 1); @@ -318,20 +281,22 @@ PWMap reduce(Interval i, LExp le) Util::NAT st = i.step(); if (h == (Util::INT) st) { Util::NAT hi = i.end(); - Util::RATIONAL const_expr(hi + st, 1); - if (st < Util::Inf - hi) res = PWMap(SBGMap(i, LExp(zero, const_expr))); + Util::RATIONAL off(hi + st, 1); + LExp const_expr(zero, off); + if (st < Util::Inf - hi) res = PWMap(SBGMap(i, const_expr)); } else if (h == (Util::INT) -st) { Util::NAT lo = i.begin(); - Util::RATIONAL const_expr(lo - st, 1); - if (lo >= st) res = PWMap(SBGMap(i, LExp(zero, const_expr))); + Util::RATIONAL off(lo - st, 1); + LExp const_expr(zero, off); + if (lo >= st) res = PWMap(SBGMap(i, const_expr)); } else if (h % (Util::INT) st == 0) { // Is convenient the partition of the piece? if ((Util::INT) cardinal(i) > h*h) { - res = PWMap(); + res = PWMap(); Util::INT absh = std::abs(h); for (int k = 1; k <= absh; ++k) { @@ -343,29 +308,27 @@ PWMap reduce(Interval i, LExp le) else kth_exp.set_offset(kth_piece.begin() + h); - SBGMap kth_map(kth_piece, kth_exp); + SBGMap kth_map(kth_piece, kth_exp); res.emplaceBack(kth_map); } } } } - else res.emplaceBack(SBGMap(i, le)); + else res.emplaceBack(SBGMap(i, le)); } return res; } -template -PWMap reduce(SBGMap sbgmap) +PWMap reduce(SBGMap sbgmap) { - PWMap res; + PWMap res; Set d = sbgmap.dom(), not_reduced; + std::size_t imp = d.pieces().index(); Exp e = sbgmap.exp(); - BOOST_FOREACH (SetPiece dom_piece, d) { - if (isEmpty(dom_piece)) return res; - + auto f = [&](SetPiece dom_piece) { if (dom_piece.size() == e.size()) { unsigned int j = 0; SetPiece aux_piece = dom_piece; @@ -375,12 +338,12 @@ PWMap reduce(SBGMap sbgmap) Interval i = boost::get<0>(items); LExp le = boost::get<1>(items); - PWMap reduced = reduce(i, le); - BOOST_FOREACH (SBGMap ith_reduced, reduced) { + PWMap reduced = reduce(i, le, imp); + for (SBGMap ith_reduced : reduced) { aux_piece[j] = ith_reduced.dom()[0][0]; aux_exp[j] = ith_reduced.exp()[0]; if (aux_piece != dom_piece || !(aux_exp == e)) { - res.emplaceBack(SBGMap(aux_piece, aux_exp)); + res.emplaceBack(SBGMap(aux_piece, aux_exp)); was_reduced = true; } @@ -391,26 +354,25 @@ PWMap reduce(SBGMap sbgmap) ++j; } - if (!was_reduced) not_reduced = concatenation(not_reduced, dom_piece); + if (!was_reduced) not_reduced.emplace(dom_piece); } - else { - Util::ERROR("LIB::PWMap::reduce: dimensions don't match"); - return PWMap(); - } - } + else Util::ERROR("LIB::PWMap::reduce: dimensions don't match"); - res.emplaceBack(SBGMap(not_reduced, e)); // Add unreduced submaps + return; + }; + foreach(f, d); + + res.emplaceBack(SBGMap(not_reduced, e)); // Add unreduced submaps return res; } -template -PWMap reduce(PWMap pw) +PWMap reduce(PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw.maps()) { + for (SBGMap sbgmap : pw) { PWMap ith = reduce(sbgmap); res = concatenation(ith, res); } @@ -418,19 +380,18 @@ PWMap reduce(PWMap pw) return res; } -template -PWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4) +PWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4) { - PWMap res; + PWMap res; LExp le21 = composition(le1, le2), le34 = composition(le4, le3); Util::RATIONAL m21 = le21.slope(), h21 = le21.offset(), m34 = le34.slope(), h34 = le34.offset(); // Parallel lines if (m21 == m34) { - if (h21 < h34) res.emplaceBack(SBGMap(i, le2)); + if (h21 < h34) res.emplaceBack(SBGMap(i, le2)); - else res.emplaceBack(SBGMap(i, le3)); + else res.emplaceBack(SBGMap(i, le3)); return res; } @@ -451,32 +412,30 @@ PWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4) // Before intersection if (!isEmpty(before)) { - if (m34 > m21) res.emplaceBack(SBGMap(before, le3)); + if (m34 > m21) res.emplaceBack(SBGMap(before, le3)); - else res.emplaceBack(SBGMap(before, le2)); + else res.emplaceBack(SBGMap(before, le2)); } // After intersection if (!isEmpty(after)) { - if (m21 > m34) res.emplaceBack(SBGMap(after, le3)); + if (m21 > m34) res.emplaceBack(SBGMap(after, le3)); - else res.emplaceBack(SBGMap(after, le2)); + else res.emplaceBack(SBGMap(after, le2)); } return res; } -template -PWMap minMap(Interval i, LExp le1, LExp le2) +PWMap minMap(Interval i, LExp le1, LExp le2) { LExp id; - return minMap(i, id, le1, le2, id); + return minMap(i, id, le1, le2, id); } -template -PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4) +PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4) { - PWMap res; + PWMap res; if (!isEmpty(dom_piece)) { SetPiece aux_dom = dom_piece; @@ -488,18 +447,15 @@ PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4) Interval i = boost::get<0>(items); LExp le1 = boost::get<1>(items), le2 = boost::get<2>(items); LExp le3 = boost::get<3>(items), le4 = boost::get<4>(items); - PWMap ith = minMap(i, le1, le2, le3, le4); + PWMap ith = minMap(i, le1, le2, le3, le4); if (!isEmpty(ith)) { - BOOST_FOREACH (SBGMap sbgmap, ith) { + for (SBGMap sbgmap : ith) { aux_dom[j] = sbgmap.dom()[0][0]; Exp e = sbgmap.exp(); - SBGMap new_ith; - if (e == le2) new_ith = SBGMap(aux_dom, e2); - else new_ith = SBGMap(aux_dom, e3); - - res.emplaceBack(new_ith); + if (e == le2) res.emplaceBack(SBGMap(aux_dom, e2)); + else res.emplaceBack(SBGMap(aux_dom, e3)); } } @@ -512,72 +468,72 @@ PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4) } Util::ERROR("LIB::PWMap::minMap: dimensions don't match"); - return PWMap(); + return PWMap(); } -template -PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2) +PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2) { Exp id(e1.size()); - return minMap(dom_piece, id, e1, e2, id); + return minMap(dom_piece, id, e1, e2, id); } -template -PWMap minMap(Set dom, Exp e1, Exp e2, Exp e3, Exp e4) +PWMap minMap(Set dom, Exp e1, Exp e2, Exp e3, Exp e4) { - PWMap res; - - Set d2, d3; + PWMap res; - BOOST_FOREACH (SetPiece dom_piece, dom) { - PWMap ith = minMap(dom_piece, e1, e2, e3, e4); - BOOST_FOREACH (SBGMap sbgmap, ith) { - if (sbgmap.exp() == e2) d2 = cup(d2, sbgmap.dom()); + if (!isEmpty(dom)) { + Set d2, d3; + auto f = [&](SetPiece dom_piece) { + PWMap ith = minMap(dom_piece, e1, e2, e3, e4); + for (SBGMap sbgmap : ith) { + if (sbgmap.exp() == e2) + d2 = cup(d2, sbgmap.dom()); - else d3 = cup(d3, sbgmap.dom()); - } - } + else + d3 = cup(d3, sbgmap.dom()); + } + }; + foreach (f, dom); - if (!isEmpty(d2)) res.emplaceBack(SBGMap(d2, e2)); + if (!isEmpty(d2)) res.emplaceBack(SBGMap(d2, e2)); - if (!isEmpty(d3)) res.emplaceBack(SBGMap(d3, e3)); + if (!isEmpty(d3)) res.emplaceBack(SBGMap(d3, e3)); + } return res; } -template -PWMap minMap(Set dom, Exp e1, Exp e2) +PWMap minMap(Set dom, Exp e1, Exp e2) { Exp id(e1.size()); return minMap(dom, id, e1, e2, id); } -template -PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4) +PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4) { - PWMap res; + PWMap res; Set dom1 = dom(pw1), dom2 = dom(pw2), dom3 = dom(pw3), dom4 = dom(pw4); Set dom21 = preImage(dom1, pw2), dom34 = preImage(dom4, pw3); Set cap_dom23 = intersection(dom2, dom3), cap_dom14 = intersection(dom21, dom34); Set cap_dom = intersection(cap_dom23, cap_dom14); - BOOST_FOREACH (SetPiece mdi, cap_dom) { + auto f = [&](SetPiece mdi) { Set mdi_set(mdi); bool flag1 = false, flag2 = false, flag3 = false, flag4 = false; Exp e1, e2, e3, e4; Set im2; - BOOST_FOREACH (SBGMap sbgmap2, pw2.maps()) { + for (SBGMap sbgmap2 : pw2) { Set d2 = sbgmap2.dom(), s2 = intersection(d2, mdi_set); if (!isEmpty(s2)) { e2 = sbgmap2.exp(); flag2 = true; - im2 = image(SBGMap(d2, e2)); + im2 = image(SBGMap(d2, e2)); break; } } - BOOST_FOREACH (SBGMap sbgmap1, pw1.maps()) { + for (SBGMap sbgmap1 : pw1) { Set s1 = intersection(sbgmap1.dom(), im2); if (!isEmpty(s1)) { e1 = sbgmap1.exp(); @@ -587,17 +543,17 @@ PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4 } Set im3; - BOOST_FOREACH (SBGMap sbgmap3, pw3.maps()) { + for (SBGMap sbgmap3 : pw3) { Set d3 = sbgmap3.dom(), s3 = intersection(d3, mdi_set); if (!isEmpty(s3)) { e3 = sbgmap3.exp(); flag3 = true; - im3 = image(SBGMap(d3, e3)); + im3 = image(SBGMap(d3, e3)); break; } } - BOOST_FOREACH (SBGMap sbgmap4, pw4.maps()) { + for (SBGMap sbgmap4 : pw4) { Set s4 = intersection(sbgmap4.dom(), im3); if (!isEmpty(s4)) { e4 = sbgmap4.exp(); @@ -610,30 +566,29 @@ PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4 PWMap ith = minMap(mdi_set, e1, e2, e3, e4); res = combine(ith, res); } - } + }; + foreach(f, cap_dom); return res; } -template -PWMap minMap(PWMap pw1, PWMap pw2) +PWMap minMap(PWMap pw1, PWMap pw2) { - if (isEmpty(pw1) || isEmpty(pw2)) return PWMap(); + if (isEmpty(pw1) || isEmpty(pw2)) return PWMap(); unsigned int nmbr_dims = nmbrDims(pw1); Exp id(nmbr_dims); - SBGMap aux1(image(pw1), id), aux2(image(pw2), id); - PWMap id_map1(aux1), id_map2(aux2); + SBGMap aux1(image(pw1), id), aux2(image(pw2), id); + PWMap id_map1(aux1), id_map2(aux2); - PWMap res = minMap(id_map1, pw1, pw2, id_map2); + PWMap res = minMap(id_map1, pw1, pw2, id_map2); - return minMap(id_map1, pw1, pw2, id_map2); + return minMap(id_map1, pw1, pw2, id_map2); } -template -PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) +PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) { - PWMap res; + PWMap res; Set partitioned_dom3 = preImage(image(pw3), pw3); Set partitioned_dom = preImage(partitioned_dom3, pw2); @@ -641,12 +596,12 @@ PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) partitioned_dom = intersection(dom(pw2), partitioned_dom); Set visited; - BOOST_FOREACH (SetPiece mdi, partitioned_dom) { + auto f = [&](SetPiece mdi) { Set dom_res, mdi_set(mdi); Exp e_res, e1; // Find mdi in pw1 dom - BOOST_FOREACH (SBGMap sbgmap1, pw1) { + for (SBGMap sbgmap1 : pw1) { Set dom1 = sbgmap1.dom(), s1 = intersection(dom1, mdi_set); if (!isEmpty(s1)) { dom_res = image(s1, sbgmap1); @@ -655,14 +610,14 @@ PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) } // Find mdi in pw2 dom - BOOST_FOREACH (SBGMap sbgmap2, pw2) { + for (SBGMap sbgmap2 : pw2) { Set dom2 = sbgmap2.dom(), s2 = intersection(dom2, mdi_set); if (!isEmpty(s2)) { Set im2 = image(s2, sbgmap2); if (!isConstant(e1)) e_res = composition(sbgmap2.exp(), inverse(e1)); else { - BOOST_FOREACH (SBGMap sbgmap3, pw3) { + for (SBGMap sbgmap3 : pw3) { Set dom3 = sbgmap3.dom(), s3 = intersection(dom3, im2); if (!isEmpty(s3)) { if (!isConstant(sbgmap3.exp())) { @@ -678,8 +633,8 @@ PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) } } - SBGMap ith(dom_res, e_res); - PWMap ith_pw(ith); + SBGMap ith(dom_res, e_res); + PWMap ith_pw(ith); Set again = intersection(dom_res, visited); if (!isEmpty(again)) { PWMap r_res = restrict(again, res), r_map = restrict(again, ith_pw); @@ -690,40 +645,43 @@ PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3) else res.emplaceBack(ith); visited = cup(visited, dom_res); - } + }; + foreach(f, partitioned_dom); return res; } -template -PWMap minAdjMap(PWMap pw1, PWMap pw2) +PWMap minAdjMap(PWMap pw1, PWMap pw2) { - Set first_dom = pw2.maps().begin()->dom(); - unsigned int nmbr_dims = first_dom.begin()->size(); - Exp id(nmbr_dims); - SBGMap aux2(image(pw2), id); - PWMap id_map2(aux2); + if (!isEmpty(pw2)) { + Set first_dom = pw2.maps_ref().begin()->dom(); + unsigned int nmbr_dims = std::visit([](auto v) { return v.begin()->size(); }, first_dom.pieces()); + Exp id(nmbr_dims); + SBGMap aux2(image(pw2), id); + PWMap id_map2(aux2); - return minAdjMap(pw1, pw2, id_map2); + return minAdjMap(pw1, pw2, id_map2); + } + + return PWMap(); } -template -PWMap minInv(Set d, PWMap pw) +PWMap minInv(Set d, PWMap pw) { - PWMap res; + PWMap res; if (!isEmpty(pw)) { - SBGMap first = *(pw.maps_ref().begin()); + SBGMap first = *(pw.maps_ref().begin()); res.emplaceBack(minInv(d, first)); - BOOST_FOREACH (SBGMap sbgmap, pw) { - SBGMap ith = minInv(d, sbgmap); + for (SBGMap sbgmap : pw) { + SBGMap ith = minInv(d, sbgmap); Set cap_dom = intersection(ith.dom(), dom(res)); if (!isEmpty(cap_dom)) { - PWMap min = minMap(res, PWMap(ith)); + PWMap min = minMap(res, PWMap(ith)); res = combine(min, res); Set diff = difference(ith.dom(), dom(res)); - res.emplaceBack(SBGMap(diff, ith.exp())); + res.emplaceBack(SBGMap(diff, ith.exp())); } else res.emplaceBack(ith); @@ -733,30 +691,27 @@ PWMap minInv(Set d, PWMap pw) return res; } -template -PWMap minInv(PWMap pw) { return minInv(dom(pw), pw); } +PWMap minInv(PWMap pw) { return minInv(dom(pw), pw); } -template -PWMap filterMap(bool (*f)(SBGMap), PWMap pw) +PWMap filterMap(bool (*f)(SBGMap), PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw.maps()) + for (SBGMap sbgmap : pw) if (f(sbgmap)) res.emplaceBack(sbgmap); return res; } -template -Set equalImage(PWMap pw1, PWMap pw2) +Set equalImage(PWMap pw1, PWMap pw2) { Set res; - BOOST_FOREACH (SBGMap sbgmap1, pw1.maps()) { - BOOST_FOREACH (SBGMap sbgmap2, pw2.maps()) { + for (SBGMap sbgmap1 : pw1) { + for (SBGMap sbgmap2 : pw2) { Set cap_dom = intersection(sbgmap1.dom(), sbgmap2.dom()); if (!isEmpty(cap_dom)) { - SBGMap map1(cap_dom, sbgmap1.exp()), map2(cap_dom, sbgmap2.exp()); + SBGMap map1(cap_dom, sbgmap1.exp()), map2(cap_dom, sbgmap2.exp()); if (map1 == map2) res = cup(res, cap_dom); } } @@ -765,38 +720,35 @@ Set equalImage(PWMap pw1, PWMap pw2) return res; } -template -PWMap offsetDom(Util::MD_NAT off, PWMap pw) +PWMap offsetDom(Util::MD_NAT off, PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw) { - SBGMap ith(offset(off, sbgmap.dom()), sbgmap.exp()); + for (SBGMap sbgmap : pw) { + SBGMap ith(offset(off, sbgmap.dom()), sbgmap.exp()); res.emplaceBack(ith); } return res; } -template -PWMap offsetDom(PWMap off, PWMap pw) +PWMap offsetDom(PWMap off, PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw) { + for (SBGMap sbgmap : pw) { Set ith_dom = image(sbgmap.dom(), off); - res.emplaceBack(SBGMap(ith_dom, sbgmap.exp())); + res.emplaceBack(SBGMap(ith_dom, sbgmap.exp())); } return res; } -template -PWMap offsetImage(Util::MD_NAT off, PWMap pw) +PWMap offsetImage(Util::MD_NAT off, PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw) { + for (SBGMap sbgmap : pw) { Exp e = sbgmap.exp(), res_e; parallel_foreach2 (off, e.exps_ref()) { Util::NAT o = boost::get<0>(items); @@ -805,19 +757,18 @@ PWMap offsetImage(Util::MD_NAT off, PWMap pw) res_e.emplaceBack(res_lexp); } - res.emplaceBack(SBGMap(sbgmap.dom(), res_e)); + res.emplaceBack(SBGMap(sbgmap.dom(), res_e)); } return res; } -template -PWMap offsetImage(Exp off, PWMap pw) +PWMap offsetImage(Exp off, PWMap pw) { - PWMap res; + PWMap res; - BOOST_FOREACH (SBGMap sbgmap, pw) { - SBGMap ith(sbgmap.dom(), off + sbgmap.exp()); + for (SBGMap sbgmap : pw) { + SBGMap ith(sbgmap.dom(), off + sbgmap.exp()); res.emplaceBack(ith); } @@ -825,107 +776,31 @@ PWMap offsetImage(Exp off, PWMap pw) } // Function should be called on a non-empty pw -template -unsigned int nmbrDims(PWMap pw) { return nmbrDims(pw[0]); } +unsigned int nmbrDims(PWMap pw) +{ + Set first_dom = pw.begin()->dom(); + return std::visit([](auto v) { return v.begin()->size(); }, first_dom.pieces()); +} -template -PWMap normalize(PWMap pw) +PWMap normalize(PWMap pw) { - PWMap res; + PWMap res; Set visited; - BOOST_FOREACH (SBGMap sbgmap1, pw) { + for (SBGMap sbgmap1 : pw) { if (isEmpty(intersection(sbgmap1.dom(), visited))) { Set ith(sbgmap1.dom()); - BOOST_FOREACH (SBGMap sbgmap2, pw) + for (SBGMap sbgmap2 : pw) if (sbgmap1.exp() == sbgmap2.exp()) cup(ith, sbgmap2.dom()); visited = cup(visited, ith); - res.emplaceBack(SBGMap(ith, sbgmap1.exp())); + res.emplaceBack(SBGMap(ith, sbgmap1.exp())); } } return res; } -// Template instantiations ----------------------------------------------------- - -template std::ostream &operator<<(std::ostream &out, const MapSet &ms); -template struct PWMap; -template std::ostream &operator<<(std::ostream &out, const BasePWMap &pw); -template bool isEmpty(BasePWMap pw); -template UnordSet dom(BasePWMap pw); -template BasePWMap restrict(UnordSet subdom, BasePWMap pw); -template UnordSet image(BasePWMap pw); -template UnordSet image(UnordSet subdom, BasePWMap pw); -template UnordSet preImage(BasePWMap pw); -template UnordSet preImage(UnordSet subcodom, BasePWMap pw); -template BasePWMap mapInf(BasePWMap pw); -template BasePWMap composition(BasePWMap pw1, BasePWMap pw2); -template BasePWMap concatenation(BasePWMap pw1, BasePWMap pw2); -template BasePWMap combine(BasePWMap pw1, BasePWMap pw2); -template BasePWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4); -template BasePWMap minMap(Interval i, LExp le1, LExp le2); -template BasePWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4); -template BasePWMap minMap(SetPiece dom_piece, Exp e1, Exp e2); -template BasePWMap minMap(UnordSet dom, Exp e1, Exp e2, Exp e3, Exp e4); -template BasePWMap minMap(UnordSet dom, Exp e1, Exp e2); -template BasePWMap minMap(BasePWMap pw1, BasePWMap pw2, BasePWMap pw3, BasePWMap pw4); -template BasePWMap minMap(BasePWMap pw1, BasePWMap pw2); -template BasePWMap reduce(Interval i, LExp e); -template BasePWMap reduce(BaseMap sbgmap); -template BasePWMap reduce(BasePWMap pw); -template BasePWMap minAdjMap(BasePWMap pw1, BasePWMap pw2, BasePWMap pw3); -template BasePWMap minAdjMap(BasePWMap pw1, BasePWMap pw2); -template BasePWMap minInv(UnordSet im, BasePWMap pw); -template BasePWMap minInv(BasePWMap pw); -template BasePWMap filterMap(bool (*f)(BaseMap), BasePWMap pw); -template UnordSet equalImage(BasePWMap pw1, BasePWMap pw2); -template BasePWMap offsetDom(Util::MD_NAT off, BasePWMap pw); -template BasePWMap offsetDom(BasePWMap off, BasePWMap pw); -template BasePWMap offsetImage(Util::MD_NAT off, BasePWMap pw); -template BasePWMap offsetImage(Exp off, BasePWMap pw); -template unsigned int nmbrDims(BasePWMap pw); -template BasePWMap normalize(BasePWMap pw); - -template std::ostream &operator<<(std::ostream &out, const MapSet &ms); -template struct PWMap; -template std::ostream &operator<<(std::ostream &out, const CanonPWMap &pw); -template bool isEmpty(CanonPWMap pw); -template OrdSet dom(CanonPWMap pw); -template CanonPWMap restrict(OrdSet subdom, CanonPWMap pw); -template OrdSet image(CanonPWMap pw); -template OrdSet image(OrdSet subdom, CanonPWMap pw); -template OrdSet preImage(CanonPWMap pw); -template OrdSet preImage(OrdSet subcodom, CanonPWMap pw); -template CanonPWMap mapInf(CanonPWMap pw); -template CanonPWMap composition(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap concatenation(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap combine(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4); -template CanonPWMap minMap(Interval i, LExp le1, LExp le2); -template CanonPWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4); -template CanonPWMap minMap(SetPiece dom_piece, Exp e1, Exp e2); -template CanonPWMap minMap(OrdSet dom, Exp e1, Exp e2, Exp e3, Exp e4); -template CanonPWMap minMap(OrdSet dom, Exp e1, Exp e2); -template CanonPWMap minMap(CanonPWMap pw1, CanonPWMap pw2, CanonPWMap pw3, CanonPWMap pw4); -template CanonPWMap minMap(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap reduce(Interval i, LExp e); -template CanonPWMap reduce(CanonMap sbgmap); -template CanonPWMap reduce(CanonPWMap pw); -template CanonPWMap minAdjMap(CanonPWMap pw1, CanonPWMap pw2, CanonPWMap pw3); -template CanonPWMap minAdjMap(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap minInv(OrdSet im, CanonPWMap pw); -template CanonPWMap minInv(CanonPWMap pw); -template CanonPWMap filterMap(bool (*f)(CanonMap), CanonPWMap pw); -template OrdSet equalImage(CanonPWMap pw1, CanonPWMap pw2); -template CanonPWMap offsetDom(Util::MD_NAT off, CanonPWMap pw); -template CanonPWMap offsetDom(CanonPWMap off, CanonPWMap pw); -template CanonPWMap offsetImage(Util::MD_NAT off, CanonPWMap pw); -template CanonPWMap offsetImage(Exp off, CanonPWMap pw); -template unsigned int nmbrDims(CanonPWMap pw); -template CanonPWMap normalize(CanonPWMap pw); - } // namespace LIB } // namespace SBG diff --git a/sbg/pw_map.hpp b/sbg/pw_map.hpp index 321c4ed..244be80 100755 --- a/sbg/pw_map.hpp +++ b/sbg/pw_map.hpp @@ -24,7 +24,7 @@ #ifndef SBG_PWMAP_HPP #define SBG_PWMAP_HPP -#include +#include #include "sbg/map.hpp" @@ -36,43 +36,27 @@ namespace LIB { * @brief Unordered collection of maps. */ -template -struct LTMap { - LTMap(); +using MapSet = boost::unordered::unordered_flat_set; +std::ostream &operator<<(std::ostream &out, const MapSet &ms); - bool operator()(const SBGMap &x, const SBGMap &y) const; -}; - - -template -using MapSet = boost::container::flat_set, LTMap, boost::container::new_allocator>>; -template -using MapSetIt = typename MapSet::iterator; -template -using MapSetConstIt = typename MapSet::const_iterator; -template -std::ostream &operator<<(std::ostream &out, const MapSet &ms); - -template struct PWMap { - typedef MapSetIt iterator; - typedef MapSetConstIt const_iterator; + typedef MapSet::iterator iterator; + typedef MapSet::const_iterator const_iterator; - member_class(MapSet, maps); + member_class(MapSet, maps); PWMap(); PWMap(Set s); // Create id with s as domain - PWMap(SBGMap m); - PWMap(MapSet maps); + PWMap(SBGMap m); + PWMap(MapSet maps); iterator begin(); iterator end(); std::size_t size(); - void emplace(SBGMap m); - void emplace_hint(MapSetIt it, SBGMap m); - void emplaceBack(SBGMap m); - SBGMap &operator[](std::size_t n); + void emplace(SBGMap m); + void emplace_hint(iterator it, SBGMap m); + void emplaceBack(SBGMap m); PWMap operator+(const PWMap &pw); @@ -80,44 +64,29 @@ struct PWMap { eq_class(PWMap); neq_class(PWMap); }; -template -std::ostream &operator<<(std::ostream &out, const PWMap &pw); +std::ostream &operator<<(std::ostream &out, const PWMap &pw); /** * @brief Traditional map operations. */ -template -bool isEmpty(PWMap pw); - -template -Set dom(PWMap pw); - -template -PWMap restrict(Set subdom, PWMap pw); - -template -Set image(PWMap pw); - -template -Set image(Set subdom, PWMap pw); +bool isEmpty(PWMap pw); +Set dom(PWMap pw); +PWMap restrict(Set subdom, PWMap pw); -template -Set preImage(PWMap pw); +Set image(PWMap pw); +Set image(Set subdom, PWMap pw); -template -Set preImage(Set subcodom, PWMap pw); +Set preImage(PWMap pw); +Set preImage(Set subcodom, PWMap pw); -template -PWMap mapInf(PWMap pw, unsigned int n); -template -PWMap mapInf(PWMap pw); +PWMap mapInf(PWMap pw, unsigned int n); +PWMap mapInf(PWMap pw); /** @function composition * * @brief Apply first pw2, then pw1 (i.e. pw1(pw2(x)) is calculated). */ -template -PWMap composition(PWMap pw1, PWMap pw2); +PWMap composition(PWMap pw1, PWMap pw2); /** * @brief Extra operations. @@ -128,10 +97,8 @@ PWMap composition(PWMap pw1, PWMap pw2); * @brief Concatenation of two pwis. * !!! Result is correct iff pw1 and pw2 are domain-disjoint. */ -template -PWMap concatenation(PWMap pw1, PWMap pw2); -template -PWMap combine(PWMap pw1, PWMap pw2); +PWMap concatenation(PWMap pw1, PWMap pw2); +PWMap combine(PWMap pw1, PWMap pw2); /** @function reduce * @@ -143,64 +110,38 @@ PWMap combine(PWMap pw1, PWMap pw2); * - x-h * - h */ -template -PWMap reduce(Interval i, LExp e); -template -PWMap reduce(SBGMap sbgmap); -template -PWMap reduce(PWMap pw); - -template -PWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4); -template -PWMap minMap(Interval i, LExp le1, LExp le2); -template -PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4); -template -PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2); -template -PWMap minMap(Set dom, Exp e1, Exp e2, Exp e3, Exp e4); -template -PWMap minMap(Set dom, Exp e1, Exp e2); -template -PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4); -template -PWMap minMap(PWMap pw1, PWMap pw2); - -template -PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3); -template -PWMap minAdjMap(PWMap pw1, PWMap pw2); - -template -PWMap minInv(Set im, PWMap pw); -template -PWMap minInv(PWMap pw); - -template -PWMap filterMap(bool (*f)(SBGMap), PWMap pw); +PWMap reduce(Interval i, LExp e); +PWMap reduce(SBGMap sbgmap); +PWMap reduce(PWMap pw); + +PWMap minMap(Interval i, LExp le1, LExp le2, LExp le3, LExp le4); +PWMap minMap(Interval i, LExp le1, LExp le2); +PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2, Exp e3, Exp e4); +PWMap minMap(SetPiece dom_piece, Exp e1, Exp e2); +PWMap minMap(Set dom, Exp e1, Exp e2, Exp e3, Exp e4); +PWMap minMap(Set dom, Exp e1, Exp e2); +PWMap minMap(PWMap pw1, PWMap pw2, PWMap pw3, PWMap pw4); +PWMap minMap(PWMap pw1, PWMap pw2); + +PWMap minAdjMap(PWMap pw1, PWMap pw2, PWMap pw3); +PWMap minAdjMap(PWMap pw1, PWMap pw2); + +PWMap minInv(Set im, PWMap pw); +PWMap minInv(PWMap pw); + +PWMap filterMap(bool (*f)(SBGMap), PWMap pw); // Returns elements in both doms, that have the same image in both maps -template -Set equalImage(PWMap pw1, PWMap pw2); - -template -PWMap offsetDom(Util::MD_NAT off, PWMap pw); -template -PWMap offsetDom(PWMap off, PWMap pw); -template -PWMap offsetImage(Util::MD_NAT off, PWMap pw); -template -PWMap offsetImage(Exp off, PWMap pw); - -template -unsigned int nmbrDims(PWMap pw); - -template -PWMap normalize(PWMap pw); - -typedef PWMap BasePWMap; -typedef PWMap CanonPWMap; +Set equalImage(PWMap pw1, PWMap pw2); + +PWMap offsetDom(Util::MD_NAT off, PWMap pw); +PWMap offsetDom(PWMap off, PWMap pw); +PWMap offsetImage(Util::MD_NAT off, PWMap pw); +PWMap offsetImage(Exp off, PWMap pw); + +unsigned int nmbrDims(PWMap pw); + +PWMap normalize(PWMap pw); } // namespace LIB diff --git a/sbg/sbg.cpp b/sbg/sbg.cpp index 5918e2f..055b707 100755 --- a/sbg/sbg.cpp +++ b/sbg/sbg.cpp @@ -25,21 +25,19 @@ namespace LIB { // SBG ------------------------------------------------------------------------- -template -SBGraph::SBGraph() : V_(), Vmap_(), E_(), map1_(), map2_(), Emap_() {} -template -SBGraph::SBGraph(Set V, PWMap Vmap, PWMap map1, PWMap map2, PWMap Emap) - : V_(V), Vmap_(Vmap), E_(intersection(dom(map1), dom(map2))), map1_(map1), map2_(map2), Emap_(Emap) {} - -member_imp_temp(template, SBGraph, Set, V); -member_imp_temp(template, SBGraph, PWMap, Vmap); -member_imp_temp(template, SBGraph, Set, E); -member_imp_temp(template, SBGraph, PWMap, map1); -member_imp_temp(template, SBGraph, PWMap, map2); -member_imp_temp(template, SBGraph, PWMap, Emap); - -template -std::ostream &operator<<(std::ostream &out, const SBGraph &g) +SBGraph::SBGraph() : V_(), Vmap_(), E_(), map1_(), map2_(), Emap_() {} +SBGraph::SBGraph(Set V, PWMap Vmap, PWMap map1, PWMap map2, PWMap Emap) + : V_(V), Vmap_(Vmap), E_(intersection(dom(map1), dom(map2))), map1_(map1), map2_(map2), Emap_(Emap) +{} + +member_imp(SBGraph, Set, V); +member_imp(SBGraph, PWMap, Vmap); +member_imp(SBGraph, Set, E); +member_imp(SBGraph, PWMap, map1); +member_imp(SBGraph, PWMap, map2); +member_imp(SBGraph, PWMap, Emap); + +std::ostream &operator<<(std::ostream &out, const SBGraph &g) { out << "V = " << g.V() << ";\n"; out << "Vmap = " << g.Vmap() << ";\n\n"; @@ -51,48 +49,49 @@ std::ostream &operator<<(std::ostream &out, const SBGraph &g) return out; } -template -SBGraph addSV(Set vertices, SBGraph g) +SBGraph addSV(Set vertices, SBGraph g) { if (!isEmpty(vertices) && isEmpty(intersection(vertices, g.V()))) { SBGraph res = g; res.set_V(cup(g.V(), vertices)); - Set SV = image(g.Vmap()); // Identifiers of SV + Set SV = image(g.Vmap()); // Identifiers of SV Util::NAT max = maxElem(SV)[0]; std::size_t dims = maxElem(SV).size(); MDLExp to_max(dims, LExp(0, Util::RATIONAL(max + 1))); - PWMap new_Vmap(SBGMap(vertices, to_max)); + PWMap new_Vmap(SBGMap(vertices, to_max)); res.set_Vmap(concatenation(g.Vmap(), new_Vmap)); return res; } - else Util::ERROR("LIB::SBG::addSV: vertices should be non-empty and disjoint from current vertices"); + else + Util::ERROR("LIB::SBG::addSV: vertices should be non-empty and disjoint from current vertices"); - return SBGraph(); + return SBGraph(); } -template -unsigned int nmbrSV(SBGraph g) { return image(g.Vmap()).size(); } +unsigned int nmbrSV(SBGraph g) +{ + return image(g.Vmap()).size(); +} -template -SBGraph addSE(PWMap pw1, PWMap pw2, SBGraph g) +SBGraph addSE(PWMap pw1, PWMap pw2, SBGraph g) { Set edges, edges1 = dom(pw1), edges2 = dom(pw2); if (edges1 == edges2) { edges = intersection(edges1, edges2); if (!isEmpty(edges) && isEmpty(intersection(edges, g.E()))) { - SBGraph res = g; + SBGraph res = g; res.set_E(cup(g.E(), edges)); - Set SE = image(g.Emap()); // Identifiers of SV + Set SE = image(g.Emap()); // Identifiers of SV Util::NAT max = maxElem(SE)[0]; std::size_t dims = maxElem(SE).size(); MDLExp to_max(dims, LExp(0, Util::RATIONAL(max + 1))); - PWMap new_Emap(SBGMap(edges, to_max)); + PWMap new_Emap(SBGMap(edges, to_max)); res.set_Emap(concatenation(g.Emap(), new_Emap)); res.set_map1(concatenation(g.map1(), pw1)); @@ -101,22 +100,23 @@ SBGraph addSE(PWMap pw1, PWMap pw2, SBGraph g) return res; } - else Util::ERROR("LIB::SBG::addSE: edges should be non-empty and disjoint from current vertices"); + else + Util::ERROR("LIB::SBG::addSE: edges should be non-empty and disjoint from current vertices"); } - else Util::ERROR("LIB::SBG::addSE: maps domains should coincide"); + else + Util::ERROR("LIB::SBG::addSE: maps domains should coincide"); - return SBGraph(); + return SBGraph(); } -template -SBGraph copy(unsigned int times, SBGraph g) +SBGraph copy(unsigned int times, SBGraph g) { Set V_ith = g.V(), V_new = V_ith; - PWMap Vmap_ith = g.Vmap(), Vmap_new = Vmap_ith; - PWMap map1_ith = g.map1(), map1_new = map1_ith; - PWMap map2_ith = g.map2(), map2_new = map2_ith; - PWMap Emap_ith = g.Emap(), Emap_new = Emap_ith; + PWMap Vmap_ith = g.Vmap(), Vmap_new = Vmap_ith; + PWMap map1_ith = g.map1(), map1_new = map1_ith; + PWMap map2_ith = g.map2(), map2_new = map2_ith; + PWMap Emap_ith = g.Emap(), Emap_new = Emap_ith; Util::MD_NAT maxv = maxElem(V_ith); Util::MD_NAT maxV = maxElem(image(Vmap_ith)); @@ -124,7 +124,8 @@ SBGraph copy(unsigned int times, SBGraph g) Util::MD_NAT maxE = maxElem(image(Emap_ith)); Exp off; - parallel_foreach2 (maxv.value_ref(), maxe.value_ref()) { + parallel_foreach2(maxv.value_ref(), maxe.value_ref()) + { Util::NAT v = boost::get<0>(items), e = boost::get<1>(items); Util::RATIONAL o = Util::RATIONAL(v) - Util::RATIONAL(e); off.emplaceBack(LExp(0, o)); @@ -151,26 +152,25 @@ SBGraph copy(unsigned int times, SBGraph g) Emap_ith = offsetImage(maxE, Emap_ith); } - return SBGraph(V_new, Vmap_new, map1_new, map2_new, Emap_new); + return SBGraph(V_new, Vmap_new, map1_new, map2_new, Emap_new); } // Directed SBG ---------------------------------------------------------------- -template -DSBGraph::DSBGraph() : V_(), Vmap_(), E_(), mapB_(), mapD_(), Emap_() {} -template -DSBGraph::DSBGraph(Set V, PWMap Vmap, PWMap mapB, PWMap mapD, PWMap Emap) - : V_(V), Vmap_(Vmap), E_(intersection(dom(mapB), dom(mapD))), mapB_(mapB), mapD_(mapD), Emap_(Emap) {} - -member_imp_temp(template, DSBGraph, Set, V); -member_imp_temp(template, DSBGraph, PWMap, Vmap); -member_imp_temp(template, DSBGraph, Set, E); -member_imp_temp(template, DSBGraph, PWMap, mapB); -member_imp_temp(template, DSBGraph, PWMap, mapD); -member_imp_temp(template, DSBGraph, PWMap, Emap); - -template -std::ostream &operator<<(std::ostream &out, const DSBGraph &g) +DSBGraph::DSBGraph() : V_(), Vmap_(), E_(), mapB_(), mapD_(), Emap_() {} +DSBGraph::DSBGraph(Set V, PWMap Vmap, PWMap mapB, PWMap mapD, PWMap Emap) + : V_(V), Vmap_(Vmap), E_(intersection(dom(mapB), dom(mapD))), mapB_(mapB), mapD_(mapD), Emap_(Emap) +{ +} + +member_imp(DSBGraph, Set, V); +member_imp(DSBGraph, PWMap, Vmap); +member_imp(DSBGraph, Set, E); +member_imp(DSBGraph, PWMap, mapB); +member_imp(DSBGraph, PWMap, mapD); +member_imp(DSBGraph, PWMap, Emap); + +std::ostream &operator<<(std::ostream &out, const DSBGraph &g) { out << "V = " << g.V() << ";\n"; out << "Vmap = " << g.Vmap() << ";\n\n"; @@ -182,92 +182,64 @@ std::ostream &operator<<(std::ostream &out, const DSBGraph &g) return out; } -template -DSBGraph addSV(Set vertices, DSBGraph g) +DSBGraph addSV(Set vertices, DSBGraph g) { if (!isEmpty(vertices) && isEmpty(intersection(vertices, g.V()))) { DSBGraph res = g; res.set_V(cup(g.V(), vertices)); - Set SV = image(g.Vmap()); // Identifiers of SV + Set SV = image(g.Vmap()); // Identifiers of SV Util::NAT max = maxElem(SV)[0]; std::size_t dims = maxElem(SV).size(); MDLExp to_max(dims, LExp(0, Util::RATIONAL(max + 1))); - PWMap new_Vmap(SBGMap(vertices, to_max)); + PWMap new_Vmap(SBGMap(vertices, to_max)); res.set_Vmap(concatenation(g.Vmap(), new_Vmap)); return res; } - else Util::ERROR("LIB::SBG::addSV: vertices should be non-empty and disjoint from current vertices"); + else + Util::ERROR("LIB::SBG::addSV: vertices should be non-empty and disjoint from current vertices"); - return DSBGraph(); + return DSBGraph(); } -template -unsigned int nmbrSV(DSBGraph g) { return image(g.Vmap()).size(); } +unsigned int nmbrSV(DSBGraph g) { return image(g.Vmap()).size(); } -template -DSBGraph addSE(PWMap pw1, PWMap pw2, DSBGraph g) +DSBGraph addSE(PWMap pw1, PWMap pw2, DSBGraph g) { Set edges, edges1 = dom(pw1), edges2 = dom(pw2); if (edges1 == edges2) { edges = intersection(edges1, edges2); if (!isEmpty(edges) && isEmpty(intersection(edges, g.E()))) { - DSBGraph res; + DSBGraph res; g.set_E(cup(g.E(), edges)); - Set SE = image(g.Emap()); // Identifiers of SV + Set SE = image(g.Emap()); // Identifiers of SV Util::NAT max = maxElem(SE)[0]; std::size_t dims = maxElem(SE).size(); MDLExp to_max(dims, LExp(0, Util::RATIONAL(max + 1))); - PWMap new_Emap(SBGMap(edges, to_max)); + PWMap new_Emap(SBGMap(edges, to_max)); g.set_Emap(concatenation(g.Emap(), new_Emap)); g.set_mapB(concatenation(g.mapB(), pw1)); g.set_mapD(concatenation(g.mapD(), pw2)); - + return res; } - else Util::ERROR("LIB::SBG::addSE: edges should be non-empty and disjoint from current vertices"); + else + Util::ERROR("LIB::SBG::addSE: edges should be non-empty and disjoint from current vertices"); } - else Util::ERROR("LIB::SBG::addSE: maps domains should coincide"); + else + Util::ERROR("LIB::SBG::addSE: maps domains should coincide"); - return DSBGraph(); + return DSBGraph(); } -// Template instantiations ----------------------------------------------------- - -template struct SBGraph; -template std::ostream &operator<<(std::ostream &out, const BaseSBG &g); -template BaseSBG addSV(UnordSet vertices, BaseSBG g); -template unsigned int nmbrSV(BaseSBG g); -template BaseSBG addSE(BasePWMap pw1, BasePWMap pw2, BaseSBG g); -template BaseSBG copy(unsigned int times, BaseSBG g); - -template struct SBGraph; -template std::ostream &operator<<(std::ostream &out, const CanonSBG &g); -template CanonSBG addSV(OrdSet vertices, CanonSBG g); -template unsigned int nmbrSV(CanonSBG g); -template CanonSBG addSE(CanonPWMap pw1, CanonPWMap pw2, CanonSBG g); -template CanonSBG copy(unsigned int times, CanonSBG g); - -template struct DSBGraph; -template std::ostream &operator<<(std::ostream &out, const BaseDSBG &g); -template BaseDSBG addSV(UnordSet vertices, BaseDSBG g); -template unsigned int nmbrSV(BaseDSBG g); -template BaseDSBG addSE(BasePWMap pw1, BasePWMap pw2, BaseDSBG g); - -template struct DSBGraph; -template std::ostream &operator<<(std::ostream &out, const CanonDSBG &g); -template CanonDSBG addSV(OrdSet vertices, CanonDSBG g); -template unsigned int nmbrSV(CanonDSBG g); -template CanonDSBG addSE(CanonPWMap pw1, CanonPWMap pw2, CanonDSBG g); - } // namespace LIB } // namespace SBG diff --git a/sbg/sbg.hpp b/sbg/sbg.hpp index 8bdb2db..520e4ae 100755 --- a/sbg/sbg.hpp +++ b/sbg/sbg.hpp @@ -32,70 +32,51 @@ namespace LIB { // Undirected SBG -------------------------------------------------------------- -template struct SBGraph { // Vertex definitions member_class(Set, V); - member_class(PWMap, Vmap); + member_class(PWMap, Vmap); // Edge definitions member_class(Set, E); - member_class(PWMap, map1); - member_class(PWMap, map2); - member_class(PWMap, Emap); + member_class(PWMap, map1); + member_class(PWMap, map2); + member_class(PWMap, Emap); SBGraph(); - SBGraph(Set V, PWMap VMap, PWMap map1, PWMap map2, PWMap Emap); + SBGraph(Set V, PWMap VMap, PWMap map1, PWMap map2, PWMap Emap); }; -template -std::ostream &operator<<(std::ostream &out, const SBGraph &pw); +std::ostream &operator<<(std::ostream &out, const SBGraph &pw); -template -void addSV(Set vertices, SBGraph &g); +void addSV(Set vertices, SBGraph &g); +unsigned int nmbrSV(SBGraph g); -template -unsigned int nmbrSV(SBGraph g); +void addSE(Set edges, SBGraph &g); -template -void addSE(Set edges, SBGraph &g); - -template -SBGraph copy(unsigned int times, SBGraph g); - -typedef SBGraph BaseSBG; -typedef SBGraph CanonSBG; +SBGraph copy(unsigned int times, SBGraph g); // Directed SBG ---------------------------------------------------------------- -template struct DSBGraph { // Vertex definitions member_class(Set, V); - member_class(PWMap, Vmap); + member_class(PWMap, Vmap); // Edge definitions member_class(Set, E); - member_class(PWMap, mapB); - member_class(PWMap, mapD); - member_class(PWMap, Emap); + member_class(PWMap, mapB); + member_class(PWMap, mapD); + member_class(PWMap, Emap); DSBGraph(); - DSBGraph(Set V, PWMap VMap, PWMap mapB, PWMap mapD, PWMap Emap); + DSBGraph(Set V, PWMap VMap, PWMap mapB, PWMap mapD, PWMap Emap); }; -template -std::ostream &operator<<(std::ostream &out, const DSBGraph &pw); - -template -void addSV(Set vertices, DSBGraph &g); - -template -unsigned int nmbrSV(DSBGraph g); +std::ostream &operator<<(std::ostream &out, const DSBGraph &pw); -template -void addSE(Set edges, DSBGraph &g); +void addSV(Set vertices, DSBGraph &g); +unsigned int nmbrSV(DSBGraph g); -typedef DSBGraph BaseDSBG; -typedef DSBGraph CanonDSBG; +void addSE(Set edges, DSBGraph &g); } // namespace LIB diff --git a/sbg/sbg_algorithms.cpp b/sbg/sbg_algorithms.cpp index f9d7d57..2c7823e 100755 --- a/sbg/sbg_algorithms.cpp +++ b/sbg/sbg_algorithms.cpp @@ -27,24 +27,23 @@ namespace LIB { // Connected components -------------------------------------------------------- // ----------------------------------------------------------------------------- -template -PWMap connectedComponents(SBGraph g) +PWMap connectedComponents(SBGraph g) { if (!isEmpty(g.V())) { unsigned int dims = g.V()[0].size(); - SBGMap id(g.V(), Exp(dims)); - PWMap rmap(id), old_rmap; + SBGMap id(g.V(), Exp(dims)); + PWMap rmap(id), old_rmap; if (isEmpty(g.E())) return rmap; do { old_rmap = rmap; - PWMap ermap1 = composition(rmap, g.map1()); - PWMap ermap2 = composition(rmap, g.map2()); + PWMap ermap1 = composition(rmap, g.map1()); + PWMap ermap2 = composition(rmap, g.map2()); - PWMap rmap1 = minAdjMap(ermap1, ermap2); - PWMap rmap2 = minAdjMap(ermap2, ermap1); + PWMap rmap1 = minAdjMap(ermap1, ermap2); + PWMap rmap2 = minAdjMap(ermap2, ermap1); rmap1 = combine(rmap1, rmap); rmap2 = combine(rmap2, rmap); @@ -60,38 +59,33 @@ PWMap connectedComponents(SBGraph g) return rmap; } - return PWMap(); + return PWMap(); } // ----------------------------------------------------------------------------- // Minimum reachable ----------------------------------------------------------- // ----------------------------------------------------------------------------- -template -PathInfo::PathInfo() : succs_(), reps_() {} -template -PathInfo::PathInfo(PWMap succs, PWMap reps) : succs_(succs), reps_(reps) {} +PathInfo::PathInfo() : succs_(), reps_() {} +PathInfo::PathInfo(PWMap succs, PWMap reps) : succs_(succs), reps_(reps) {} -member_imp_temp(template, PathInfo, PWMap, succs); -member_imp_temp(template, PathInfo, PWMap, reps); +member_imp(PathInfo, PWMap, succs); +member_imp(PathInfo, PWMap, reps); -template -bool eqId(SBGMap sbgmap) { return isId(sbgmap); } +bool eqId(SBGMap sbgmap) { return isId(sbgmap); } -template -bool notEqId(SBGMap sbgmap) { return !(isId(sbgmap)); } +bool notEqId(SBGMap sbgmap) { return !(isId(sbgmap)); } // Update rep iff new is less than current. Without this function, if there are // vertices v1, v2, v3 and edges v1->v2, v1->v3 where rmap(v2) = rmap(v3) the // algorithm could switch infinitely between those two reps. -template -PWMap updateMap(Set V, PWMap smap, PWMap new_smap, PWMap rmap) +PWMap updateMap(Set V, PWMap smap, PWMap new_smap, PWMap rmap) { SetPiece mi_zero(V[0].size(), Interval(0)); Set zero(mi_zero); - PWMap res; - PWMap vto_rep = composition(rmap, smap), new_vto_rep = composition(rmap, new_smap); + PWMap res; + PWMap vto_rep = composition(rmap, smap), new_vto_rep = composition(rmap, new_smap); Set not_updated = equalImage(vto_rep, new_vto_rep); res = restrict(not_updated, smap); @@ -100,18 +94,14 @@ PWMap updateMap(Set V, PWMap smap, PWMap new_smap, PWMap rma return res; } -template -PWMap minReach1(Set V, Set E, PWMap mapB, PWMap mapD, PWMap smap, PWMap rmap) +PWMap minReach1(Set V, Set E, PWMap mapB, PWMap mapD, PWMap smap, PWMap rmap) { - SetPiece mi_zero(V[0].size(), Interval(0)); - Set zero(mi_zero); - - PWMap auto_succs = filterMap(eqId, smap); + PWMap auto_succs = filterMap(eqId, smap); Set auto_reps = equalImage(auto_succs, rmap); Set usable_verts = cup(auto_reps, dom(filterMap(notEqId, smap))); - PWMap auxB = restrict(E, mapB), auxD = restrict(E, mapD); - PWMap adj_smap = minAdjMap(auxB, auxD, rmap); // Get minimum adjacent vertex with minimum representative + PWMap auxB = restrict(E, mapB), auxD = restrict(E, mapD); + PWMap adj_smap = minAdjMap(auxB, auxD, rmap); // Get minimum adjacent vertex with minimum representative PWMap new_smap = minMap(rmap, adj_smap, restrict(usable_verts, smap), rmap); // Get minimum between current rep and adjacent reps new_smap = updateMap(V, smap, new_smap, rmap); // Update rep iff new is less than current new_smap = combine(new_smap, adj_smap); @@ -121,11 +111,10 @@ PWMap minReach1(Set V, Set E, PWMap mapB, PWMap mapD, PWMap } // Handle ONE recursion -template -PathInfo MinReach::recursion(unsigned int n, Set ER, Set rv, PWMap smap, PWMap rmap) +PathInfo MinReach::recursion(unsigned int n, Set ER, Set rv, PWMap smap, PWMap rmap) { - PWMap mapB = dsbg().mapB(), mapD = dsbg().mapD(), Emap = dsbg().Emap(), Vmap = dsbg().Vmap(); - PWMap ERB = restrict(ER, mapB), ERD = restrict(ER, mapD); + PWMap mapB = dsbg().mapB(), mapD = dsbg().mapD(), Emap = dsbg().Emap(), Vmap = dsbg().Vmap(); + PWMap ERB = restrict(ER, mapB), ERD = restrict(ER, mapD); Set start = image(ERB), end = image(ERD), aux_start = start; start = difference(start, end), end = difference(end, aux_start); @@ -133,7 +122,7 @@ PathInfo MinReach::recursion(unsigned int n, Set ER, Set rv, PWMap new_smap; + PWMap new_smap; Set repeated = intersection(start, end); Set available_vertices = dsbg().V(); while (isEmpty(repeated)) { @@ -141,8 +130,8 @@ PathInfo MinReach::recursion(unsigned int n, Set ER, Set rv, PWMap sideB = restrict(ER_plus_side, mapB), sideD = restrict(ER_plus_side, mapD); - PWMap ith = restrict(available_vertices, composition(sideD, minInv(sideB))); + PWMap sideB = restrict(ER_plus_side, mapB), sideD = restrict(ER_plus_side, mapD); + PWMap ith = restrict(available_vertices, composition(sideD, minInv(sideB))); new_smap = combine(ith, new_smap); start = image(start, smap); @@ -152,35 +141,29 @@ PathInfo MinReach::recursion(unsigned int n, Set ER, Set rv, PWMap rmap_plus = composition(rmap, mapInf(new_smap, n)); // Solve recursion - PWMap new_rmap = minMap(rmap, rmap_plus); + PWMap rmap_plus = composition(rmap, mapInf(new_smap, n)); // Solve recursion + PWMap new_rmap = minMap(rmap, rmap_plus); new_rmap = combine(new_rmap, rmap); - return PathInfo(new_smap, new_rmap); + return PathInfo(new_smap, new_rmap); } -template -MinReach::MinReach() : dsbg_() {} -template -MinReach::MinReach(DSBGraph sbg) : dsbg_(sbg) {} +MinReach::MinReach() : dsbg_() {} +MinReach::MinReach(DSBGraph sbg) : dsbg_(sbg) {} -member_imp_temp(template, MinReach, DSBGraph, dsbg); +member_imp(MinReach, DSBGraph, dsbg); -template -PathInfo MinReach::calculate(Set unmatched_V) +PathInfo MinReach::calculate(Set unmatched_V) { DSBGraph dg = dsbg(); if (!isEmpty(dg.V())) { Set V = dg.V(), E = dg.E(); - PWMap mapB = dg.mapB(), mapD = dg.mapD(), Emap = dg.Emap(); + PWMap mapB = dg.mapB(), mapD = dg.mapD(), Emap = dg.Emap(); - SetPiece mi_zero(V[0].size(), Interval(0)); - Set zero(mi_zero); - - PWMap old_smap, old_semap; // Old vertex and edge successors maps - PWMap new_smap(V), new_semap(E); // New vertex and edge successors maps - PWMap new_rmap(V); // New vertex reps map + PWMap old_smap, old_semap; // Old vertex and edge successors maps + PWMap new_smap(V), new_semap(E); // New vertex and edge successors maps + PWMap new_rmap(V); // New vertex reps map Set Vc; // Vertices that changed sucessor Set Ec; // Edges that changed successor @@ -202,7 +185,7 @@ PathInfo MinReach::calculate(Set unmatched_V) if (!isEmpty(intersection(reach_vertices, unmatched_B))) { new_rmap = mapInf(new_smap); // Get minimum reachable following path - return PathInfo(new_smap, new_rmap); + return PathInfo(new_smap, new_rmap); } if (!isEmpty(Vc)) { @@ -211,7 +194,7 @@ PathInfo MinReach::calculate(Set unmatched_V) Set E_succ = equalImage(mapD, composition(new_smap, mapB)); if (!isEmpty(E_succ)) { // A new path was chosen old_semap = new_semap; - PWMap mapB_succ = restrict(E_succ, mapB), mapD_succ = restrict(E_succ, mapD); + PWMap mapB_succ = restrict(E_succ, mapB), mapD_succ = restrict(E_succ, mapD); new_semap = composition(minInv(E_succ, mapB_succ), mapD_succ); new_semap = combine(new_semap, old_semap); @@ -220,7 +203,7 @@ PathInfo MinReach::calculate(Set unmatched_V) if (!isEmpty(Ec)) { Set ER; // Recursive edges that changed its successor - PWMap old_semap_nth, semap_nth = composition(new_semap, new_semap); + PWMap old_semap_nth, semap_nth = composition(new_semap, new_semap); unsigned int j = 0; do { // The max depth of recursion is the number of SVs ER = equalImage(Emap, composition(Emap, filterMap(notEqId, semap_nth))); @@ -238,7 +221,7 @@ PathInfo MinReach::calculate(Set unmatched_V) } if (!isEmpty(ER)) { // There are recursions, lets handle one of them - PathInfo res = recursion(j, ER, reach_vertices, new_smap, new_rmap); + PathInfo res = recursion(j, ER, reach_vertices, new_smap, new_rmap); new_smap = res.succs(); new_rmap = res.reps(); } @@ -247,10 +230,10 @@ PathInfo MinReach::calculate(Set unmatched_V) } } while (!isEmpty(Vc)); - return PathInfo(new_smap, new_rmap); + return PathInfo(new_smap, new_rmap); } - return PathInfo(); + return PathInfo(); } // ----------------------------------------------------------------------------- @@ -261,13 +244,12 @@ PathInfo MinReach::calculate(Set unmatched_V) bool moreThanOne(SetPiece mdi) { return cardinal(mdi) > 1; } -template -Set SBGMatching::getManyToOne() +Set SBGMatching::getManyToOne() { Set res; - BOOST_FOREACH (SBGMap sbgmapB, mapB_ref()) { - BOOST_FOREACH (SBGMap sbgmapD, mapD_ref()) { + for (SBGMap sbgmapB : mapB_ref()) { + for (SBGMap sbgmapD : mapD_ref()) { Exp expB = sbgmapB.exp(), expD = sbgmapD.exp(); if (isConstant(expD)) { Set dom = intersection(sbgmapB.dom(), sbgmapD.dom()); @@ -285,13 +267,12 @@ Set SBGMatching::getManyToOne() return res; } -template -void SBGMatching::shortPathDirection(Set endings, Direction dir) +void SBGMatching::shortPathDirection(Set endings, Direction dir) { - PWMap auxB = restrict(paths_edges(), mapB()), auxD = restrict(paths_edges(), mapD()); + PWMap auxB = restrict(paths_edges(), mapB()), auxD = restrict(paths_edges(), mapD()); - set_smap(PWMap(V())); - set_rmap(PWMap(V())); + set_smap(PWMap(V())); + set_rmap(PWMap(V())); Set reach_end = endings; // Vertices that reach endings Set P; // Vertices adjacent to reach_end @@ -308,10 +289,10 @@ void SBGMatching::shortPathDirection(Set endings, Direction dir) P = image(preImage(reach_end, auxD), auxB); // Start of edges entering reach_end P = difference(P, reach_end); // Take out vertices that are self-reps Set reach_edges = intersection(preImage(P, auxB), preImage(reach_end, auxD)); // Edges that reach reach_end - PWMap starts = minInv(reach_edges, auxB); // Map from starts to the edges that take them to reach_end - PWMap smap_reach = composition(auxD, starts); + PWMap starts = minInv(reach_edges, auxB); // Map from starts to the edges that take them to reach_end + PWMap smap_reach = composition(auxD, starts); set_smap(combine(smap_reach, smap())); - PWMap rmap_reach = composition(rmap(), smap_reach); + PWMap rmap_reach = composition(rmap(), smap_reach); set_rmap(combine(rmap_reach, rmap())); reach_end = cup(reach_end, P); @@ -325,8 +306,7 @@ void SBGMatching::shortPathDirection(Set endings, Direction dir) return; } -template -void SBGMatching::shortPathStep() +void SBGMatching::shortPathStep() { // *** Forward direction shortPathDirection(unmatched_F(), forward); @@ -334,7 +314,7 @@ void SBGMatching::shortPathStep() set_paths_edges(pe); // *** Backward direction - PWMap auxB = mapB(); + PWMap auxB = mapB(); set_mapB(mapD()); set_mapD(auxB); @@ -352,8 +332,7 @@ void SBGMatching::shortPathStep() return; } -template -void SBGMatching::shortPath() +void SBGMatching::shortPath() { Set allowed_edges = difference(E(), getManyToOne()); @@ -372,48 +351,44 @@ void SBGMatching::shortPath() // Minimum reachable ----------------------------------------------------------- -template -PWMap SBGMatching::directedOffset(PWMap dir_map) +PWMap SBGMatching::directedOffset(PWMap dir_map) { Set unmatched_side = image(paths_edges(), dir_map); unmatched_side = intersection(unmatched_side, unmatched_V()); Util::MD_NAT max_dirV = maxElem(image(omap())); - PWMap res = restrict(unmatched_side, omap()); + PWMap res = restrict(unmatched_side, omap()); res = offsetImage(max_dirV, res); return combine(res, omap()); } -template -DSBGraph SBGMatching::offsetGraph(PWMap dir_omap) +DSBGraph SBGMatching::offsetGraph(PWMap dir_omap) { Set _V = image(dir_omap); - PWMap _Vmap = offsetDom(dir_omap, Vmap()); + PWMap _Vmap = offsetDom(dir_omap, Vmap()); - PWMap _mapB = composition(dir_omap, mapB()), _mapD = composition(dir_omap, mapD()); + PWMap _mapB = composition(dir_omap, mapB()), _mapD = composition(dir_omap, mapD()); _mapB = restrict(paths_edges(), _mapB); _mapD = restrict(paths_edges(), _mapD); - return DSBGraph(_V, _Vmap, _mapB, _mapD, restrict(paths_edges(), Emap())); + return DSBGraph(_V, _Vmap, _mapB, _mapD, restrict(paths_edges(), Emap())); } -template -void SBGMatching::directedMinReach(PWMap dir_map) +void SBGMatching::directedMinReach(PWMap dir_map) { - PWMap dir_omap = directedOffset(dir_map); - DSBGraph dsbg = offsetGraph(dir_omap); + PWMap dir_omap = directedOffset(dir_map); + DSBGraph dsbg = offsetGraph(dir_omap); MinReach min_reach(dsbg); - PathInfo res = min_reach.calculate(image(unmatched_V(), dir_omap)); + PathInfo res = min_reach.calculate(image(unmatched_V(), dir_omap)); - PWMap aux_omap = combine(dir_omap, omap()), to_normal = minInv(aux_omap); - PWMap aux_succs = composition(res.succs(), aux_omap); + PWMap aux_omap = combine(dir_omap, omap()), to_normal = minInv(aux_omap); + PWMap aux_succs = composition(res.succs(), aux_omap); set_smap(composition(to_normal, aux_succs)); - PWMap aux_reps = composition(res.reps(), aux_omap); + PWMap aux_reps = composition(res.reps(), aux_omap); set_rmap(composition(to_normal, aux_reps)); } -template -void SBGMatching::minReachableStep() +void SBGMatching::minReachableStep() { // *** Forward direction directedMinReach(mapU()); @@ -423,7 +398,7 @@ void SBGMatching::minReachableStep() set_paths_edges(intersection(pe, reach_unmatched)); // *** Backward direction - PWMap auxB = mapB(); + PWMap auxB = mapB(); set_mapB(mapD()); set_mapD(auxB); @@ -452,8 +427,7 @@ void SBGMatching::minReachableStep() return; } -template -void SBGMatching::minReachable() +void SBGMatching::minReachable() { do { set_paths_edges(E()); @@ -465,16 +439,13 @@ void SBGMatching::minReachable() // Matching -------------------------------------------------------------------- -template -MatchInfo::MatchInfo() : matched_edges_(), fully_matchedU_() {} -template -MatchInfo::MatchInfo(Set matched_edges, bool fully_matchedU) : matched_edges_(matched_edges), fully_matchedU_(fully_matchedU) {} +MatchInfo::MatchInfo() : matched_edges_(), fully_matchedU_() {} +MatchInfo::MatchInfo(Set matched_edges, bool fully_matchedU) : matched_edges_(matched_edges), fully_matchedU_(fully_matchedU) {} -member_imp_temp(template, MatchInfo, Set, matched_edges); -member_imp_temp(template, MatchInfo, bool, fully_matchedU); +member_imp(MatchInfo, Set, matched_edges); +member_imp(MatchInfo, bool, fully_matchedU); -template -std::ostream &operator<<(std::ostream &out, const MatchInfo &m_info) +std::ostream &operator<<(std::ostream &out, const MatchInfo &m_info) { out << m_info.matched_edges(); if (m_info.fully_matchedU()) out << " [FULLY MATCHED]"; @@ -484,16 +455,14 @@ std::ostream &operator<<(std::ostream &out, const MatchInfo &m_info) return out; } -template -SBGMatching::SBGMatching() : sbg_(), V_(), Vmap_(), E_(), Emap_(), smap_(), rmap_(), omap_(), +SBGMatching::SBGMatching() : sbg_(), V_(), Vmap_(), E_(), Emap_(), smap_(), rmap_(), omap_(), max_V_(), F_(), U_(), mapF_(), mapU_(), mapB_(), mapD_(), paths_edges_(), matched_E_(), unmatched_E_(), matched_V_(), unmatched_V_(), unmatched_F_(), matched_U_(), unmatched_U_() {} -template -SBGMatching::SBGMatching(SBGraph sbg) : sbg_(sbg), V_(sbg.V()), Vmap_(sbg.Vmap()), +SBGMatching::SBGMatching(SBGraph sbg) : sbg_(sbg), V_(sbg.V()), Vmap_(sbg.Vmap()), Emap_(sbg.Emap()) { set_E(dom(Emap())); - PWMap id_vertex(V()); + PWMap id_vertex(V()); set_smap(id_vertex); set_rmap(id_vertex); @@ -519,55 +488,52 @@ SBGMatching::SBGMatching(SBGraph sbg) : sbg_(sbg), V_(sbg.V()), Vmap_( set_unmatched_U(U()); } -member_imp_temp(template, SBGMatching, SBGraph, sbg); -member_imp_temp(template, SBGMatching, Set, V); -member_imp_temp(template, SBGMatching, PWMap, Vmap); -member_imp_temp(template, SBGMatching, Set, E); -member_imp_temp(template, SBGMatching, PWMap, Emap); +member_imp(SBGMatching, SBGraph, sbg); +member_imp(SBGMatching, Set, V); +member_imp(SBGMatching, PWMap, Vmap); +member_imp(SBGMatching, Set, E); +member_imp(SBGMatching, PWMap, Emap); -member_imp_temp(template, SBGMatching, PWMap, smap); -member_imp_temp(template, SBGMatching, PWMap, rmap); +member_imp(SBGMatching, PWMap, smap); +member_imp(SBGMatching, PWMap, rmap); -member_imp_temp(template, SBGMatching, PWMap, omap); -member_imp_temp(template, SBGMatching, Util::MD_NAT, max_V); +member_imp(SBGMatching, PWMap, omap); +member_imp(SBGMatching, Util::MD_NAT, max_V); -member_imp_temp(template, SBGMatching, Set, F); -member_imp_temp(template, SBGMatching, Set, U); -member_imp_temp(template, SBGMatching, PWMap, mapF); -member_imp_temp(template, SBGMatching, PWMap, mapU); +member_imp(SBGMatching, Set, F); +member_imp(SBGMatching, Set, U); +member_imp(SBGMatching, PWMap, mapF); +member_imp(SBGMatching, PWMap, mapU); -member_imp_temp(template, SBGMatching, PWMap, mapB); -member_imp_temp(template, SBGMatching, PWMap, mapD); +member_imp(SBGMatching, PWMap, mapB); +member_imp(SBGMatching, PWMap, mapD); -member_imp_temp(template, SBGMatching, Set, paths_edges); -member_imp_temp(template, SBGMatching, Set, matched_E); -member_imp_temp(template, SBGMatching, Set, unmatched_E); +member_imp(SBGMatching, Set, paths_edges); +member_imp(SBGMatching, Set, matched_E); +member_imp(SBGMatching, Set, unmatched_E); -member_imp_temp(template, SBGMatching, Set, matched_V); -member_imp_temp(template, SBGMatching, Set, unmatched_V); -member_imp_temp(template, SBGMatching, Set, unmatched_F); -member_imp_temp(template, SBGMatching, Set, matched_U); -member_imp_temp(template, SBGMatching, Set, unmatched_U); +member_imp(SBGMatching, Set, matched_V); +member_imp(SBGMatching, Set, unmatched_V); +member_imp(SBGMatching, Set, unmatched_F); +member_imp(SBGMatching, Set, matched_U); +member_imp(SBGMatching, Set, unmatched_U); -template -Set SBGMatching::getAllowedEdges() +Set SBGMatching::getAllowedEdges() { Set succs = image(filterMap(notEqId, smap())); // Vertices that are successor of other vertices in a path Set ending_edges = preImage(succs, mapD()); // Edges whose endings are successors - PWMap auxB = restrict(ending_edges, mapB()); // Map from a 'successor' edge to its start - PWMap map_succs = composition(smap(), auxB); // Map from edge to the successor of its start + PWMap auxB = restrict(ending_edges, mapB()); // Map from a 'successor' edge to its start + PWMap map_succs = composition(smap(), auxB); // Map from edge to the successor of its start return equalImage(map_succs, mapD()); // Edges that connect vertices with their successors } -template -bool SBGMatching::fullyMatchedU() { return isEmpty(difference(U(), matched_U())); } +bool SBGMatching::fullyMatchedU() { return isEmpty(difference(U(), matched_U())); } -template -void SBGMatching::updatePaths() +void SBGMatching::updatePaths() { // *** Revert match and unmatched edges in augmenting paths - PWMap paths_mapB = restrict(paths_edges(), mapB()), paths_mapD = restrict(paths_edges(), mapD()); + PWMap paths_mapB = restrict(paths_edges(), mapB()), paths_mapD = restrict(paths_edges(), mapD()); set_mapB(combine(paths_mapD, mapB())); set_mapD(combine(paths_mapB, mapD())); @@ -587,10 +553,9 @@ void SBGMatching::updatePaths() return; } -template -void SBGMatching::updateOffset() +void SBGMatching::updateOffset() { - PWMap aux = restrict(matched_V(), omap()); + PWMap aux = restrict(matched_V(), omap()); aux = offsetImage(max_V(), aux); aux = offsetImage(max_V(), aux); set_omap(combine(aux, omap())); @@ -598,8 +563,7 @@ void SBGMatching::updateOffset() return; } -template -MatchInfo SBGMatching::calculate() +MatchInfo SBGMatching::calculate() { auto begin = std::chrono::high_resolution_clock::now(); shortPath(); @@ -615,23 +579,6 @@ MatchInfo SBGMatching::calculate() return MatchInfo(matched_E(), fullyMatchedU()); } -// Template instantiations ----------------------------------------------------- - -template BasePWMap connectedComponents(BaseSBG g); -template CanonPWMap connectedComponents(CanonSBG g); - -template struct PathInfo; -template struct PathInfo; - -template struct MinReach; -template struct MinReach; - -template struct MatchInfo; -template struct MatchInfo; - -template struct SBGMatching; -template struct SBGMatching; - } // namespace LIB } // namespace SBG diff --git a/sbg/sbg_algorithms.hpp b/sbg/sbg_algorithms.hpp index c0bc9c0..f328824 100755 --- a/sbg/sbg_algorithms.hpp +++ b/sbg/sbg_algorithms.hpp @@ -34,43 +34,35 @@ namespace LIB { // Connected components -------------------------------------------------------- -template -PWMap connectedComponents(SBGraph g); +PWMap connectedComponents(SBGraph g); // Minimum reachable ----------------------------------------------------------- -template struct PathInfo { - member_class(PWMap, succs); - member_class(PWMap, reps); + member_class(PWMap, succs); + member_class(PWMap, reps); PathInfo(); - PathInfo(PWMap succs, PWMap reps); + PathInfo(PWMap succs, PWMap reps); }; -template -PWMap minReach1(Set V, Set E, PWMap mapB, PWMap mapD, PWMap smap, PWMap rmap); +PWMap minReach1(Set V, Set E, PWMap mapB, PWMap mapD, PWMap smap, PWMap rmap); -template struct MinReach { - member_class(DSBGraph, dsbg); + member_class(DSBGraph, dsbg); MinReach(); - MinReach(DSBGraph dsbg); + MinReach(DSBGraph dsbg); - PathInfo recursion(unsigned int n, Set ER, Set not_rv, PWMap smap, PWMap rmap); - PathInfo calculate(Set unmatched_V); + PathInfo recursion(unsigned int n, Set ER, Set not_rv, PWMap smap, PWMap rmap); + PathInfo calculate(Set unmatched_V); }; -typedef MinReach BaseMR; -typedef MinReach CanonMR; - // Matching -------------------------------------------------------------------- enum Direction { forward, backward }; -template struct MatchInfo { member_class(Set, matched_edges); member_class(bool, fully_matchedU); @@ -78,34 +70,32 @@ struct MatchInfo { MatchInfo(); MatchInfo(Set matched_edges, bool fully_matchedU); }; -template -std::ostream &operator<<(std::ostream &out, const MatchInfo &m_info); +std::ostream &operator<<(std::ostream &out, const MatchInfo &m_info); -template struct SBGMatching { //*** SBG info, constant - member_class(SBGraph, sbg); + member_class(SBGraph, sbg); member_class(Set, V); - member_class(PWMap, Vmap); + member_class(PWMap, Vmap); member_class(Set, E); - member_class(PWMap, Emap); + member_class(PWMap, Emap); //----------------------------- - member_class(PWMap, smap); // Successors map - member_class(PWMap, rmap); // Representatives map + member_class(PWMap, smap); // Successors map + member_class(PWMap, rmap); // Representatives map - member_class(PWMap, omap); // Offset map + member_class(PWMap, omap); // Offset map member_class(Util::MD_NAT, max_V); // Current maximum value member_class(Set, F); // Left vertices, constant member_class(Set, U); // Right vertices, constant - member_class(PWMap, mapF); // Left map, constant - member_class(PWMap, mapU); // Forward map, constant + member_class(PWMap, mapF); // Left map, constant + member_class(PWMap, mapU); // Forward map, constant - member_class(PWMap, mapB); // Backward map, mutable - member_class(PWMap, mapD); // Forward map, mutable + member_class(PWMap, mapB); // Backward map, mutable + member_class(PWMap, mapD); // Forward map, mutable member_class(Set, paths_edges); // Available edges in each step to find paths, mutable member_class(Set, matched_E); // Matched edges, mutable @@ -118,16 +108,16 @@ struct SBGMatching { member_class(Set, unmatched_U); // Right unmatched vertices, mutable SBGMatching(); - SBGMatching(SBGraph sbg); + SBGMatching(SBGraph sbg); Set getManyToOne(); // Find N:1 connections void shortPathDirection(Set endings, Direction dir); void shortPathStep(); void shortPath(); - PWMap directedOffset(PWMap dir_map); - DSBGraph offsetGraph(PWMap dir_omap); - void directedMinReach(PWMap dir_map); + PWMap directedOffset(PWMap dir_map); + DSBGraph offsetGraph(PWMap dir_omap); + void directedMinReach(PWMap dir_map); void minReachableStep(); void minReachable(); @@ -136,12 +126,9 @@ struct SBGMatching { void offsetVertices(); void updatePaths(); void updateOffset(); - MatchInfo calculate(); + MatchInfo calculate(); }; -typedef SBGMatching BaseMatch; -typedef SBGMatching CanonMatch; - } // namespace LIB } // namespace SBG diff --git a/sbg/set.cpp b/sbg/set.cpp new file mode 100644 index 0000000..45126fe --- /dev/null +++ b/sbg/set.cpp @@ -0,0 +1,256 @@ +/******************************************************************************* + + 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 . + + ******************************************************************************/ + +#include "sbg/set.hpp" + +namespace SBG { + +namespace LIB { + +//////////////////////////////////////////////////////////////////////////////// +// Generic implementation ------------------------------------------------------ +//////////////////////////////////////////////////////////////////////////////// + +Set::Set() : pieces_(UnordSet()) {} +Set::Set(SetPiece mdi) : pieces_() { emplace(mdi); } +Set::Set(UnordSet c) : pieces_(c) {} +Set::Set(OrdSet c) : pieces_(c) {} + +member_imp(Set, SetType, pieces); + +std::size_t Set::size() +{ + return std::visit([](auto v) { + return v.size(); + }, pieces()); +} + +void Set::emplace(SetPiece mdi) +{ + std::visit([mdi](auto &v) { + v.emplace(mdi); + }, pieces_ref()); + return; +} + +SetPiece Set::operator[](std::size_t n) +{ + return std::visit([n](auto &v) { + return v[n]; + }, pieces_ref()); +} + +bool Set::operator<(const Set &other) const +{ + Set s1 = *this, s2 = other; + bool res = std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return aux1 < aux2; }, + [](OrdSet aux1, OrdSet aux2) { return aux1 < aux2; }, + [](auto aux1, auto aux2) { + if (isEmpty(aux1)) return true; + if (isEmpty(aux2)) return false; + + Util::ERROR("LIB::Set::operator<: mismatched containers"); + return false; + } + }, s1.pieces(), s2.pieces()); + + return res; +} + +bool Set::operator==(const Set &other) const +{ + Set s1 = *this, s2 = other; + bool res = std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return aux1 == aux2; }, + [](OrdSet aux1, OrdSet aux2) { return aux1 == aux2; }, + [](auto aux1, auto aux2) { + if (isEmpty(aux1)) return isEmpty(aux2); + if (isEmpty(aux2)) return isEmpty(aux1); + + Util::ERROR("LIB::Set::operator==: mismatched containers"); + return false; + } + }, s1.pieces(), s2.pieces()); + + return res; +} + +std::ostream &operator<<(std::ostream &out, const Set &s) +{ + std::visit([&out](auto v) { + out << v; + }, s.pieces()); + + return out; +} + +void foreach(std::function f, Set s) +{ + std::visit([f](auto v) { + for (SetPiece mdi : v) f(mdi); + return; + }, s.pieces()); + return; +} + +// Set operations -------------------------------------------------------------- + +unsigned int cardinal(Set s) +{ + return std::visit([](auto v) { + return cardinal(v); + }, s.pieces()); +} + +bool isEmpty(Set s) +{ + return std::visit([](auto v) { + return isEmpty(v); + }, s.pieces()); +} + +bool isMember(MD_NAT x, Set s) +{ + return std::visit([x](auto v){ + return isMember(x, v); + }, s.pieces()); +} + +Util::MD_NAT minElem(Set s) +{ + return std::visit([](auto v){ + return minElem(v); + }, s.pieces()); +} + +Util::MD_NAT maxElem(Set s) +{ + return std::visit([](auto v){ + return maxElem(v); + }, s.pieces()); +} + +Set intersection(Set s1, Set s2) +{ + std::cout << s1 << " | " << s2 << "\n"; + return std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return Set(intersection(aux1, aux2)); }, + [](OrdSet aux1, OrdSet aux2) { return Set(intersection(aux1, aux2)); }, + [](UnordSet aux1, OrdSet aux2) { + if (isEmpty(aux1)) return Set(OrdSet()); + + Util::ERROR("LIB::Set::intersection: mismatched containers 1"); + return Set(UnordSet()); + }, + [](OrdSet aux1, UnordSet aux2) { + if (isEmpty(aux2)) return Set(OrdSet()); + + Util::ERROR("LIB::Set::intersection: mismatched containers 2"); + return Set(UnordSet()); + } + }, s1.pieces(), s2.pieces()); +} + +Set cup(Set s1, Set s2) +{ + return std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return Set(cup(aux1, aux2)); }, + [](OrdSet aux1, OrdSet aux2) { return Set(cup(aux1, aux2)); }, + [](UnordSet aux1, OrdSet aux2) { + if (isEmpty(aux1)) return Set(aux2); + + Util::ERROR("LIB::Set::cup: mismatched containers 1"); + return Set(UnordSet()); + }, + [](OrdSet aux1, UnordSet aux2) { + if (isEmpty(aux2)) return Set(aux1); + + Util::ERROR("LIB::Set::cup: mismatched containers 2"); + return Set(UnordSet()); + } + }, s1.pieces(), s2.pieces()); +} + +Set difference(Set s1, Set s2) +{ + return std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return Set(difference(aux1, aux2)); }, + [](OrdSet aux1, OrdSet aux2) { return Set(difference(aux1, aux2)); }, + [](UnordSet aux1, OrdSet aux2) { + if (isEmpty(aux1)) return Set(OrdSet()); + + Util::ERROR("LIB::Set::difference: mismatched containers 1"); + return Set(UnordSet()); + }, + [](OrdSet aux1, UnordSet aux2) { + if (isEmpty(aux2)) return Set(aux1); + + Util::ERROR("LIB::Set::difference: mismatched containers 2"); + return Set(UnordSet()); + } + }, s1.pieces(), s2.pieces()); +} + +// Extra operations ------------------------------------------------------------ + +Set concatenation(Set s1, Set s2) +{ + return std::visit(Util::Overload { + [](UnordSet aux1, UnordSet aux2) { return Set(concatenation(aux1, aux2)); }, + [](OrdSet aux1, OrdSet aux2) { return Set(concatenation(aux1, aux2)); }, + [](UnordSet aux1, OrdSet aux2) { + if (isEmpty(aux1)) return Set(aux2); + + Util::ERROR("LIB::Set::concatenation: mismatched containers 1"); + return Set(UnordSet()); + }, + [](OrdSet aux1, UnordSet aux2) { + if (isEmpty(aux2)) return Set(aux1); + + Util::ERROR("LIB::Set::concatenation: mismatched containers 2"); + return Set(UnordSet()); + } + }, s1.pieces(), s2.pieces()); +} + +Set filterSet(bool (*f)(SetPiece), Set s) +{ + return std::visit([&f](auto v){ + return Set(filterSet(f, v)); + }, s.pieces()); +} + +Set offset(Util::MD_NAT off, Set s) +{ + return std::visit([off](auto v){ + return Set(offset(off, v)); + }, s.pieces()); +} + +std::size_t hash_value(const Set &s) +{ + return std::visit([](auto v){ + return hash_value(v); + }, s.pieces()); +} + +} // namespace LIB + +} // namespace SBG diff --git a/sbg/set.hpp b/sbg/set.hpp new file mode 100644 index 0000000..8e62db5 --- /dev/null +++ b/sbg/set.hpp @@ -0,0 +1,90 @@ +/** @file set.hpp + + @brief Set + + Set is a wrapper for all possible pwi implementations + +
+ + 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 . + + ******************************************************************************/ + +#ifndef SBG_SET_HPP +#define SBG_SET_HPP + +#include "sbg/ord_pw_mdinter.hpp" +#include "sbg/unord_pw_mdinter.hpp" + +namespace SBG { + +namespace LIB { + +typedef std::variant SetType; + +struct Set { + member_class(SetType, pieces); + + Set(); + Set(SetPiece mdi); + Set(UnordSet c); + Set(OrdSet c); + + std::size_t size(); + void emplace(SetPiece mdi); + SetPiece operator[](std::size_t n); + + eq_class(Set); + lt_class(Set); +}; +std::ostream &operator<<(std::ostream &out, const Set &s); +void foreach(std::function, Set s); + +/** + * @brief Traditional set operations. + */ + +unsigned int cardinal(Set s); +bool isEmpty(Set s); +bool isMember(MD_NAT x, Set s); +Util::MD_NAT minElem(Set s); +Util::MD_NAT maxElem(Set s); +Set intersection(Set s1, Set s2); +Set cup(Set s1, Set s2); + +Set difference(Set s1, Set s2); + +/** + * @brief Extra operations. + */ + +/** @function concatenation + * + * @brief Function useful to unite two s in the case these are known to be + * disjoint. + */ +Set concatenation(Set s1, Set s2); +Set filterSet(bool (*f)(SetPiece), Set s); + +Set offset(Util::MD_NAT off, Set); + +std::size_t hash_value(const Set &s); + +} // namespace LIB + +} // namespace SBG + +#endif \ No newline at end of file diff --git a/sbg/unord_pw_mdinter.cpp b/sbg/unord_pw_mdinter.cpp index da7f3a6..2b7d29e 100755 --- a/sbg/unord_pw_mdinter.cpp +++ b/sbg/unord_pw_mdinter.cpp @@ -30,7 +30,7 @@ std::ostream &operator<<(std::ostream &out, const MDInterUnordSet &ii) MDInterUnordSet aux = ii; int sz = aux.size(); - out << "{"; + out << "{{"; if (sz > 0) { auto it = aux.begin(); for (int i = 0; i < sz - 1; ++i) { @@ -41,7 +41,7 @@ std::ostream &operator<<(std::ostream &out, const MDInterUnordSet &ii) if (!isEmpty(*it)) out << *it; } - out << "}"; + out << "}}"; return out; } @@ -51,8 +51,11 @@ std::ostream &operator<<(std::ostream &out, const MDInterUnordSet &ii) //////////////////////////////////////////////////////////////////////////////// UnordPWMDInter::UnordPWMDInter() : pieces_() {} -UnordPWMDInter::UnordPWMDInter(SetPiece mdi) : pieces_() { pieces_ref().emplace(mdi); } -UnordPWMDInter::UnordPWMDInter(MDInterUnordSet c) : pieces_(c) {} +UnordPWMDInter::UnordPWMDInter(Interval i) : pieces_() { emplaceBack(SetPiece(i)); } +UnordPWMDInter::UnordPWMDInter(SetPiece mdi) : pieces_() { emplaceBack(mdi); } +UnordPWMDInter::UnordPWMDInter(MDInterUnordSet c) : pieces_(c) { + for (SetPiece mdi : c) emplaceBack(mdi); +} member_imp(UnordPWMDInter, MDInterUnordSet, pieces); @@ -60,6 +63,7 @@ std::size_t UnordPWMDInter::size() { return pieces().size(); } void UnordPWMDInter::emplace(SetPiece mdi) { if (!isEmpty(mdi)) pieces_ref().emplace(mdi); } void UnordPWMDInter::emplace_hint(MDInterUnordSetIt it, SetPiece mdi) { if (!isEmpty(mdi)) pieces_ref().emplace_hint(it, mdi); } +void UnordPWMDInter::emplaceBack(SetPiece mdi) { emplace_hint(pieces_ref().end(), mdi); } UnordPWMDInter::iterator UnordPWMDInter::begin() { return pieces_ref().begin(); } UnordPWMDInter::iterator UnordPWMDInter::end() { return pieces_ref().end(); } @@ -96,7 +100,7 @@ unsigned int cardinal(UnordPWMDInter pwi) { unsigned int result = 0; - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) result += cardinal(mdi); return result; @@ -106,10 +110,10 @@ bool isEmpty(UnordPWMDInter pwi) { return pwi.pieces().empty(); } bool isMember(MD_NAT x, UnordPWMDInter pwi) { - BOOST_FOREACH (SetPiece mdi, pwi) - if (!isMember(x, mdi)) return false; + for (SetPiece mdi : pwi) + if (isMember(x, mdi)) return true; - return true; + return false; } Util::MD_NAT minElem(UnordPWMDInter pwi) @@ -118,7 +122,7 @@ Util::MD_NAT minElem(UnordPWMDInter pwi) return MD_NAT(0); MD_NAT res = minElem(*pwi.begin()); - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) if (minElem(mdi) < res) res = minElem(mdi); @@ -131,7 +135,7 @@ Util::MD_NAT maxElem(UnordPWMDInter pwi) return MD_NAT(0); MD_NAT res = maxElem(*pwi.begin()); - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) if (res < maxElem(mdi)) res = maxElem(mdi); @@ -149,9 +153,9 @@ UnordPWMDInter intersection(UnordPWMDInter pwi1, UnordPWMDInter pwi2) // General case MDInterUnordSet cap; - BOOST_FOREACH (SetPiece mi1, pwi1) { - BOOST_FOREACH (SetPiece mi2, pwi2) { - SetPiece ith = intersection(mi1, mi2); + for (SetPiece mdi1 : pwi1) { + for (SetPiece mdi2 : pwi2) { + SetPiece ith = intersection(mdi1, mdi2); if (!isEmpty(ith)) cap.insert(ith); } @@ -171,21 +175,21 @@ UnordPWMDInter cup(UnordPWMDInter pwi1, UnordPWMDInter pwi2) if (pwi1.pieces() == pwi2.pieces()) return pwi1; if (maxElem(pwi1) <= minElem(pwi2)) { - BOOST_FOREACH (SetPiece i1, pwi1) - un.emplace_hint(un.cend(), i1); + for (SetPiece mdi1 : pwi1) + un.emplace_hint(un.cend(), mdi1); - BOOST_FOREACH (SetPiece i2, pwi2) - un.emplace_hint(un.cend(), i2); + for (SetPiece mdi2 : pwi2) + un.emplace_hint(un.cend(), mdi2); return UnordPWMDInter(un); } if (maxElem(pwi2) <= minElem(pwi1)) { - BOOST_FOREACH (SetPiece i2, pwi2) - un.emplace_hint(un.cend(), i2); + for (SetPiece mdi2 : pwi2) + un.emplace_hint(un.cend(), mdi2); - BOOST_FOREACH (SetPiece i1, pwi1) - un.emplace_hint(un.cend(), i1); + for (SetPiece mdi1 : pwi1) + un.emplace_hint(un.cend(), mdi1); return UnordPWMDInter(un); } @@ -210,7 +214,7 @@ UnordPWMDInter complementAtom(UnordPWMDInter pwi) if (isEmpty(mdi)) return all; unsigned int dim = 0; - BOOST_FOREACH (Interval i, mdi.intervals()) { + for (Interval i : mdi) { MDInterUnordSet c; // Before interval @@ -265,7 +269,7 @@ UnordPWMDInter complement(UnordPWMDInter pwi) ++first_it; MDInterUnordSet second(first_it, pwi.end()); - BOOST_FOREACH (SetPiece mdi, second) { + for (SetPiece mdi : second) { UnordPWMDInter c = complementAtom(UnordPWMDInter(mdi)); res = intersection(res, c); } @@ -288,9 +292,9 @@ UnordPWMDInter concatenation(UnordPWMDInter pwi1, UnordPWMDInter pwi2) { UnordPWMDInter res; - BOOST_FOREACH (SetPiece mdi, pwi1) res.emplace_hint(res.end(), mdi); + for (SetPiece mdi : pwi1) res.emplace_hint(res.end(), mdi); - BOOST_FOREACH (SetPiece mdi, pwi2) res.emplace_hint(res.end(), mdi); + for (SetPiece mdi : pwi2) res.emplace_hint(res.end(), mdi); return res; } @@ -299,7 +303,7 @@ UnordPWMDInter filterSet(bool (*f)(SetPiece), UnordPWMDInter pwi) { UnordPWMDInter res; - BOOST_FOREACH (SetPiece mdi, pwi) + for (SetPiece mdi : pwi) if (f(mdi)) res.emplace_hint(res.end(), mdi); return res; @@ -309,11 +313,18 @@ UnordPWMDInter offset(Util::MD_NAT off, UnordPWMDInter pwi) { UnordPWMDInter res; - BOOST_FOREACH (SetPiece mdi, pwi) res.emplace(offset(off, mdi)); + for (SetPiece mdi : pwi) res.emplace(offset(off, mdi)); return res; } +void foreach(UnordPWMDInter pwi, void (*f)(SetPiece)) +{ + for (SetPiece mdi : pwi) f(mdi); + + return; +} + std::size_t hash_value(const UnordPWMDInter &pwi) { UnordPWMDInter aux_pwi = pwi; diff --git a/sbg/unord_pw_mdinter.hpp b/sbg/unord_pw_mdinter.hpp index 8c7dd04..23f936e 100755 --- a/sbg/unord_pw_mdinter.hpp +++ b/sbg/unord_pw_mdinter.hpp @@ -29,7 +29,6 @@ #ifndef SBG_UNORD_PW_MDINTERVAL_HPP #define SBG_UNORD_PW_MDINTERVAL_HPP -#include #include #include "sbg/multidim_inter.hpp" @@ -54,12 +53,14 @@ struct UnordPWMDInter { member_class(MDInterUnordSet, pieces); UnordPWMDInter(); + UnordPWMDInter(Interval i); UnordPWMDInter(SetPiece mdi); UnordPWMDInter(MDInterUnordSet c); std::size_t size(); void emplace(SetPiece mdi); void emplace_hint(MDInterUnordSetIt it, SetPiece mdi); + void emplaceBack(SetPiece mdi); iterator begin(); const_iterator end(); SetPiece operator[](std::size_t n); @@ -110,6 +111,8 @@ UnordPWMDInter filterSet(bool (*f)(SetPiece), UnordPWMDInter pwi); UnordPWMDInter offset(Util::MD_NAT off, UnordPWMDInter); +void foreach(UnordPWMDInter pwi, void (*f)(SetPiece)); + std::size_t hash_value(const UnordPWMDInter &pwi); typedef UnordPWMDInter UnordSet; diff --git a/test/eval/gt_data/pw_map/pw_map.cpp b/test/eval/gt_data/pw_map/pw_map.cpp index 2261365..23810e3 100755 --- a/test/eval/gt_data/pw_map/pw_map.cpp +++ b/test/eval/gt_data/pw_map/pw_map.cpp @@ -62,7 +62,7 @@ int main(int argc, char** argv) { std::string fnames[3] = {"../../../pw_map1.test", "../../../pw_map2.test", "../../../pw_map3.test"}; - BOOST_FOREACH (std::string fname, fnames) { + for (std::string fname : fnames) { if (fname != "") { std::ifstream in(fname.c_str()); if (in.fail()) { diff --git a/test/interval.test b/test/interval.test index a7e631d..6a63a08 100644 --- a/test/interval.test +++ b/test/interval.test @@ -2,15 +2,15 @@ // !!! If this file is modified the corresponding SBG.log file // in all the gt_data directories should be modified. -#[1:1:10] -#[3:5:50] +//#[1:1:10] +//#[3:5:50] -isEmpty([1:0:0]) -isEmpty([100:1:200]) -isEmpty([100:1:5]) +//isEmpty([1:0:0]) +//isEmpty([100:1:200]) +//isEmpty([100:1:5]) -isMember(201, [201:2:399]) -isMember(201, [200:4:400]) +//isMember(201, [201:2:399]) +//isMember(201, [200:4:400]) ([1:1:0] /\ [100:1:500]) ([100:1:500] /\ [1:1:0]) @@ -19,11 +19,11 @@ isMember(201, [200:4:400]) ([201:2:399] /\ [200:4:400]) ([300:1:1000000] /\ [300:1:500]) -minElem([500:5:499]) -minElem([500:5:600]) +//minElem([500:5:499]) +//minElem([500:5:600]) -maxElem([500:5:499]) -maxElem([500:5:600]) +//maxElem([500:5:499]) +//maxElem([500:5:600]) ([1:1:100] == [1:1:100]) ([1:2:100] == [1:1:100]) diff --git a/test/pw_map1.test b/test/pw_map1.test index dd63123..4ea90a0 100644 --- a/test/pw_map1.test +++ b/test/pw_map1.test @@ -9,4 +9,6 @@ minMap({[1:1:5], [10:1:15], [20:2:30]}, 0*x+12, 2*x-12) minMap(<<{[1:1:10], [15:3:30]} -> 1*x+0, {[12:3:12], [50:5:100]} -> 1*x+1>>, <<{[1:2:20], [30:5:60]} -> 0*x+100, {[75:5:90], [95:1:100]} -> 1*x+0>>) +/* reduce(<<{[100:1:200]} -> 1*x-1>>) +*/ diff --git a/test/set.test b/test/set.test index 3ad5ffa..d456214 100644 --- a/test/set.test +++ b/test/set.test @@ -7,9 +7,9 @@ isEmpty({[1:1:100]}) isEmpty({}) -isMember(1, {[50:3:100], [500:10:1000], [1:1:25]}) -isMember(51, {[50:3:100], [500:10:1000], [1:1:25]}) -isMember(53, {[50:3:100], [500:10:1000], [1:1:25]}) +isMember((1), {[50:3:100], [500:10:1000], [1:1:25]}) +isMember((51), {[50:3:100], [500:10:1000], [1:1:25]}) +isMember((53), {[50:3:100], [500:10:1000], [1:1:25]}) minElem({}) minElem({[500:3:1000], [1:1:100]}) @@ -29,12 +29,14 @@ maxElem({[500:3:1000], [1:1:100]}) /\ {[3:1:5], [7:1:8]}) ({[1:3:100], [2:3:100]} /\ {[0:1:2], [4:6:94], [5:6:95], [6:6:96], [7:6:97], [8:6:98], [100:1:10000]}) +/* -{[3:6:100]} -{[1:1:100], [101:2:300]} -{[1:1:100], [101:3:300]} -{[3:10:100], [4:10:100], [5:10:100], [6:10:100], [7:10:100], [8:10:100]} -{[3:10:100], [4:10:100], [5:10:100], [6:10:100], [7:10:100], [8:10:100], [10:2:12]} -{[3:10:100], [4:10:100], [7:2:11], [28:10:100], [39:10:100]} +*/ ({[50:2:150], [300:1:500]} \ {[1:1:100], [101:2:300]}) ({[1:3:100], [2:3:100]} \ {[3:6:100]})