From 51701548c59faf28d39b3d4ec6ff85c9c566246c Mon Sep 17 00:00:00 2001 From: kalashnikovni Date: Sun, 6 Sep 2026 17:24:42 -0300 Subject: [PATCH] : replaced NAT with Int --- algorithms/matching/bfs_matching.cpp | 10 +- algorithms/mfvs/greedy_mfvs.cpp | 6 +- algorithms/mfvs/smallest_sv_mfvs.cpp | 8 +- algorithms/scc/minadj_mrv.cpp | 5 +- .../sorting/topological/min_vertex_ts.cpp | 7 +- .../sorting/topological/min_vertex_ts.hpp | 3 +- ast/expr.hpp | 18 +- ast/sbg_program.cpp | 10 +- ast/sbg_program.hpp | 10 +- ast/statement.cpp | 20 +- ast/statement.hpp | 10 +- eval/base_type.hpp | 8 +- eval/visitors/CMakeLists.txt | 1 - eval/visitors/autom_impl_visitor.cpp | 2 +- eval/visitors/expr_evaluator.cpp | 14 +- eval/visitors/expr_evaluator.hpp | 2 +- eval/visitors/func_evaluator.cpp | 78 ++++---- eval/visitors/int_evaluator.cpp | 54 +++--- eval/visitors/int_evaluator.hpp | 36 ++-- eval/visitors/linear_expr_evaluator.cpp | 12 +- eval/visitors/linear_expr_evaluator.hpp | 2 +- eval/visitors/nat_evaluator.cpp | 179 ------------------ eval/visitors/nat_evaluator.hpp | 72 ------- eval/visitors/program_evaluator.cpp | 6 +- eval/visitors/rational_evaluator.cpp | 58 +++--- eval/visitors/rational_evaluator.hpp | 36 ++-- eval/visitors/set_impl_visitor.cpp | 8 +- eval/visitors/set_impl_visitor.hpp | 2 +- eval/visitors/stm_evaluator.cpp | 2 +- parser/expr.hpp | 3 +- parser/expr_def.hpp | 11 +- parser/sbg_program_def.hpp | 7 +- parser/statement_def.hpp | 6 +- sbg/CMakeLists.txt | 2 +- sbg/bipartite_sbg.cpp | 30 +-- sbg/bipartite_sbg.hpp | 4 +- sbg/directed_sbg.cpp | 30 +-- sbg/directed_sbg.hpp | 4 +- sbg/dom_ord_pwmap.cpp | 4 +- sbg/expression.cpp | 20 +- sbg/expression.hpp | 12 +- sbg/expression_impl.hpp | 3 +- sbg/fixed_points.cpp | 4 +- sbg/fixed_points.hpp | 8 +- sbg/{natural.cpp => integer.cpp} | 46 ++--- sbg/integer.hpp | 114 +++++++++++ sbg/interval.cpp | 52 ++--- sbg/interval.hpp | 32 ++-- sbg/linear_expr.cpp | 27 ++- sbg/linear_expr.hpp | 16 +- sbg/map.cpp | 2 +- sbg/map.hpp | 6 +- sbg/map_detail.cpp | 92 +++++---- sbg/multidim_inter.cpp | 16 +- sbg/multidim_inter.hpp | 10 +- sbg/natural.hpp | 113 ----------- sbg/ord_pwmap.cpp | 8 +- sbg/ord_set.cpp | 54 +++--- sbg/ord_set.hpp | 15 +- sbg/ord_unidim_dense_set.cpp | 22 +-- sbg/ord_unidim_dense_set.hpp | 11 +- sbg/perimeter.cpp | 6 +- sbg/perimeter.hpp | 12 +- sbg/rational.cpp | 72 ++++--- sbg/rational.hpp | 84 ++++---- sbg/sbg.cpp | 11 +- sbg/sbg.hpp | 4 +- sbg/set.cpp | 14 +- sbg/set.hpp | 18 +- sbg/set_detail.cpp | 18 +- sbg/set_detail.hpp | 11 +- sbg/unord_set.cpp | 44 ++--- sbg/unord_set.hpp | 11 +- test/eval/gt_data/pw_map2.log | 2 +- test/eval/gt_data/pw_map3.log | 2 +- test/eval/gt_data/set.log | 2 +- test/matching_TestRL1.test | 2 +- test/performance/boost/scalar_graph.hpp | 6 +- .../boost/scalar_graph_builder.cpp | 18 +- .../boost/scalar_graph_builder.hpp | 6 +- test/performance/boost/scc_graph_builder.cpp | 6 +- test/performance/boost/scc_graph_builder.hpp | 6 +- test/performance/set_bm.cpp | 2 - test/performance/utils.cpp | 74 ++++---- test/performance/utils.hpp | 18 +- 85 files changed, 819 insertions(+), 1093 deletions(-) delete mode 100755 eval/visitors/nat_evaluator.cpp delete mode 100755 eval/visitors/nat_evaluator.hpp rename sbg/{natural.cpp => integer.cpp} (60%) create mode 100755 sbg/integer.hpp delete mode 100755 sbg/natural.hpp diff --git a/algorithms/matching/bfs_matching.cpp b/algorithms/matching/bfs_matching.cpp index 452f266f..a23d2326 100644 --- a/algorithms/matching/bfs_matching.cpp +++ b/algorithms/matching/bfs_matching.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "algorithms/matching/bfs_matching.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "util/logger.hpp" namespace SBG { @@ -73,17 +73,17 @@ PWMap BFSMatching::partitionSubsetEdges() const PWMap result; Set free_edges = _dsbg.E().difference(_M); std::size_t arity = free_edges.arity(); - NAT j = 1; + unsigned int j = 1; PWMap Emap = _dsbg.Emap(); - _dsbg.foreachSetEdge([&](const MD_NAT& SE) + _dsbg.foreachSetEdge([&](const IntTuple& SE) { Set domain_edges = Emap.preImage(Set{SE}); - Expression matched_expr{MD_NAT{arity, j}}; + Expression matched_expr{IntTuple{arity, j}}; result.emplace(_M.intersection(domain_edges), matched_expr); ++j; - Expression free_expr{MD_NAT{arity, j}}; + Expression free_expr{IntTuple{arity, j}}; result.emplace(free_edges.intersection(domain_edges), free_expr); ++j; }); diff --git a/algorithms/mfvs/greedy_mfvs.cpp b/algorithms/mfvs/greedy_mfvs.cpp index 60c84d6a..d24cd50e 100644 --- a/algorithms/mfvs/greedy_mfvs.cpp +++ b/algorithms/mfvs/greedy_mfvs.cpp @@ -19,7 +19,7 @@ #include "algorithms/mfvs/greedy_mfvs.hpp" #include "algorithms/scc/scc.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/pw_map.hpp" #include "util/logger.hpp" @@ -40,7 +40,7 @@ GreedyMFVS::GreedyMFVS() {} /** * @brief It calculates the minimum vertex with maximum degree. */ -MD_NAT maxDegreeVertex(const DirectedSBG& dsbg) +IntTuple maxDegreeVertex(const DirectedSBG& dsbg) { Set V = dsbg.V(); PWMap mapB = dsbg.mapB(); @@ -76,7 +76,7 @@ Set GreedyMFVS::calculate(const DirectedSBG& input_dsbg) const Set visitedSV; while (rmap.fixedPoints() != rmap.domain()) { // Get minimum vertex with maximum degree - MD_NAT max_degree_vertex = maxDegreeVertex(dsbg); + IntTuple max_degree_vertex = maxDegreeVertex(dsbg); Set Vj{max_degree_vertex}; fvs_result = std::move(fvs_result).disjointCup(Vj); diff --git a/algorithms/mfvs/smallest_sv_mfvs.cpp b/algorithms/mfvs/smallest_sv_mfvs.cpp index 1cf2fef4..85354e59 100644 --- a/algorithms/mfvs/smallest_sv_mfvs.cpp +++ b/algorithms/mfvs/smallest_sv_mfvs.cpp @@ -19,7 +19,7 @@ #include "algorithms/mfvs/smallest_sv_mfvs.hpp" #include "algorithms/scc/scc.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/pw_map.hpp" #include "util/logger.hpp" @@ -45,11 +45,11 @@ SmallestSVMFVS::SmallestSVMFVS() {} Set getVerticesFromSmallestSV(const PWMap& Vmap) { Set Vmap_image = Vmap.image(); - NAT min_sz = Inf; + std::size_t min_sz = std::numeric_limits::min(); Set remaining = Vmap_image; while (!remaining.isEmpty()) { Set jth_sv{remaining.minElem()}; - NAT jth_sz = Vmap.preImage(jth_sv).cardinal(); + std::size_t jth_sz = Vmap.preImage(jth_sv).cardinal(); if (jth_sz < min_sz) { min_sz = jth_sz; } @@ -75,7 +75,7 @@ Set getVerticesFromSmallestSV(const PWMap& Vmap) /** * @brief It calculates the minimum vertex of maximum degree of V. */ -MD_NAT getMaxDegreeVertex(const Set& V, const DirectedSBG& dsbg) +IntTuple getMaxDegreeVertex(const Set& V, const DirectedSBG& dsbg) { PWMap mapB = dsbg.mapB(); PWMap mapD = dsbg.mapD(); diff --git a/algorithms/scc/minadj_mrv.cpp b/algorithms/scc/minadj_mrv.cpp index 5a01773c..a7a4415f 100644 --- a/algorithms/scc/minadj_mrv.cpp +++ b/algorithms/scc/minadj_mrv.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "algorithms/scc/minadj_mrv.hpp" +#include "sbg/integer.hpp" #include "util/logger.hpp" namespace SBG { @@ -88,11 +89,11 @@ PWMap MinAdjMRV::calculate(const DirectedSBG& dsbg) // Distance map PWMap dmap; Set ith = end; - NAT dist = 0; + unsigned int dist = 0; // Calculate distance for vertices in same_rep that reach reps for (; dmap.domain().intersection(Vc.intersection(VR)).isEmpty();) { Set domain = ith.difference(dmap.domain()); - Expression expr(MD_NAT{arity, dist}); + Expression expr(IntTuple{arity, dist}); dmap.emplace(domain, expr); // Update ith to vertices that have outgoing edges entering ith ith = mapB.image(mapD.preImage(ith)); diff --git a/algorithms/sorting/topological/min_vertex_ts.cpp b/algorithms/sorting/topological/min_vertex_ts.cpp index f6438457..1dbfc846 100644 --- a/algorithms/sorting/topological/min_vertex_ts.cpp +++ b/algorithms/sorting/topological/min_vertex_ts.cpp @@ -18,7 +18,6 @@ ******************************************************************************/ #include "algorithms/sorting/topological/min_vertex_ts.hpp" -#include "sbg/natural.hpp" #include "util/debug.hpp" #include "util/logger.hpp" @@ -138,7 +137,7 @@ PWMap MinVertexTS::repetition(const Set& init_V, const DirectedSBG& dsbg) // getVertex ------------------------------------------------------------------- -MD_NAT MinVertexTS::getVertex() +IntTuple MinVertexTS::getVertex() { Set V = _dsbg.V(); PWMap mapD = _dsbg.mapD(); @@ -214,8 +213,8 @@ PWMap MinVertexTS::calculate(const DirectedSBG& dsbg std::size_t arity = V.arity(); Expression successor_expr{arity, 1, 0}; - MD_NAT vj; - MD_NAT old_vj = V.difference(_dsbg.mapD().image()).minElem(); + IntTuple vj; + IntTuple old_vj = V.difference(_dsbg.mapD().image()).minElem(); _start = old_vj; do { // Find new vertex without dependencies, and add it to the sorting. diff --git a/algorithms/sorting/topological/min_vertex_ts.hpp b/algorithms/sorting/topological/min_vertex_ts.hpp index fa252402..cc7c2a98 100644 --- a/algorithms/sorting/topological/min_vertex_ts.hpp +++ b/algorithms/sorting/topological/min_vertex_ts.hpp @@ -27,6 +27,7 @@ #include "sbg/directed_sbg.hpp" #include "sbg/expression.hpp" +#include "sbg/integer.hpp" #include "sbg/pw_map.hpp" #include "sbg/set.hpp" @@ -54,7 +55,7 @@ class MinVertexTS { PWMap calculate(const DirectedSBG& dsbg, const PWMap& pmap); private: - MD_NAT getVertex(); + IntTuple getVertex(); /** * @brief Identifies the "path" that leads to the repetition in _smap and diff --git a/ast/expr.hpp b/ast/expr.hpp index f7e59018..3ad4f329 100755 --- a/ast/expr.hpp +++ b/ast/expr.hpp @@ -21,16 +21,16 @@ ******************************************************************************/ -#ifndef PARSER_EXPR_AST_HPP -#define PARSER_EXPR_AST_HPP +#ifndef SBGRAPH_AST_EXPR_HPP_ +#define SBGRAPH_AST_EXPR_HPP_ -#include +#include "sbg/integer.hpp" +#include "util/defs.hpp" -#include #include +#include -#include "sbg/natural.hpp" -#include "util/defs.hpp" +#include namespace SBG { @@ -39,7 +39,7 @@ namespace AST { // Arithmetic and call structures ---------------------------------------------- using Name = std::string; -using Natural = LIB::NAT; +using Integer = LIB::Int; struct Rational; struct UnaryOp; struct BinOp; @@ -56,7 +56,7 @@ class BipartiteSBG; struct DSBG; struct ParenExpr; -using Expr = boost::variant, boost::recursive_wrapper, boost::recursive_wrapper, @@ -303,4 +303,4 @@ std::ostream &operator<<(std::ostream &out, const ParenExpr &pe); } // namespace SBG -#endif +#endif // SBGRAPH_AST_EXPR_HPP_ diff --git a/ast/sbg_program.cpp b/ast/sbg_program.cpp index c761abc2..86694001 100755 --- a/ast/sbg_program.cpp +++ b/ast/sbg_program.cpp @@ -23,13 +23,13 @@ namespace SBG { namespace AST { -SBGProgram::SBGProgram() : nmbr_dims_(1), stms_(), exprs_() {} -SBGProgram::SBGProgram(StatementList stms, ExprList exprs) : nmbr_dims_(1) +SBGProgram::SBGProgram() : arity_(1), stms_(), exprs_() {} +SBGProgram::SBGProgram(StatementList stms, ExprList exprs) : arity_(1) , stms_(stms), exprs_(exprs) {} -SBGProgram::SBGProgram(LIB::NAT nmbr_dims, StatementList stms, ExprList exprs) - : nmbr_dims_(nmbr_dims), stms_(stms), exprs_(exprs) {} +SBGProgram::SBGProgram(std::size_t arity, StatementList stms, ExprList exprs) + : arity_(arity), stms_(stms), exprs_(exprs) {} -member_imp(SBGProgram, LIB::NAT, nmbr_dims); +member_imp(SBGProgram, std::size_t, arity); member_imp(SBGProgram, StatementList, stms); member_imp(SBGProgram, ExprList, exprs); diff --git a/ast/sbg_program.hpp b/ast/sbg_program.hpp index 1f7a7315..9ad16b81 100755 --- a/ast/sbg_program.hpp +++ b/ast/sbg_program.hpp @@ -21,8 +21,8 @@ ******************************************************************************/ -#ifndef PARSER_PROGRAM_AST_HPP -#define PARSER_PROGRAM_AST_HPP +#ifndef SBGRAPH_AST_SBG_PROGRAM_HPP_ +#define SBGRAPH_AST_SBG_PROGRAM_HPP_ #include "ast/statement.hpp" @@ -31,13 +31,13 @@ namespace SBG { namespace AST { struct SBGProgram { - member_class(LIB::NAT, nmbr_dims); + member_class(std::size_t, arity); member_class(StatementList, stms); member_class(ExprList, exprs); SBGProgram(); SBGProgram(StatementList stms, ExprList exprs); - SBGProgram(LIB::NAT nmbr_dims, StatementList stms, ExprList exprs); + SBGProgram(std::size_t arity, StatementList stms, ExprList exprs); }; std::ostream &operator<<(std::ostream &out, const SBGProgram &prog); @@ -45,4 +45,4 @@ std::ostream &operator<<(std::ostream &out, const SBGProgram &prog); } // namespace SBG -#endif +#endif // SBGRAPH_AST_SBG_PROGRAM_HPP_ diff --git a/ast/statement.cpp b/ast/statement.cpp index 150bbb5c..e0ba3905 100755 --- a/ast/statement.cpp +++ b/ast/statement.cpp @@ -36,20 +36,22 @@ std::ostream &operator<<(std::ostream &out, const Assign &asgn) return out; } -ConfigDims::ConfigDims() : nmbr_dims_() {} -ConfigDims::ConfigDims(LIB::NAT nmbr_dims) : nmbr_dims_() { - if (nmbr_dims > 0) - nmbr_dims_ = nmbr_dims; - - else - Util::ERROR("ConfigDims: dimension should be greater than 0\n"); +ConfigDims::ConfigDims() : arity_(0) {} +ConfigDims::ConfigDims(std::size_t arity) : arity_(arity) { + if (arity > 0) { + arity_ = arity; + } + + else { + Util::ERROR("ConfigDims::ConfigDims: dimension should be greater than 0\n"); + } } -member_imp(ConfigDims, LIB::NAT, nmbr_dims); +member_imp(ConfigDims, std::size_t, arity); std::ostream &operator<<(std::ostream &out, const ConfigDims &cfg) { - out << "nmbr_dims = " << cfg.nmbr_dims(); + out << "arity = " << cfg.arity(); return out; } diff --git a/ast/statement.hpp b/ast/statement.hpp index f387a795..523fec34 100755 --- a/ast/statement.hpp +++ b/ast/statement.hpp @@ -21,8 +21,8 @@ ******************************************************************************/ -#ifndef PARSER_STATEMENT_AST_HPP -#define PARSER_STATEMENT_AST_HPP +#ifndef SBGRAPH_AST_STATEMENT_HPP_ +#define SBGRAPH_AST_STATEMENT_HPP_ #include "ast/expr.hpp" #include "util/debug.hpp" @@ -41,10 +41,10 @@ struct Assign { std::ostream &operator<<(std::ostream &out, const Assign &asgn); struct ConfigDims { - member_class(LIB::NAT, nmbr_dims); + member_class(std::size_t, arity); ConfigDims(); - ConfigDims(LIB::NAT nmbr_dims); + ConfigDims(std::size_t arity); }; std::ostream &operator<<(std::ostream &out, const ConfigDims &cfg); @@ -64,4 +64,4 @@ std::ostream &operator<<(std::ostream &out, const StatementList &stm); } // namespace SBG -#endif +#endif // SBGRAPH_AST_STATEMENT_HPP_ diff --git a/eval/base_type.hpp b/eval/base_type.hpp index 3e3f3b83..e17c9a77 100755 --- a/eval/base_type.hpp +++ b/eval/base_type.hpp @@ -30,8 +30,8 @@ #include "sbg/bipartite_sbg.hpp" #include "sbg/directed_sbg.hpp" #include "sbg/expression.hpp" +#include "sbg/integer.hpp" #include "sbg/map.hpp" -#include "sbg/natural.hpp" #include "sbg/pw_map.hpp" #include "sbg/rational.hpp" #include "sbg/sbg.hpp" @@ -45,9 +45,9 @@ namespace SBG { namespace Eval { using ExprBaseType = std::variant(first).nmbr_dims()); + eval_context.setArity(boost::get(first).arity()); } } diff --git a/eval/visitors/expr_evaluator.cpp b/eval/visitors/expr_evaluator.cpp index d62dcd5b..7c5b4aaa 100755 --- a/eval/visitors/expr_evaluator.cpp +++ b/eval/visitors/expr_evaluator.cpp @@ -19,8 +19,8 @@ #include "eval/visitors/expr_evaluator.hpp" #include "eval/visitors/func_evaluator.hpp" +#include "eval/visitors/int_evaluator.hpp" #include "eval/visitors/linear_expr_evaluator.hpp" -#include "eval/visitors/nat_evaluator.hpp" #include "eval/visitors/rational_evaluator.hpp" #include "util/debug.hpp" @@ -69,9 +69,9 @@ ExprEvaluator::ExprEvaluator(EvalContext& eval_ctx) : _eval_context(eval_ctx) eval_ctx.insertFunction("sort", BuiltInFunctions::topoSortEvaluator); } -ExprBaseType ExprEvaluator::operator()(AST::Natural v) const +ExprBaseType ExprEvaluator::operator()(AST::Integer v) const { - return (LIB::NAT) v; + return (LIB::Int) v; } ExprBaseType ExprEvaluator::operator()(AST::Rational v) const @@ -131,11 +131,11 @@ ExprBaseType ExprEvaluator::operator()(AST::Call v) const ExprBaseType ExprEvaluator::operator()(AST::Interval v) const { - NatEvaluator nat_evaluator{_eval_context.venv()}; + IntEvaluator int_evaluator{_eval_context.venv()}; - LIB::NAT b = boost::apply_visitor(nat_evaluator, v.begin()); - LIB::NAT s = boost::apply_visitor(nat_evaluator, v.step()); - LIB::NAT e = boost::apply_visitor(nat_evaluator, v.end()); + LIB::Int b = boost::apply_visitor(int_evaluator, v.begin()); + LIB::Int s = boost::apply_visitor(int_evaluator, v.step()); + LIB::Int e = boost::apply_visitor(int_evaluator, v.end()); return LIB::Set{b, s, e}; } diff --git a/eval/visitors/expr_evaluator.hpp b/eval/visitors/expr_evaluator.hpp index 68895cd2..99a43a11 100755 --- a/eval/visitors/expr_evaluator.hpp +++ b/eval/visitors/expr_evaluator.hpp @@ -40,7 +40,7 @@ class ExprEvaluator : public boost::static_visitor { public: ExprEvaluator(EvalContext& eval_ctx); - ExprBaseType operator()(AST::Natural v) const; + ExprBaseType operator()(AST::Integer v) const; ExprBaseType operator()(AST::Rational v) const; ExprBaseType operator()(AST::Name v) const; ExprBaseType operator()(AST::UnaryOp v) const; diff --git a/eval/visitors/func_evaluator.cpp b/eval/visitors/func_evaluator.cpp index 6741467d..f94c6ce7 100755 --- a/eval/visitors/func_evaluator.cpp +++ b/eval/visitors/func_evaluator.cpp @@ -26,10 +26,10 @@ #include "eval/base_type.hpp" #include "sbg/bipartite_sbg.hpp" #include "sbg/expression.hpp" +#include "sbg/integer.hpp" #include "sbg/interval.hpp" #include "sbg/map.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" #include "sbg/rational.hpp" #include "sbg/set.hpp" #include "sbg/pw_map.hpp" @@ -52,16 +52,13 @@ ExprBaseType BuiltInOperators::oppositeEvaluator(const EBTList& args) , "oppositeEvaluator: wrong number of arguments\n"); auto opposite_evaluator = Util::Overload { - [](LIB::NAT a) - { - return ExprBaseType{LIB::RATIONAL{static_cast(a), -1}}; - }, - [](LIB::RATIONAL a) { return ExprBaseType{LIB::RATIONAL{-1}*a}; }, + [](LIB::Int a) { return ExprBaseType{-a}; }, + [](LIB::Rational a) { return ExprBaseType{LIB::Rational{-1}*a}; }, [](LIB::Set a) { return ExprBaseType{a.complement()}; }, [](auto a) { Util::ERROR("oppositeEvaluator: wrong type argument ", a , " for - (opposite)\n"); - return ExprBaseType{LIB::RATIONAL{0}}; + return ExprBaseType{LIB::Rational{0}}; } }; return std::visit(opposite_evaluator, args[0]); @@ -73,10 +70,10 @@ ExprBaseType BuiltInOperators::cardinalEvaluator(const EBTList& args) , "cardinalEvaluator: wrong number of arguments\n"); const auto cardinal_evaluator = Util::Overload { - [](LIB::Set a) { return (LIB::NAT) a.cardinal(); }, + [](LIB::Set a) { return (LIB::Int) a.cardinal(); }, [](auto a) { Util::ERROR("cardinalEvaluator: wrong argument ", a, " for #\n"); - return (LIB::NAT) 0; + return (LIB::Int) 0; } }; return std::visit(cardinal_evaluator, args[0]); @@ -104,14 +101,14 @@ ExprBaseType BuiltInOperators::addEvaluator(const EBTList& args) , "addEvaluator: wrong number of arguments\n"); const auto add_evaluator = Util::Overload { - [](LIB::NAT a, LIB::NAT b) { return ExprBaseType{a + b}; }, - [](LIB::MD_NAT a, LIB::MD_NAT b) { return ExprBaseType{a + b}; }, - [](LIB::RATIONAL a, LIB::RATIONAL b) { return ExprBaseType{a + b}; }, - [](LIB::NAT a, LIB::RATIONAL b) { - return ExprBaseType{LIB::RATIONAL{static_cast(a)} + b}; + [](LIB::Int a, LIB::Int b) { return ExprBaseType{a + b}; }, + [](LIB::IntTuple a, LIB::IntTuple b) { return ExprBaseType{a + b}; }, + [](LIB::Rational a, LIB::Rational b) { return ExprBaseType{a + b}; }, + [](LIB::Int a, LIB::Rational b) { + return ExprBaseType{LIB::Rational{a} + b}; }, - [](LIB::RATIONAL a, LIB::NAT b) { - return ExprBaseType{a + LIB::RATIONAL{static_cast(b)}}; + [](LIB::Rational a, LIB::Int b) { + return ExprBaseType{a + LIB::Rational{b}}; }, [](LIB::Expression a, LIB::Expression b) { return ExprBaseType{a + b}; }, [](LIB::Map a, LIB::Map b) { return ExprBaseType{a + b}; }, @@ -131,20 +128,13 @@ ExprBaseType BuiltInOperators::subEvaluator(const EBTList& args) , "subEvaluator: wrong number of arguments\n"); const auto sub_evaluator = Util::Overload { - [](LIB::NAT a, LIB::NAT b) { - if (a > b) { - return ExprBaseType{LIB::NAT{a - b}}; - } else { - return ExprBaseType{LIB::RATIONAL{static_cast(a)} - - LIB::RATIONAL{static_cast(b)}}; - } + [](LIB::Int a, LIB::Int b) { return ExprBaseType{a - b}; }, + [](LIB::Rational a, LIB::Rational b) { return ExprBaseType{a - b}; }, + [](LIB::Int a, LIB::Rational b) { + return ExprBaseType{LIB::Rational{a} - b}; }, - [](LIB::RATIONAL a, LIB::RATIONAL b) { return ExprBaseType{a - b}; }, - [](LIB::NAT a, LIB::RATIONAL b) { - return ExprBaseType{LIB::RATIONAL{static_cast(a)} - b}; - }, - [](LIB::RATIONAL a, LIB::NAT b) { - return ExprBaseType{a - LIB::RATIONAL{static_cast(b)}}; + [](LIB::Rational a, LIB::Int b) { + return ExprBaseType{a - LIB::Rational{b}}; }, [](LIB::Expression a, LIB::Expression b) { return ExprBaseType{a - b}; }, [](auto a, auto b) { @@ -162,18 +152,14 @@ ExprBaseType BuiltInOperators::multEvaluator(const EBTList& args) , "multEvaluator: wrong number of arguments\n"); const auto mult_evaluator = Util::Overload { - [](LIB::NAT a, LIB::NAT b) - { - return ExprBaseType{LIB::RATIONAL{static_cast(a*b)}}; - }, - [](LIB::RATIONAL a, LIB::RATIONAL b) { return ExprBaseType{a*b}; }, - [](LIB::NAT a, LIB::RATIONAL b) + [](LIB::Int a, LIB::Int b) { return ExprBaseType{a*b}; }, + [](LIB::Int a, LIB::Rational b) { - return ExprBaseType{LIB::RATIONAL{static_cast(a)}*b}; + return ExprBaseType{LIB::Rational{a}*b}; }, - [](LIB::RATIONAL a, LIB::NAT b) + [](LIB::Rational a, LIB::Int b) { - return ExprBaseType{a*LIB::RATIONAL{static_cast(b)}}; + return ExprBaseType{a*LIB::Rational{b}}; }, [](auto a, auto b) { Util::ERROR("multEvaluator: wrong arguments ", a, ", ", b @@ -190,8 +176,8 @@ ExprBaseType BuiltInOperators::eqEvaluator(const EBTList& args) , "eqEvaluator: wrong number of arguments\n"); const auto eq_evaluator = Util::Overload { - [](LIB::MD_NAT a, LIB::MD_NAT b) { return a == b; }, - [](LIB::RATIONAL a, LIB::RATIONAL b) { return a == b; }, + [](LIB::IntTuple a, LIB::IntTuple b) { return a == b; }, + [](LIB::Rational a, LIB::Rational b) { return a == b; }, [](LIB::Set a, LIB::Set b) { return a == b; }, [](LIB::Expression a, LIB::Expression b) { return a == b; }, [](LIB::Map a, LIB::Map b) { return a == b; }, @@ -211,8 +197,8 @@ ExprBaseType BuiltInOperators::lessEvaluator(const EBTList& args) , "lessEvaluator: wrong number of arguments\n"); const auto less_evaluator = Util::Overload { - [](LIB::MD_NAT a, LIB::MD_NAT b) { return a < b; }, - [](LIB::RATIONAL a, LIB::RATIONAL b) { return a < b; }, + [](LIB::IntTuple a, LIB::IntTuple b) { return a < b; }, + [](LIB::Rational a, LIB::Rational b) { return a < b; }, [](auto a, auto b) { Util::ERROR("lessEvaluator: wrong arguments ", a, ", ", b , " for operator<\n"); @@ -382,7 +368,7 @@ ExprBaseType BuiltInFunctions::minEvaluator(const EBTList& args) [](LIB::Set a) { return a.minElem(); }, [](auto a) { Util::ERROR("minEvaluator: wrong argument ", a, " for minElem\n"); - return LIB::MD_NAT{}; + return LIB::IntTuple{}; } }; return std::visit(min_evaluator, args[0]); @@ -397,7 +383,7 @@ ExprBaseType BuiltInFunctions::maxEvaluator(const EBTList& args) [](LIB::Set a) { return a.maxElem(); }, [](auto a) { Util::ERROR("maxEvaluator: wrong argument ", a, " for maxElem\n"); - return LIB::MD_NAT{}; + return LIB::IntTuple{}; } }; return std::visit(max_evaluator, args[0]); @@ -622,10 +608,10 @@ ExprBaseType BuiltInFunctions::matchingEvaluator(const EBTList& args) LIB::Matching match_impl; const auto matching_evaluator = Util::Overload { - [&match_impl](LIB::BipartiteSBG a, LIB::NAT b) { + [&match_impl](LIB::BipartiteSBG a, LIB::Int b) { return ExprBaseType{match_impl.calculate(copy(b, a))}; }, - [&match_impl](LIB::BipartiteSBG a, LIB::MD_NAT b) { + [&match_impl](LIB::BipartiteSBG a, LIB::IntTuple b) { return ExprBaseType{match_impl.calculate(copy(b[0], a))}; }, [](auto a, auto b) { diff --git a/eval/visitors/int_evaluator.cpp b/eval/visitors/int_evaluator.cpp index dd4db119..5451ea70 100755 --- a/eval/visitors/int_evaluator.cpp +++ b/eval/visitors/int_evaluator.cpp @@ -32,9 +32,9 @@ IntEvaluator::IntEvaluator() : _venv() {} IntEvaluator::IntEvaluator(VarEnv &venv) : _venv(venv) {} -LIB::INT IntEvaluator::operator()(AST::Natural v) const { return (LIB::INT) v; } +LIB::Int IntEvaluator::operator()(AST::Integer v) const { return (LIB::Int) v; } -LIB::INT IntEvaluator::operator()(AST::Rational v) const +LIB::Int IntEvaluator::operator()(AST::Rational v) const { if (boost::apply_visitor(*this, v.den()) == 1) { return boost::apply_visitor(*this, v.num()); @@ -44,18 +44,18 @@ LIB::INT IntEvaluator::operator()(AST::Rational v) const return 0; } -LIB::INT IntEvaluator::operator()(AST::Name v) const +LIB::Int IntEvaluator::operator()(AST::Name v) const { auto var_definition = _venv.find(v); if (var_definition != _venv.end()) { ExprBaseType value = var_definition->second; - if (std::holds_alternative(value)) { - return static_cast(std::get(value)); - } else if (std::holds_alternative(value)) { - LIB::MD_NAT x = std::get(value); - return static_cast(x[0]); - } else if (std::holds_alternative(value)) { - LIB::RATIONAL x = std::get(value); + if (std::holds_alternative(value)) { + return std::get(value); + } else if (std::holds_alternative(value)) { + LIB::IntTuple x = std::get(value); + return x[0]; + } else if (std::holds_alternative(value)) { + LIB::Rational x = std::get(value); return x.toInt(); } } @@ -64,9 +64,9 @@ LIB::INT IntEvaluator::operator()(AST::Name v) const return 0; } -LIB::INT IntEvaluator::operator()(AST::UnaryOp v) const +LIB::Int IntEvaluator::operator()(AST::UnaryOp v) const { - LIB::INT x = boost::apply_visitor(*this, v.expr()); + LIB::Int x = boost::apply_visitor(*this, v.expr()); switch (v.op()) { case AST::UnOp::oppo: { return -x; @@ -79,10 +79,10 @@ LIB::INT IntEvaluator::operator()(AST::UnaryOp v) const } } -LIB::INT IntEvaluator::operator()(AST::BinOp v) const +LIB::Int IntEvaluator::operator()(AST::BinOp v) const { - LIB::INT l = boost::apply_visitor(*this, v.left()); - LIB::INT r = boost::apply_visitor(*this, v.right()); + LIB::Int l = boost::apply_visitor(*this, v.left()); + LIB::Int r = boost::apply_visitor(*this, v.right()); switch (v.op()) { case AST::Op::add: { return l + r; @@ -107,73 +107,73 @@ LIB::INT IntEvaluator::operator()(AST::BinOp v) const } } -LIB::INT IntEvaluator::operator()(AST::Call v) const +LIB::Int IntEvaluator::operator()(AST::Call v) const { Util::ERROR("IntEvaluator: trying to evaluate Call ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::Interval v) const +LIB::Int IntEvaluator::operator()(AST::Interval v) const { Util::ERROR("IntEvaluator: trying to evaluate Interval ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::MultiDimInter v) const +LIB::Int IntEvaluator::operator()(AST::MultiDimInter v) const { Util::ERROR("IntEvaluator: trying to evaluate MultiDimInter ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::Set v) const +LIB::Int IntEvaluator::operator()(AST::Set v) const { Util::ERROR("IntEvaluator: trying to evaluate Set ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::LinearExp v) const +LIB::Int IntEvaluator::operator()(AST::LinearExp v) const { Util::ERROR("IntEvaluator: trying to evaluate LinearExp ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::MDLExp v) const +LIB::Int IntEvaluator::operator()(AST::MDLExp v) const { Util::ERROR("IntEvaluator: trying to evaluate MDLExp ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::LinearMap v) const +LIB::Int IntEvaluator::operator()(AST::LinearMap v) const { Util::ERROR("IntEvaluator: trying to evaluate LinearMap ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::PWLMap v) const +LIB::Int IntEvaluator::operator()(AST::PWLMap v) const { Util::ERROR("IntEvaluator: trying to evaluate PWLMap ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::SBG v) const +LIB::Int IntEvaluator::operator()(AST::SBG v) const { Util::ERROR("IntEvaluator: trying to evaluate SBG ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::BipartiteSBG v) const +LIB::Int IntEvaluator::operator()(AST::BipartiteSBG v) const { Util::ERROR("IntEvaluator: trying to evaluate BipartiteSBG ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::DSBG v) const +LIB::Int IntEvaluator::operator()(AST::DSBG v) const { Util::ERROR("IntEvaluator: trying to evaluate DirectedSBG ", v, "\n"); return 0; } -LIB::INT IntEvaluator::operator()(AST::ParenExpr v) const +LIB::Int IntEvaluator::operator()(AST::ParenExpr v) const { return boost::apply_visitor(*this, v.e()); } diff --git a/eval/visitors/int_evaluator.hpp b/eval/visitors/int_evaluator.hpp index 98d3e08b..57a919c4 100755 --- a/eval/visitors/int_evaluator.hpp +++ b/eval/visitors/int_evaluator.hpp @@ -36,28 +36,28 @@ namespace Eval { namespace detail { -class IntEvaluator : public boost::static_visitor { +class IntEvaluator : public boost::static_visitor { public: IntEvaluator(); IntEvaluator(VarEnv& venv); - LIB::INT operator()(AST::Natural v) const; - LIB::INT operator()(AST::Rational v) const; - LIB::INT operator()(AST::Name v) const; - LIB::INT operator()(AST::UnaryOp v) const; - LIB::INT operator()(AST::BinOp v) const; - LIB::INT operator()(AST::Call v) const; - LIB::INT operator()(AST::Interval v) const; - LIB::INT operator()(AST::MultiDimInter v) const; - LIB::INT operator()(AST::Set v) const; - LIB::INT operator()(AST::LinearExp v) const; - LIB::INT operator()(AST::MDLExp v) const; - LIB::INT operator()(AST::LinearMap v) const; - LIB::INT operator()(AST::PWLMap v) const; - LIB::INT operator()(AST::SBG v) const; - LIB::INT operator()(AST::BipartiteSBG v) const; - LIB::INT operator()(AST::DSBG v) const; - LIB::INT operator()(AST::ParenExpr v) const; + LIB::Int operator()(AST::Integer v) const; + LIB::Int operator()(AST::Rational v) const; + LIB::Int operator()(AST::Name v) const; + LIB::Int operator()(AST::UnaryOp v) const; + LIB::Int operator()(AST::BinOp v) const; + LIB::Int operator()(AST::Call v) const; + LIB::Int operator()(AST::Interval v) const; + LIB::Int operator()(AST::MultiDimInter v) const; + LIB::Int operator()(AST::Set v) const; + LIB::Int operator()(AST::LinearExp v) const; + LIB::Int operator()(AST::MDLExp v) const; + LIB::Int operator()(AST::LinearMap v) const; + LIB::Int operator()(AST::PWLMap v) const; + LIB::Int operator()(AST::SBG v) const; + LIB::Int operator()(AST::BipartiteSBG v) const; + LIB::Int operator()(AST::DSBG v) const; + LIB::Int operator()(AST::ParenExpr v) const; private: mutable VarEnv _venv; diff --git a/eval/visitors/linear_expr_evaluator.cpp b/eval/visitors/linear_expr_evaluator.cpp index 8e6ab6bd..65efe735 100755 --- a/eval/visitors/linear_expr_evaluator.cpp +++ b/eval/visitors/linear_expr_evaluator.cpp @@ -30,17 +30,17 @@ namespace detail { LinearExprEvaluator::LinearExprEvaluator(VarEnv &venv) : _venv(venv) {} -LIB::detail::LinearExpr LinearExprEvaluator::operator()(AST::Natural v) const +LIB::detail::LinearExpr LinearExprEvaluator::operator()(AST::Integer v) const { - return LIB::detail::LinearExpr{0, LIB::RATIONAL{static_cast(v)}}; + return LIB::detail::LinearExpr{0, LIB::Rational{v}}; } LIB::detail::LinearExpr LinearExprEvaluator::operator()(AST::Rational v) const { IntEvaluator visit_int{_venv}; - LIB::INT p = boost::apply_visitor(visit_int, v.num()); - LIB::INT q = boost::apply_visitor(visit_int, v.den()); - return LIB::detail::LinearExpr{0, LIB::RATIONAL{p, q}}; + LIB::Int p = boost::apply_visitor(visit_int, v.num()); + LIB::Int q = boost::apply_visitor(visit_int, v.den()); + return LIB::detail::LinearExpr{0, LIB::Rational{p, q}}; } LIB::detail::LinearExpr LinearExprEvaluator::operator()(AST::Name v) const @@ -49,7 +49,7 @@ LIB::detail::LinearExpr LinearExprEvaluator::operator()(AST::Name v) const return LIB::detail::LinearExpr{1, 0}; } - LIB::RATIONAL off = boost::apply_visitor(RationalEvaluator{_venv} + LIB::Rational off = boost::apply_visitor(RationalEvaluator{_venv} , AST::Expr{v}); return LIB::detail::LinearExpr{0, off}; } diff --git a/eval/visitors/linear_expr_evaluator.hpp b/eval/visitors/linear_expr_evaluator.hpp index ec3e5c43..5f2b91f1 100755 --- a/eval/visitors/linear_expr_evaluator.hpp +++ b/eval/visitors/linear_expr_evaluator.hpp @@ -41,7 +41,7 @@ class LinearExprEvaluator public: LinearExprEvaluator(VarEnv &venv); - LIB::detail::LinearExpr operator()(AST::Natural v) const; + LIB::detail::LinearExpr operator()(AST::Integer v) const; LIB::detail::LinearExpr operator()(AST::Rational v) const; LIB::detail::LinearExpr operator()(AST::Name v) const; LIB::detail::LinearExpr operator()(AST::UnaryOp v) const; diff --git a/eval/visitors/nat_evaluator.cpp b/eval/visitors/nat_evaluator.cpp deleted file mode 100755 index ef4dea63..00000000 --- a/eval/visitors/nat_evaluator.cpp +++ /dev/null @@ -1,179 +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/nat_evaluator.hpp" -#include "util/debug.hpp" - -#include - -namespace SBG { - -namespace Eval { - -namespace detail { - -NatEvaluator::NatEvaluator() : _venv() {} - -NatEvaluator::NatEvaluator(VarEnv &venv) : _venv(venv) {} - -LIB::NAT NatEvaluator::operator()(AST::Natural v) const { return v; } - -LIB::NAT NatEvaluator::operator()(AST::Rational v) const -{ - if (boost::apply_visitor(*this, v.den()) == 1) { - return boost::apply_visitor(*this, v.num()); - } - - Util::ERROR("NatEvaluator: trying to evaluate Rational ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::Name v) const -{ - auto var_definition = _venv.find(v); - if (var_definition != _venv.end()) { - ExprBaseType value = var_definition->second; - if (std::holds_alternative(value)) { - return std::get(value); - } else if (std::holds_alternative(value)) { - LIB::MD_NAT x = std::get(value); - if (x.arity() == 1) { - return x[0]; - } - } else { - if (std::holds_alternative(value)) { - return std::get(value).toNat(); - } - } - } - - Util::ERROR("NatEvaluator: variable ", v, " undefined\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::UnaryOp v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate arithmetic UnaryOp ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::BinOp v) const -{ - LIB::NAT l = boost::apply_visitor(*this, v.left()); - LIB::NAT r = boost::apply_visitor(*this, v.right()); - switch (v.op()) { - case AST::Op::add: { - return l + r; - } - - case AST::Op::sub: { - return l - r; - } - - case AST::Op::mult: { - return l * r; - } - - case AST::Op::expo: { - return pow(l, r); - } - - default: { - Util::ERROR("NatEvaluator: BinOp ", v.op(), " unsupported\n"); - return 0; - } - } -} - -LIB::NAT NatEvaluator::operator()(AST::Call v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate Call ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::Interval v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate Interval ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::MultiDimInter v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate MultiDimInter ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::Set v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate Set ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::LinearExp v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate LinearExp ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::MDLExp v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate MDLExp ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::LinearMap v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate LinearMap ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::PWLMap v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate PWLMap ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::SBG v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate SBG ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::BipartiteSBG v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate BipartiteSBG ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::DSBG v) const -{ - Util::ERROR("NatEvaluator: trying to evaluate DirectedSBG ", v, "\n"); - return 0; -} - -LIB::NAT NatEvaluator::operator()(AST::ParenExpr v) const -{ - return boost::apply_visitor(*this, v.e()); -} - -} // namespace detail - -} // namespace Eval - -} // namespace SBG diff --git a/eval/visitors/nat_evaluator.hpp b/eval/visitors/nat_evaluator.hpp deleted file mode 100755 index 44bda79a..00000000 --- a/eval/visitors/nat_evaluator.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/** @file nat_evaluator.hpp - - @brief Natural 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 SBGRAPH_EVAL_VISITORS_NAT_EVALUATOR_HPP_ -#define SBGRAPH_EVAL_VISITORS_NAT_EVALUATOR_HPP_ - -#include "ast/expr.hpp" -#include "eval/var_env.hpp" -#include "sbg/natural.hpp" - -#include "boost/variant.hpp" - -namespace SBG { - -namespace Eval { - -namespace detail { - -class NatEvaluator : public boost::static_visitor { -public: - NatEvaluator(); - NatEvaluator(VarEnv &venv); - - LIB::NAT operator()(AST::Natural v) const; - LIB::NAT operator()(AST::Rational v) const; - LIB::NAT operator()(AST::Name v) const; - LIB::NAT operator()(AST::UnaryOp v) const; - LIB::NAT operator()(AST::BinOp v) const; - LIB::NAT operator()(AST::Call v) const; - LIB::NAT operator()(AST::Interval v) const; - LIB::NAT operator()(AST::MultiDimInter v) const; - LIB::NAT operator()(AST::Set v) const; - LIB::NAT operator()(AST::LinearExp v) const; - LIB::NAT operator()(AST::MDLExp v) const; - LIB::NAT operator()(AST::LinearMap v) const; - LIB::NAT operator()(AST::PWLMap v) const; - LIB::NAT operator()(AST::SBG v) const; - LIB::NAT operator()(AST::BipartiteSBG v) const; - LIB::NAT operator()(AST::DSBG v) const; - LIB::NAT operator()(AST::ParenExpr) const; - -private: - mutable VarEnv _venv; -}; - -} // namespace detail - -} // namespace Eval - -} // namespace SBG - -#endif // SBGRAPH_EVAL_VISITORS_NAT_EVALUTOR_HPP_ diff --git a/eval/visitors/program_evaluator.cpp b/eval/visitors/program_evaluator.cpp index f84e485e..397099eb 100755 --- a/eval/visitors/program_evaluator.cpp +++ b/eval/visitors/program_evaluator.cpp @@ -32,14 +32,14 @@ ProgramEvaluator::ProgramEvaluator() {} ProgramIO ProgramEvaluator::evaluate(AST::SBGProgram p) const { - LIB::NAT dims = 1; + std::size_t arity = 1; EvalContext eval_context; AST::IsConfig cfg_visit; if (!p.stms().empty()) { AST::Statement first = p.stms()[0]; if (boost::apply_visitor(cfg_visit, first)) { - eval_context.setArity(boost::get(first).nmbr_dims()); + eval_context.setArity(boost::get(first).arity()); } } @@ -59,7 +59,7 @@ ProgramIO ProgramEvaluator::evaluate(AST::SBGProgram p) const exprs.emplace_back(e, expr_res); } - return ProgramIO{dims, stms, exprs}; + return ProgramIO{arity, stms, exprs}; } } // namespace detail diff --git a/eval/visitors/rational_evaluator.cpp b/eval/visitors/rational_evaluator.cpp index b4ec02bf..c7b330ec 100755 --- a/eval/visitors/rational_evaluator.cpp +++ b/eval/visitors/rational_evaluator.cpp @@ -31,32 +31,32 @@ RationalEvaluator::RationalEvaluator() : _venv() {} RationalEvaluator::RationalEvaluator(VarEnv& venv) : _venv(venv) {} -LIB::RATIONAL RationalEvaluator::operator()(AST::Natural v) const +LIB::Rational RationalEvaluator::operator()(AST::Integer v) const { - return LIB::RATIONAL{static_cast(v)}; + return LIB::Rational{v}; } -LIB::RATIONAL RationalEvaluator::operator()(AST::Rational v) const +LIB::Rational RationalEvaluator::operator()(AST::Rational v) const { IntEvaluator visit_int{_venv}; - return LIB::RATIONAL(boost::apply_visitor(visit_int, v.num()) + return LIB::Rational(boost::apply_visitor(visit_int, v.num()) , boost::apply_visitor(visit_int, v.den())); } -LIB::RATIONAL RationalEvaluator::operator()(AST::Name v) const +LIB::Rational RationalEvaluator::operator()(AST::Name v) const { auto var_definition = _venv.find(v); if (var_definition != _venv.end()) { ExprBaseType value = var_definition->second; - if (std::holds_alternative(value)) { - return std::get(value); - } else if (std::holds_alternative(value)) { - LIB::MD_NAT x = std::get(value); + if (std::holds_alternative(value)) { + return std::get(value); + } else if (std::holds_alternative(value)) { + LIB::IntTuple x = std::get(value); if (x.arity() == 1) { - return LIB::RATIONAL(static_cast(x[0])); + return LIB::Rational(x[0]); } - } else if (std::holds_alternative(value)) { - return LIB::RATIONAL{static_cast(std::get(value))}; + } else if (std::holds_alternative(value)) { + return LIB::Rational{std::get(value)}; } else { Util::ERROR("RationalEvaluator: variable ", v, " is not rational\n"); return 0; @@ -67,10 +67,10 @@ LIB::RATIONAL RationalEvaluator::operator()(AST::Name v) const return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::UnaryOp v) const +LIB::Rational RationalEvaluator::operator()(AST::UnaryOp v) const { RationalEvaluator visit_rat{_venv}; - LIB::RATIONAL result = boost::apply_visitor(visit_rat, v.expr()); + LIB::Rational result = boost::apply_visitor(visit_rat, v.expr()); switch (v.op()) { case AST::UnOp::oppo: { return -result; @@ -86,10 +86,10 @@ LIB::RATIONAL RationalEvaluator::operator()(AST::UnaryOp v) const return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::BinOp v) const +LIB::Rational RationalEvaluator::operator()(AST::BinOp v) const { - LIB::RATIONAL l = boost::apply_visitor(*this, v.left()); - LIB::RATIONAL r = boost::apply_visitor(*this, v.right()); + LIB::Rational l = boost::apply_visitor(*this, v.left()); + LIB::Rational r = boost::apply_visitor(*this, v.right()); switch (v.op()) { case AST::Op::add: { return l + r; @@ -113,73 +113,73 @@ LIB::RATIONAL RationalEvaluator::operator()(AST::BinOp v) const return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::Call v) const +LIB::Rational RationalEvaluator::operator()(AST::Call v) const { Util::ERROR("RationalEvaluator: trying to evaluate Call ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::Interval v) const +LIB::Rational RationalEvaluator::operator()(AST::Interval v) const { Util::ERROR("RationalEvaluator: trying to evaluate Interval ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::MultiDimInter v) const +LIB::Rational RationalEvaluator::operator()(AST::MultiDimInter v) const { Util::ERROR("RationalEvaluator: trying to evaluate MultiDimInter ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::Set v) const +LIB::Rational RationalEvaluator::operator()(AST::Set v) const { Util::ERROR("RationalEvaluator: trying to evaluate Set ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::LinearExp v) const +LIB::Rational RationalEvaluator::operator()(AST::LinearExp v) const { Util::ERROR("RationalEvaluator: trying to evaluate LinearExp ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::MDLExp v) const +LIB::Rational RationalEvaluator::operator()(AST::MDLExp v) const { Util::ERROR("RationalEvaluator: trying to evaluate MDLExp ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::LinearMap v) const +LIB::Rational RationalEvaluator::operator()(AST::LinearMap v) const { Util::ERROR("RationalEvaluator: trying to evaluate LinearMap ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::PWLMap v) const +LIB::Rational RationalEvaluator::operator()(AST::PWLMap v) const { Util::ERROR("RationalEvaluator: trying to evaluate PWLMap ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::SBG v) const +LIB::Rational RationalEvaluator::operator()(AST::SBG v) const { Util::ERROR("RationalEvaluator: trying to evaluate SBG ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::BipartiteSBG v) const +LIB::Rational RationalEvaluator::operator()(AST::BipartiteSBG v) const { Util::ERROR("RationalEvaluator: trying to evaluate BipartiteSBG ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::DSBG v) const +LIB::Rational RationalEvaluator::operator()(AST::DSBG v) const { Util::ERROR("RationalEvaluator: trying to evaluate DirectedSBG ", v, "\n"); return 0; } -LIB::RATIONAL RationalEvaluator::operator()(AST::ParenExpr v) const +LIB::Rational RationalEvaluator::operator()(AST::ParenExpr v) const { return boost::apply_visitor(*this, v.e()); } diff --git a/eval/visitors/rational_evaluator.hpp b/eval/visitors/rational_evaluator.hpp index e53c1793..ae5f1fdb 100755 --- a/eval/visitors/rational_evaluator.hpp +++ b/eval/visitors/rational_evaluator.hpp @@ -36,28 +36,28 @@ namespace Eval { namespace detail { -class RationalEvaluator : public boost::static_visitor { +class RationalEvaluator : public boost::static_visitor { public: RationalEvaluator(); RationalEvaluator(VarEnv &venv); - LIB::RATIONAL operator()(AST::Natural v) const; - LIB::RATIONAL operator()(AST::Rational v) const; - LIB::RATIONAL operator()(AST::Name v) const; - LIB::RATIONAL operator()(AST::UnaryOp v) const; - LIB::RATIONAL operator()(AST::BinOp v) const; - LIB::RATIONAL operator()(AST::Call v) const; - LIB::RATIONAL operator()(AST::Interval v) const; - LIB::RATIONAL operator()(AST::MultiDimInter v) const; - LIB::RATIONAL operator()(AST::Set v) const; - LIB::RATIONAL operator()(AST::LinearExp v) const; - LIB::RATIONAL operator()(AST::MDLExp v) const; - LIB::RATIONAL operator()(AST::LinearMap v) const; - LIB::RATIONAL operator()(AST::PWLMap v) const; - LIB::RATIONAL operator()(AST::SBG v) const; - LIB::RATIONAL operator()(AST::BipartiteSBG v) const; - LIB::RATIONAL operator()(AST::DSBG v) const; - LIB::RATIONAL operator()(AST::ParenExpr) const; + LIB::Rational operator()(AST::Integer v) const; + LIB::Rational operator()(AST::Rational v) const; + LIB::Rational operator()(AST::Name v) const; + LIB::Rational operator()(AST::UnaryOp v) const; + LIB::Rational operator()(AST::BinOp v) const; + LIB::Rational operator()(AST::Call v) const; + LIB::Rational operator()(AST::Interval v) const; + LIB::Rational operator()(AST::MultiDimInter v) const; + LIB::Rational operator()(AST::Set v) const; + LIB::Rational operator()(AST::LinearExp v) const; + LIB::Rational operator()(AST::MDLExp v) const; + LIB::Rational operator()(AST::LinearMap v) const; + LIB::Rational operator()(AST::PWLMap v) const; + LIB::Rational operator()(AST::SBG v) const; + LIB::Rational operator()(AST::BipartiteSBG v) const; + LIB::Rational operator()(AST::DSBG v) const; + LIB::Rational operator()(AST::ParenExpr) const; private: mutable VarEnv _venv; diff --git a/eval/visitors/set_impl_visitor.cpp b/eval/visitors/set_impl_visitor.cpp index 80f82e27..e2145812 100755 --- a/eval/visitors/set_impl_visitor.cpp +++ b/eval/visitors/set_impl_visitor.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include "eval/visitors/nat_evaluator.hpp" +#include "eval/visitors/int_evaluator.hpp" #include "eval/visitors/rational_evaluator.hpp" #include "eval/visitors/set_impl_visitor.hpp" #include "eval/visitors/stm_evaluator.hpp" @@ -34,7 +34,7 @@ namespace detail { SetImplExprVisitor::SetImplExprVisitor(VarEnv& venv) : _venv(venv) {} -int SetImplExprVisitor::operator()(AST::Natural v) const { return 2; } +int SetImplExprVisitor::operator()(AST::Integer v) const { return 2; } int SetImplExprVisitor::operator()(AST::Rational v) const { return 2; } @@ -65,7 +65,7 @@ int SetImplExprVisitor::operator()(AST::Call v) const int SetImplExprVisitor::operator()(AST::Interval v) const { - NatEvaluator visit_nat{_venv}; + IntEvaluator visit_nat{_venv}; return boost::apply_visitor(visit_nat, v.step()) == 1 ? 2 : 1; } @@ -97,7 +97,7 @@ int SetImplExprVisitor::operator()(AST::Set v) const int SetImplExprVisitor::operator()(AST::LinearExp v) const { RationalEvaluator visit_rat{_venv}; - LIB::RATIONAL r = boost::apply_visitor(visit_rat, v.slope()); + LIB::Rational r = boost::apply_visitor(visit_rat, v.slope()); return (r == 0 || r == 1) ? 2 : 1; } diff --git a/eval/visitors/set_impl_visitor.hpp b/eval/visitors/set_impl_visitor.hpp index 1a17e5e5..21909ed0 100755 --- a/eval/visitors/set_impl_visitor.hpp +++ b/eval/visitors/set_impl_visitor.hpp @@ -52,7 +52,7 @@ class SetImplExprVisitor : public boost::static_visitor { public: SetImplExprVisitor(VarEnv& venv); - int operator()(AST::Natural v) const; + int operator()(AST::Integer v) const; int operator()(AST::Rational v) const; int operator()(AST::Name v) const; int operator()(AST::UnaryOp v) const; diff --git a/eval/visitors/stm_evaluator.cpp b/eval/visitors/stm_evaluator.cpp index 8442b34f..739f8b82 100755 --- a/eval/visitors/stm_evaluator.cpp +++ b/eval/visitors/stm_evaluator.cpp @@ -44,7 +44,7 @@ StmResult StmEvaluator::operator()(AST::Assign assgn) const StmResult StmEvaluator::operator()(AST::ConfigDims cfg) const { - return StmResult("", cfg.nmbr_dims()); + return StmResult("", static_cast(cfg.arity())); } } // namespace detail diff --git a/parser/expr.hpp b/parser/expr.hpp index 8059aa33..688307a8 100755 --- a/parser/expr.hpp +++ b/parser/expr.hpp @@ -28,6 +28,7 @@ #include "ast/expr.hpp" #include "parser/skipper.hpp" +#include "sbg/integer.hpp" namespace SBG { @@ -51,7 +52,7 @@ class ExprRule : qi::grammar, AST::ExprList()> { , SEMI, V, VMAP, MAP1, MAP2, EMAP, MAPB, MAPD, X, Y; // Other rules - qi::rule, LIB::NAT()> nat; + qi::rule, LIB::Int> integer; qi::rule, AST::Rational> rational_legacy; qi::rule, AST::Expr()> primary; qi::rule, AST::Expr()> factor; diff --git a/parser/expr_def.hpp b/parser/expr_def.hpp index 68231a1f..f96f9a2e 100755 --- a/parser/expr_def.hpp +++ b/parser/expr_def.hpp @@ -30,10 +30,12 @@ // Adapt structures ------------------------------------------------------------ -BOOST_FUSION_ADAPT_STRUCT(SBG::LIB::MD_NAT, (SBG::LIB::MD_NAT::VNAT, value_)) +BOOST_FUSION_ADAPT_STRUCT( + SBG::LIB::IntTuple, (std::vector, value_) +) BOOST_FUSION_ADAPT_STRUCT( - SBG::LIB::RATIONAL, (boost::rational, value_) + SBG::LIB::Rational, (boost::rational, value_) ) BOOST_FUSION_ADAPT_STRUCT( @@ -174,7 +176,8 @@ ExprRule::ExprRule(Iterator &it) : identifier = qi::lexeme[qi::char_("a-zA-Z") >> *(qi::alnum | qi::char_('_'))]; - nat = qi::lexeme[qi::ulong_long][qi::_val = phx::construct(qi::_1)]; + integer = qi::lexeme[qi::long_long] + [qi::_val = phx::construct(qi::_1)]; rational_legacy = (RAT >> OPAREN @@ -184,7 +187,7 @@ ExprRule::ExprRule(Iterator &it) : >> CPAREN)[qi::_val = phx::construct(qi::_1, qi::_2)]; primary = rational_legacy[qi::_val = qi::_1] - | nat[qi::_val = qi::_1] + | integer[qi::_val = qi::_1] | identifier[qi::_val = qi::_1] | (OPAREN >> arithmetic_expr >> CPAREN) [qi::_val = phx::construct(qi::_1)]; diff --git a/parser/sbg_program_def.hpp b/parser/sbg_program_def.hpp index 2404a8da..2b921862 100755 --- a/parser/sbg_program_def.hpp +++ b/parser/sbg_program_def.hpp @@ -20,18 +20,17 @@ #ifndef PROGRAM_DEF_PARSER_HPP #define PROGRAM_DEF_PARSER_HPP +#include "ast/sbg_program.hpp" + #include #include #include -#include "ast/sbg_program.hpp" - - // Adapt structures ------------------------------------------------------------ BOOST_FUSION_ADAPT_STRUCT( SBG::AST::SBGProgram - , (SBG::LIB::NAT, nmbr_dims_) + , (std::size_t, arity_) (SBG::AST::StatementList, stms_) (SBG::AST::ExprList, exprs_) ) diff --git a/parser/statement_def.hpp b/parser/statement_def.hpp index 6570be3a..0bee8afd 100755 --- a/parser/statement_def.hpp +++ b/parser/statement_def.hpp @@ -20,20 +20,20 @@ #ifndef STATEMENT_DEF_PARSER_HPP #define STATEMENT_DEF_PARSER_HPP +#include "ast/statement.hpp" + #include #include #include #include -#include "ast/statement.hpp" - // Adapt structures ------------------------------------------------------------ BOOST_FUSION_ADAPT_STRUCT( SBG::AST::Assign, (SBG::AST::Name, l_)(SBG::AST::Expr, r_) ) -BOOST_FUSION_ADAPT_STRUCT(SBG::AST::ConfigDims, (SBG::LIB::NAT, nmbr_dims_)) +BOOST_FUSION_ADAPT_STRUCT(SBG::AST::ConfigDims, (std::size_t, arity)) // Statement parser ------------------------------------------------------------ diff --git a/sbg/CMakeLists.txt b/sbg/CMakeLists.txt index 01a2c1b2..dc212fec 100644 --- a/sbg/CMakeLists.txt +++ b/sbg/CMakeLists.txt @@ -12,13 +12,13 @@ target_sources( dom_ord_pwmap.cpp expression.cpp fixed_points.cpp + integer.cpp interval.cpp linear_expr.cpp map.cpp map_detail.cpp map_entry.cpp multidim_inter.cpp - natural.cpp ord_pwmap.cpp ord_set.cpp ord_unidim_dense_set.cpp diff --git a/sbg/bipartite_sbg.cpp b/sbg/bipartite_sbg.cpp index ef373950..ef473ce9 100644 --- a/sbg/bipartite_sbg.cpp +++ b/sbg/bipartite_sbg.cpp @@ -18,7 +18,9 @@ ******************************************************************************/ #include "sbg/bipartite_sbg.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" +#include "sbg/map.hpp" +#include "sbg/rational.hpp" #include "util/debug.hpp" #include @@ -70,9 +72,9 @@ void BipartiteSBG::addSetVertex(const Set& X, const Set& Y) } else if (!vertices.isEmpty()) { Set set_vertices = _Vmap.image(); std::size_t arity = vertices.arity(); - MD_NAT max = set_vertices.isEmpty() ? MD_NAT{arity, 0} + IntTuple max = set_vertices.isEmpty() ? IntTuple{arity, 0} : set_vertices.maxElem(); - _Vmap.emplace(vertices, max + MD_NAT{arity, 1}); + _Vmap.emplace(vertices, max + IntTuple{arity, 1}); _X = std::move(_X).cup(X); _Y = std::move(_Y).cup(Y); _V = std::move(_V).cup(std::move(vertices)); @@ -91,11 +93,11 @@ void BipartiteSBG::addSetEdge(const PWMap& pw1, const PWMap& pw2) if (!edges.isEmpty()) { Set set_edges = _Emap.image(); std::size_t arity = edges.arity(); - MD_NAT max = set_edges.isEmpty() ? MD_NAT{arity, 0} + IntTuple max = set_edges.isEmpty() ? IntTuple{arity, 0} : set_edges.maxElem(); _map1 = std::move(_map1).concatenation(pw1); _map2 = std::move(_map2).concatenation(pw2); - _Emap.emplace(edges, max + MD_NAT{arity, 1}); + _Emap.emplace(edges, max + IntTuple{arity, 1}); _E = std::move(_E).cup(std::move(edges)); } } else { @@ -139,33 +141,33 @@ BipartiteSBG copy(unsigned int copies, BipartiteSBG sbg) BipartiteSBG result = sbg; for (unsigned int j = 1; j < copies; ++j) { - MD_NAT max_v = result.V().maxElem(); + IntTuple max_v = result.V().maxElem(); Set set_vertices = Vmap.image(); - sbg.foreachSetVertex([&](const MD_NAT& SV) { + sbg.foreachSetVertex([&](const IntTuple& SV) { Set vertices = Vmap.preImage(Set{SV}); Set jth_X = vertices.intersection(X); Set jth_Y = vertices.intersection(Y); - result.addSetVertex(jth_X.offset(max_v), jth_Y.offset(max_v)); + result.addSetVertex(jth_X.translate(max_v), jth_Y.translate(max_v)); }); Expression offset_v; for (std::size_t k = 0; k < max_v.arity(); ++k) { - offset_v = offset_v.cartesianProduct(Expression{RATIONAL{1} - , RATIONAL{max_v[k]}}); + offset_v = offset_v.cartesianProduct(Expression{Rational{1} + , Rational{max_v[k]}}); } PWMap offset_pw_v{Map{V, offset_v}}; - MD_NAT max_e = result.E().maxElem(); + IntTuple max_e = result.E().maxElem(); Expression offset_e; for (std::size_t k = 0; k < max_e.arity(); ++k) { - offset_e = offset_e.cartesianProduct(Expression{RATIONAL{1} - , RATIONAL{max_e[k]}}); + offset_e = offset_e.cartesianProduct(Expression{Rational{1} + , Rational{max_e[k]}}); } PWMap offset_pw_e{Map{E, offset_e}}; PWMap inverse_offset_pw_e = offset_pw_e.inverse(); Set set_edges = Emap.image(); - sbg.foreachSetEdge([&](const MD_NAT& SE) { + sbg.foreachSetEdge([&](const IntTuple& SE) { Set edges = Emap.preImage(Set{SE}); PWMap pw1 = map1.restrict(edges); PWMap pw2 = map2.restrict(edges); diff --git a/sbg/bipartite_sbg.hpp b/sbg/bipartite_sbg.hpp index 9152e308..40f4c0f2 100644 --- a/sbg/bipartite_sbg.hpp +++ b/sbg/bipartite_sbg.hpp @@ -110,7 +110,7 @@ inline void BipartiteSBG::foreachSetVertex(FuncT&& f) const { Set remaining = _Vmap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } @@ -121,7 +121,7 @@ inline void BipartiteSBG::foreachSetEdge(FuncT&& f) const { Set remaining = _Emap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } diff --git a/sbg/directed_sbg.cpp b/sbg/directed_sbg.cpp index f57b5480..fd88288e 100644 --- a/sbg/directed_sbg.cpp +++ b/sbg/directed_sbg.cpp @@ -17,8 +17,10 @@ ******************************************************************************/ -#include "sbg/natural.hpp" #include "sbg/directed_sbg.hpp" +#include "sbg/integer.hpp" +#include "sbg/map.hpp" +#include "sbg/rational.hpp" #include "util/debug.hpp" #include @@ -66,9 +68,9 @@ void DirectedSBG::addSetVertex(const Set& vertices) } else if (!vertices.isEmpty()) { Set set_vertices = _Vmap.image(); std::size_t arity = vertices.arity(); - MD_NAT max = set_vertices.isEmpty() ? MD_NAT{arity, 0} + IntTuple max = set_vertices.isEmpty() ? IntTuple{arity, 0} : set_vertices.maxElem(); - _Vmap.emplace(vertices, max + MD_NAT{arity, 1}); + _Vmap.emplace(vertices, max + IntTuple{arity, 1}); _V = std::move(_V).cup(std::move(vertices)); } } @@ -85,10 +87,10 @@ void DirectedSBG::addSetEdge(const PWMap& pwB, const PWMap& pwD) if (!edges.isEmpty()) { Set set_edges = _Emap.image(); std::size_t arity = edges.arity(); - MD_NAT max = set_edges.isEmpty() ? MD_NAT{arity, 0} : set_edges.maxElem(); + IntTuple max = set_edges.isEmpty() ? IntTuple{arity, 0} : set_edges.maxElem(); _mapB = std::move(_mapB).concatenation(pwB); _mapD = std::move(_mapD).concatenation(pwD); - _Emap.emplace(edges, max + MD_NAT{arity, 1}); + _Emap.emplace(edges, max + IntTuple{arity, 1}); _E = std::move(_E).cup(std::move(edges)); } } else { @@ -148,30 +150,30 @@ DirectedSBG copy(unsigned int copies, DirectedSBG dsbg) DirectedSBG result = dsbg; for (unsigned int j = 1; j < copies; ++j) { - MD_NAT max_v = result.V().maxElem(); - dsbg.foreachSetVertex([&](const MD_NAT& SV) { + IntTuple max_v = result.V().maxElem(); + dsbg.foreachSetVertex([&](const IntTuple& SV) { Set vertices = Vmap.preImage(Set{SV}); - result.addSetVertex(vertices.offset(max_v)); + result.addSetVertex(vertices.translate(max_v)); }); Expression offset_v; for (std::size_t k = 0; k < max_v.arity(); ++k) { - offset_v = offset_v.cartesianProduct(Expression{RATIONAL{1} - , RATIONAL{max_v[k]}}); + offset_v = offset_v.cartesianProduct(Expression{Rational{1} + , Rational{max_v[k]}}); } PWMap offset_pw_v{Map{V, offset_v}}; - MD_NAT max_e = result.E().maxElem(); + IntTuple max_e = result.E().maxElem(); Expression offset_e; for (std::size_t k = 0; k < max_e.arity(); ++k) { - offset_e = offset_e.cartesianProduct(Expression{RATIONAL{1} - , RATIONAL{max_e[k]}}); + offset_e = offset_e.cartesianProduct(Expression{Rational{1} + , Rational{max_e[k]}}); } PWMap offset_pw_e{Map{E, offset_e}}; PWMap inverse_offset_pw_e = offset_pw_e.inverse(); Set set_edges = Emap.image(); - dsbg.foreachSetEdge([&](const MD_NAT& SE) { + dsbg.foreachSetEdge([&](const IntTuple& SE) { Set edges = Emap.preImage(Set{SE}); PWMap pwB = mapB.restrict(edges); PWMap pwD = mapD.restrict(edges); diff --git a/sbg/directed_sbg.hpp b/sbg/directed_sbg.hpp index 32544b82..d41f5171 100644 --- a/sbg/directed_sbg.hpp +++ b/sbg/directed_sbg.hpp @@ -120,7 +120,7 @@ inline void DirectedSBG::foreachSetVertex(FuncT&& f) const { Set remaining = _Vmap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } @@ -131,7 +131,7 @@ inline void DirectedSBG::foreachSetEdge(FuncT&& f) const { Set remaining = _Emap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } diff --git a/sbg/dom_ord_pwmap.cpp b/sbg/dom_ord_pwmap.cpp index a9569b75..33f92b7f 100644 --- a/sbg/dom_ord_pwmap.cpp +++ b/sbg/dom_ord_pwmap.cpp @@ -450,14 +450,14 @@ DomOrdPWMap DomOrdPWMap::composition(const DomOrdPWMap& other) const { DomOrdPWMap result; - NAT global_pos = 0; + std::size_t global_pos = 0; for (const MapEntry& other_entry : other._pieces) { Map other_map = other_entry.map(); Set img = other_map.image(); Perimeter img_perimeter = img.perimeter(); result.advanceHint(global_pos, other_entry); - MD_NAT img_max_perimeter = img_perimeter.max(); + IntTuple img_max_perimeter = img_perimeter.max(); for (const MapEntry& entry : _pieces) { const Perimeter& entry_perimeter = entry.perimeter(); diff --git a/sbg/expression.cpp b/sbg/expression.cpp index eb6f0a69..2077c471 100755 --- a/sbg/expression.cpp +++ b/sbg/expression.cpp @@ -29,20 +29,20 @@ namespace LIB { Expression::Expression() : _impl() {} -Expression::Expression(const MD_NAT& x) +Expression::Expression(const IntTuple& x) { - for (const NAT xj : x) { - _impl.emplace_back(detail::LinearExpr{0, RATIONAL{static_cast(xj)}}); + for (const Int xj : x) { + _impl.emplace_back(detail::LinearExpr{0, Rational{xj}}); } } -Expression::Expression(const RATIONAL& slope, const RATIONAL& offset) : _impl() +Expression::Expression(const Rational& slope, const Rational& offset) : _impl() { _impl.emplace_back(detail::LinearExpr{slope, offset}); } -Expression::Expression(std::size_t n, const RATIONAL& slope - , const RATIONAL& offset) +Expression::Expression(std::size_t n, const Rational& slope + , const Rational& offset) : _impl() { detail::LinearExpr linear_expr{slope, offset}; @@ -51,7 +51,7 @@ Expression::Expression(std::size_t n, const RATIONAL& slope } } -Expression::Expression(const MD_NAT& from, const MD_NAT& to) +Expression::Expression(const IntTuple& from, const IntTuple& to) { for (unsigned int k = 0; k < from.arity(); ++k) { _impl.emplace_back(1, to[k] - from[k]); @@ -132,9 +132,9 @@ std::ostream& operator<<(std::ostream& out, const Expression& expr) std::size_t Expression::arity() const { return _impl.size(); } -MD_NAT Expression::apply(const MD_NAT& x) const +IntTuple Expression::apply(const IntTuple& x) const { - MD_NAT result; + IntTuple result; for (unsigned int k = 0; k < _impl.size(); ++k) { result.pushBack(_impl[k].apply(x[k])); @@ -207,7 +207,7 @@ FixedPointsInfo Expression::fixedPoints() const if (kth.isId()) { result.emplace_back(Solution{SolutionKind::kFree}); } else if (kth.isConstant()) { - result.emplace_back(Solution{SolutionKind::kFixed, kth.offset().toNat()}); + result.emplace_back(Solution{SolutionKind::kFixed, kth.offset().toInt()}); } else { return {}; } diff --git a/sbg/expression.hpp b/sbg/expression.hpp index 2823a622..0817c391 100755 --- a/sbg/expression.hpp +++ b/sbg/expression.hpp @@ -29,7 +29,9 @@ #include "sbg/expression_impl.hpp" #include "sbg/fixed_points.hpp" +#include "sbg/integer.hpp" #include "sbg/linear_expr.hpp" +#include "sbg/rational.hpp" #include "rapidjson/document.h" @@ -55,24 +57,24 @@ class Expression { /** * @brief Constructs a constant mdle in all dimensions that maps to \p x. */ - Expression(const MD_NAT& x); + Expression(const IntTuple& x); /** * @brief Constructs a one-dimensional linear expression. */ - Expression(const RATIONAL& slope, const RATIONAL& offset); + Expression(const Rational& slope, const Rational& offset); /** * @brief Constructs a multi-dimensional expression of arity \p nmbr_copies * with \p the same linear expression in each dimension. */ - Expression(std::size_t n, const RATIONAL& slope, const RATIONAL& offset); + Expression(std::size_t n, const Rational& slope, const Rational& offset); /** * @brief Creates an injective expression that maps the first argument to the * second one. */ - Expression(const MD_NAT& from, const MD_NAT& to); + Expression(const IntTuple& from, const IntTuple& to); bool operator==(const Expression& other) const; bool operator!=(const Expression& other) const; @@ -87,7 +89,7 @@ class Expression { */ std::size_t arity() const; - MD_NAT apply(const MD_NAT& x) const; + IntTuple apply(const IntTuple& x) const; /** * @brief Calculate the composition of \p this with \p other, i.e. diff --git a/sbg/expression_impl.hpp b/sbg/expression_impl.hpp index b0f72fc5..a26281f6 100755 --- a/sbg/expression_impl.hpp +++ b/sbg/expression_impl.hpp @@ -2,7 +2,6 @@ @brief Multi-dimensional Expression implementation -
This file is part of Set--Based Graph Library. @@ -27,6 +26,8 @@ #include "sbg/linear_expr.hpp" +#include + namespace SBG { namespace LIB { diff --git a/sbg/fixed_points.cpp b/sbg/fixed_points.cpp index cbd07d08..5d792e10 100755 --- a/sbg/fixed_points.cpp +++ b/sbg/fixed_points.cpp @@ -25,12 +25,12 @@ namespace LIB { Solution::Solution(const SolutionKind kind) : _kind(kind), _value() {} -Solution::Solution(const SolutionKind kind, const NAT value) +Solution::Solution(const SolutionKind kind, const Int value) : _kind(kind), _value(value) {} const SolutionKind& Solution::kind() const { return _kind; } -const std::optional& Solution::value() const { return _value; } +const std::optional& Solution::value() const { return _value; } } // namespace LIB diff --git a/sbg/fixed_points.hpp b/sbg/fixed_points.hpp index 7ad2524b..cba9d88c 100755 --- a/sbg/fixed_points.hpp +++ b/sbg/fixed_points.hpp @@ -27,7 +27,7 @@ #ifndef SBGRAPH_SBG_FIXED_POINTS_HPP_ #define SBGRAPH_SBG_FIXED_POINTS_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include @@ -40,13 +40,13 @@ enum class SolutionKind { kFree, kFixed }; class Solution { public: Solution(const SolutionKind kind); - Solution(const SolutionKind kind, const NAT value); + Solution(const SolutionKind kind, const Int value); const SolutionKind& kind() const; - const std::optional& value() const; + const std::optional& value() const; private: - std::optional _value; + std::optional _value; SolutionKind _kind; }; diff --git a/sbg/natural.cpp b/sbg/integer.cpp similarity index 60% rename from sbg/natural.cpp rename to sbg/integer.cpp index 4d2445d3..8c2b5a8f 100755 --- a/sbg/natural.cpp +++ b/sbg/integer.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include @@ -27,47 +27,47 @@ namespace LIB { // Constructors/Destructors ---------------------------------------------------- -MD_NAT::MD_NAT() : _value() {} +IntTuple::IntTuple() : _value() {} -MD_NAT::MD_NAT(const NAT x) : _value() { _value.emplace_back(x); } +IntTuple::IntTuple(const Int x) : _value() { _value.emplace_back(x); } -MD_NAT::MD_NAT(const std::size_t k, const NAT x) : _value() +IntTuple::IntTuple(const std::size_t k, const Int x) : _value() { for (unsigned int j = 0; j < k; ++j) { - _value.emplace_back(x); + _value.push_back(x); } } -MD_NAT::MD_NAT(MD_NAT::Iterator b, MD_NAT::Iterator e) : _value(b, e) {} +IntTuple::IntTuple(IntTuple::Iterator b, IntTuple::Iterator e) : _value(b, e) {} // Getters --------------------------------------------------------------------- -MD_NAT::Iterator MD_NAT::begin() { return _value.begin(); } +IntTuple::Iterator IntTuple::begin() { return _value.begin(); } -MD_NAT::Iterator MD_NAT::end() { return _value.end(); } +IntTuple::Iterator IntTuple::end() { return _value.end(); } -MD_NAT::ConstIterator MD_NAT::begin() const { return _value.begin(); } +IntTuple::ConstIterator IntTuple::begin() const { return _value.begin(); } -MD_NAT::ConstIterator MD_NAT::end() const { return _value.end(); } +IntTuple::ConstIterator IntTuple::end() const { return _value.end(); } // Setters --------------------------------------------------------------------- -void MD_NAT::pushBack(const NAT x) { _value.push_back(x); } +void IntTuple::pushBack(const Int x) { _value.push_back(x); } // Operators ------------------------------------------------------------------- -NAT& MD_NAT::operator[](std::size_t n) { return _value[n]; } +Int& IntTuple::operator[](std::size_t n) { return _value[n]; } -const NAT& MD_NAT::operator[](std::size_t n) const { return _value[n]; } +const Int& IntTuple::operator[](std::size_t n) const { return _value[n]; } -bool MD_NAT::operator==(const MD_NAT& other) const +bool IntTuple::operator==(const IntTuple& other) const { return _value == other._value; } -bool MD_NAT::operator!=(const MD_NAT& other) const { return !(*this == other); } +bool IntTuple::operator!=(const IntTuple& other) const { return !(*this == other); } -bool MD_NAT::operator<(const MD_NAT& other) const +bool IntTuple::operator<(const IntTuple& other) const { for (unsigned int j = 0; j < arity(); ++j) { if (operator[](j) < other[j]) { @@ -81,14 +81,14 @@ bool MD_NAT::operator<(const MD_NAT& other) const } -bool MD_NAT::operator<=(const MD_NAT& other) const +bool IntTuple::operator<=(const IntTuple& other) const { return *this == other || *this < other; } -MD_NAT MD_NAT::operator+(const MD_NAT& other) const +IntTuple IntTuple::operator+(const IntTuple& other) const { - MD_NAT result; + IntTuple result; for (auto j = 0; j < _value.size(); ++j) { result.pushBack(operator[](j) + other[j]); @@ -97,13 +97,13 @@ MD_NAT MD_NAT::operator+(const MD_NAT& other) const return result; } -// Extra operations ------------------------------------------------------------ +// Member functions ------------------------------------------------------------ -std::size_t MD_NAT::arity() const { return _value.size(); } +std::size_t IntTuple::arity() const { return _value.size(); } -std::ostream& operator<<(std::ostream& out, const MD_NAT& md) +std::ostream& operator<<(std::ostream& out, const IntTuple& md) { - MD_NAT aux = md; + IntTuple aux = md; unsigned int sz = aux.arity(); if (sz == 1) { diff --git a/sbg/integer.hpp b/sbg/integer.hpp new file mode 100755 index 00000000..839f58f7 --- /dev/null +++ b/sbg/integer.hpp @@ -0,0 +1,114 @@ +/** @file integer.hpp + + @brief Multi-dimensional integer implementation + +
+ + 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 SBGRAPH_SBG_INTEGER_HPP_ +#define SBGRAPH_SBG_INTEGER_HPP_ + +#include +#include +#include + +namespace SBG { + +namespace LIB { + +//////////////////////////////////////////////////////////////////////////////// +// Integers implementation ----------------------------------------------------- +//////////////////////////////////////////////////////////////////////////////// + +using Int = long long int; +constexpr Int kPosInf = std::numeric_limits::max(); +constexpr Int kNegInf = std::numeric_limits::min(); + +//////////////////////////////////////////////////////////////////////////////// +// Multi-dimensional integers implementation ----------------------------------- +//////////////////////////////////////////////////////////////////////////////// + +class IntTuple { +public: + using Iterator = std::vector::iterator; + using ConstIterator = std::vector::const_iterator; + + /** + * @brief Constructs a zero-dimensional integer tuple. + */ + IntTuple(); + + /** + * @brief Constructs a one-dimensional integer tuple with value x. + */ + IntTuple(const Int x); + + /** + * @brief Constructs the tuple (x, ..., x) repeated \p k times. + */ + IntTuple(const std::size_t k, Int x); + + /** + * @brief Range constructor. + */ + IntTuple(Iterator b, Iterator e); + + Iterator begin(); + Iterator end(); + ConstIterator begin() const; + ConstIterator end() const; + + /** + * @brief Add a dimension to the integer tuple, and assign to it the value of + * x. + */ + void pushBack(const Int x); + + Int& operator[](std::size_t n); + const Int& operator[](std::size_t n) const; + + bool operator==(const IntTuple& other) const; + bool operator!=(const IntTuple& other) const; + + /** + * @brief An integer tuple x1 is less than other integer tuple x2 iff there + * is some dimension i for which x1[i] < x2[i] and for every j < i, + * x1[j] == x2[j]. + */ + bool operator<(const IntTuple& other) const; + + bool operator<=(const IntTuple& other) const; + + IntTuple operator+(const IntTuple& other) const; + + /** + * @brief Number of dimensions of the integer tuple, i.e. arity(1, 1, 1) = 3. + */ + std::size_t arity() const; + +private: + std::vector _value; +}; +std::ostream& operator<<(std::ostream& out, const IntTuple& md); + +} // namespace LIB + +} // namespace SBG + +#endif // SBGRAPH_SBG_INTEGER_HPP_ diff --git a/sbg/interval.cpp b/sbg/interval.cpp index 75def842..c41c3ccc 100755 --- a/sbg/interval.cpp +++ b/sbg/interval.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "sbg/interval.hpp" +#include "util/debug.hpp" #include #include @@ -31,28 +32,29 @@ namespace detail { // Auxiliary functions --------------------------------------------------------- -bool isMember(const SBG::LIB::NAT x, const SBG::LIB::detail::Interval& i) +bool isMember(const SBG::LIB::Int x, const SBG::LIB::detail::Interval& i) { if (x < i.begin() || x > i.end()) { return false; } - int rem = fmod(x - i.begin(), i.step()); - return rem == 0; + return ((x - i.begin()) % i.step()) == 0; } // Constructors/Destructors ---------------------------------------------------- Interval::Interval() : _begin(1), _step(1), _end(0) {} -Interval::Interval(const NAT x) : _begin(x), _step(1), _end(x) {} +Interval::Interval(const Int x) : _begin(x), _step(1), _end(x) {} -Interval::Interval(const NAT begin, const NAT step, const NAT end) +Interval::Interval(const Int begin, const Int step, const Int end) : _begin(begin), _step(step), _end(end) { + Util::ERROR_UNLESS(step >= 0 + , "Interval::Interval: step must be non-negative\n"); + if (end >= begin) { - int rem = fmod(end - begin, step); - _end = end - rem; + _end = end - ((end - begin) % step); _step = _begin == _end ? 1 : _step; } else { _begin = 1; @@ -63,17 +65,17 @@ Interval::Interval(const NAT begin, const NAT step, const NAT end) // Getters --------------------------------------------------------------------- -const NAT& Interval::begin() const +const Int& Interval::begin() const { return _begin; } -const NAT& Interval::step() const +const Int& Interval::step() const { return _step; } -const NAT& Interval::end() const +const Int& Interval::end() const { return _end; } @@ -123,14 +125,14 @@ std::ostream& operator<<(std::ostream& out, const Interval& i) unsigned int Interval::cardinal() const { - return (_end - _begin) / _step + 1; + return std::abs(_end - _begin) / _step + 1; } bool Interval::isEmpty() const { return _end < _begin; } -NAT Interval::minElem() const { return _begin; } +Int Interval::minElem() const { return _begin; } -NAT Interval::maxElem() const { return _end; } +Int Interval::maxElem() const { return _end; } Interval Interval::intersection(const Interval& other) const { @@ -142,18 +144,18 @@ Interval Interval::intersection(const Interval& other) const return Interval{}; } - // Two non overlapping intervals with the same step + // Two non overlapping intervals with the same step. if (_step == other._step && !isMember(_begin, other) && !isMember(other._begin, *this)) { return Interval{}; } - NAT max_begin = std::max(_begin, other._begin); - NAT new_step = std::lcm(_step, other._step); - NAT new_begin = max_begin; - NAT new_end = std::min(_end, other._end); + Int max_begin = std::max(_begin, other._begin); + Int new_step = std::lcm(_step, other._step); + Int new_begin = max_begin; + Int new_end = std::min(_end, other._end); bool found_member = false; - for (NAT x = max_begin; x < max_begin + new_step; ++x) { + for (Int x = max_begin; x < max_begin + new_step; ++x) { if (isMember(x, *this) && isMember(x, other)) { new_begin = x; found_member = true; @@ -167,11 +169,11 @@ Interval Interval::intersection(const Interval& other) const return Interval{}; } -// Extra operations ------------------------------------------------------------ +// Member functions ------------------------------------------------------------ -Interval Interval::offset(const NAT off) const +Interval Interval::translate(const Int t) const { - return Interval{_begin + off, _step, _end + off}; + return Interval{_begin + t, _step, _end + t}; } Perimeter Interval::perimeter() const { return Perimeter(_begin, _end); } @@ -198,11 +200,11 @@ rapidjson::Value toJSON(Interval i, rapidjson::Document::AllocatorType& alloc) { rapidjson::Value result{rapidjson::kArrayType}; - rapidjson::Value begin{static_cast(i.begin())}; + rapidjson::Value begin{static_cast(i.begin())}; result.PushBack(begin, alloc); - rapidjson::Value step{static_cast(i.step())}; + rapidjson::Value step{static_cast(i.step())}; result.PushBack(step, alloc); - rapidjson::Value end{static_cast(i.end())}; + rapidjson::Value end{static_cast(i.end())}; result.PushBack(end, alloc); return result; diff --git a/sbg/interval.hpp b/sbg/interval.hpp index 1ed623b5..17600868 100755 --- a/sbg/interval.hpp +++ b/sbg/interval.hpp @@ -2,8 +2,8 @@ @brief Interval implementation - An interval [lo:st:hi] is the set of natural numbers - {x : lo ≤ x ≤ hi ∧ x = lo + st * k, k ∈ ℕ}. Notice that an interval + An interval [lo:st:hi] is the set of integer numbers + {x : lo ≤ x ≤ hi ∧ x = lo + st * k, k ∈ ℤ}. Notice that an interval represents an unique set, but a set can have multiple representants. As such, in the implementation we will use the interval with the minimum hi existing. To ensure this, operations will be defined to create a new @@ -31,7 +31,7 @@ #ifndef SBGRAPH_SBG_INTERVAL_HPP_ #define SBGRAPH_SBG_INTERVAL_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/perimeter.hpp" #include "rapidjson/document.h" @@ -59,16 +59,16 @@ class Interval { /** * @brief Construct an interval only containing \p x. */ - Interval(const NAT x); + Interval(const Int x); /** * @brief Construct an interval with \p begin, \p step and \p end. */ - Interval(const NAT begin, const NAT step, const NAT end); + Interval(const Int begin, const Int step, const Int end); - const NAT& begin() const; - const NAT& step() const; - const NAT& end() const; + const Int& begin() const; + const Int& step() const; + const Int& end() const; bool operator<(const Interval& other) const; @@ -78,14 +78,14 @@ class Interval { */ unsigned int cardinal() const; bool isEmpty() const; - NAT minElem() const; - NAT maxElem() const; + Int minElem() const; + Int maxElem() const; Interval intersection(const Interval& other) const; /** * @brief Sum a constant value to every element of the interval. */ - Interval offset(const NAT off) const; + Interval translate(const Int off) const; Perimeter perimeter() const; @@ -96,9 +96,9 @@ class Interval { MaybeInterval compact(const Interval& other) const; private: - NAT _begin; - NAT _step; - NAT _end; + Int _begin; + Int _step; + Int _end; }; bool operator==(const Interval& lhs, const Interval& rhs); @@ -111,6 +111,10 @@ std::ostream& operator<<(std::ostream& out, const Interval& i); rapidjson::Value toJSON(Interval i, rapidjson::Document::AllocatorType& alloc); +// Interval constans ----------------------------------------------------------- + +const Interval kOneDimUniverse = Interval{kNegInf, 1, kPosInf}; + } // namespace detail } // namespace LIB diff --git a/sbg/linear_expr.cpp b/sbg/linear_expr.cpp index c361747e..424ad031 100755 --- a/sbg/linear_expr.cpp +++ b/sbg/linear_expr.cpp @@ -32,14 +32,14 @@ namespace detail { LinearExpr::LinearExpr() : _slope(1), _offset(0) {} -LinearExpr::LinearExpr(RATIONAL slope, RATIONAL offset) +LinearExpr::LinearExpr(Rational slope, Rational offset) : _slope(slope), _offset(offset) {} // Getters --------------------------------------------------------------------- -const RATIONAL& LinearExpr::slope() const { return _slope; } +const Rational& LinearExpr::slope() const { return _slope; } -const RATIONAL& LinearExpr::offset() const { return _offset; } +const Rational& LinearExpr::offset() const { return _offset; } // Operators ------------------------------------------------------------------- @@ -65,7 +65,7 @@ LinearExpr LinearExpr::operator-(const LinearExpr& other) const std::ostream& operator<<(std::ostream& out, const LinearExpr& le) { - RATIONAL slo = le.slope(), off = le.offset(); + Rational slo = le.slope(), off = le.offset(); if (slo != 0 && slo != 1) { if (slo.numerator() != 1) { @@ -100,27 +100,24 @@ std::ostream& operator<<(std::ostream& out, const LinearExpr& le) // Linear expression functions ------------------------------------------------- -NAT LinearExpr::apply(const NAT& x) const +Int LinearExpr::apply(const Int& x) const { - return (_slope*x + _offset).toNat(); + return (_slope*x + _offset).toInt(); } LinearExpr LinearExpr::composition(const LinearExpr& other) const { - RATIONAL new_slope = other._slope*_slope; - RATIONAL new_offset = _slope*other._offset + _offset; + Rational new_slope = other._slope*_slope; + Rational new_offset = _slope*other._offset + _offset; return LinearExpr{new_slope, new_offset}; } LinearExpr LinearExpr::inverse() const { - RATIONAL zero; - RATIONAL one{1}; - - RATIONAL new_slope{0, 1}; - RATIONAL new_offset{0, 1}; - new_slope = RATIONAL{_slope.denominator(), _slope.numerator()}; + Rational new_slope{0, 1}; + Rational new_offset{0, 1}; + new_slope = Rational{_slope.denominator(), _slope.numerator()}; new_offset = (-_offset)/_slope; return LinearExpr{new_slope, new_offset}; @@ -132,7 +129,7 @@ bool LinearExpr::isConstant() const { return _slope == 0; } bool LinearExpr::isInjective() const { return _slope != 0; } -RATIONAL LinearExpr::intersectionPoint(const LinearExpr& other) const +Rational LinearExpr::intersectionPoint(const LinearExpr& other) const { return (other._offset - _offset)/(_slope - other._slope); } diff --git a/sbg/linear_expr.hpp b/sbg/linear_expr.hpp index a61a5b65..d8ee0531 100755 --- a/sbg/linear_expr.hpp +++ b/sbg/linear_expr.hpp @@ -27,6 +27,7 @@ #ifndef SBGRAPH_SBG_LINEAR_EXPR_HPP_ #define SBGRAPH_SBG_LINEAR_EXPR_HPP_ +#include "sbg/integer.hpp" #include "sbg/rational.hpp" #include "rapidjson/document.h" @@ -49,10 +50,10 @@ class LinearExpr { /** * @brief Construct a linear expression defining the \p slope and \p offset. */ - LinearExpr(RATIONAL slope, RATIONAL offset); + LinearExpr(Rational slope, Rational offset); - const RATIONAL& slope() const; - const RATIONAL& offset() const; + const Rational& slope() const; + const Rational& offset() const; bool operator==(const LinearExpr &other) const; bool operator!=(const LinearExpr &other) const; @@ -63,9 +64,8 @@ class LinearExpr { /** * @brief Calculates the result of applying the linear expression to \p x. - * Precondition: result is >= 0. */ - NAT apply(const NAT& x) const; + Int apply(const Int& x) const; /** * @brief Calculate the composition of \p this with \p other, i.e. @@ -92,11 +92,11 @@ class LinearExpr { /** * Precondition: both slopes should be different. */ - RATIONAL intersectionPoint(const LinearExpr& other) const; + Rational intersectionPoint(const LinearExpr& other) const; private: - RATIONAL _slope; - RATIONAL _offset; + Rational _slope; + Rational _offset; }; std::ostream &operator<<(std::ostream &out, const LinearExpr& le); diff --git a/sbg/map.cpp b/sbg/map.cpp index 83e1bc5e..8fe10946 100755 --- a/sbg/map.cpp +++ b/sbg/map.cpp @@ -34,7 +34,7 @@ namespace LIB { Map::Map() : _domain() {} -Map::Map(const MD_NAT& x, const Expression& expr) +Map::Map(const IntTuple& x, const Expression& expr) : _domain(x), _law(expr) {} Map::Map(const Set& s, const Expression& expr) : _domain(s), _law(expr) {} diff --git a/sbg/map.hpp b/sbg/map.hpp index 8de564ab..2080fb88 100755 --- a/sbg/map.hpp +++ b/sbg/map.hpp @@ -29,8 +29,8 @@ #ifndef SBGRAPH_SBG_MAP_HPP_ #define SBGRAPH_SBG_MAP_HPP_ -#include "sbg/natural.hpp" #include "sbg/expression.hpp" +#include "sbg/integer.hpp" #include "sbg/set.hpp" #include "rapidjson/document.h" @@ -58,8 +58,8 @@ class Map { * @brief Construct a map with a single element \p x in its domain, and with * \p exp as its law. */ - Map(const MD_NAT& x, const Expression& expr); - Map(MD_NAT&& x, Expression&& expr); + Map(const IntTuple& x, const Expression& expr); + Map(IntTuple&& x, Expression&& expr); /** * @brief Construct a map defining its domain as \p s and law as \p exp. diff --git a/sbg/map_detail.cpp b/sbg/map_detail.cpp index 0017cefc..4b6e0898 100755 --- a/sbg/map_detail.cpp +++ b/sbg/map_detail.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "sbg/map_detail.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/ord_unidim_dense_set.hpp" #include "sbg/rational.hpp" #include "sbg/set_detail.hpp" @@ -48,15 +48,15 @@ Interval image(const Interval& i, const LinearExpr& linear_expr) } if (linear_expr.isConstant()) { - NAT value = linear_expr.apply(i.begin()); + Int value = linear_expr.apply(i.begin()); return Interval{value, 1, value}; } - NAT new_begin = linear_expr.apply(i.begin()); - RATIONAL m = linear_expr.slope(); - NAT step = i.step(); - NAT new_step = m >= 0 ? (m*step).toNat() : (-m*step).toNat(); - NAT new_end = linear_expr.apply(i.end()); + Int new_begin = linear_expr.apply(i.begin()); + Rational m = linear_expr.slope(); + Int step = i.step(); + Int new_step = m >= 0 ? (m*step).toInt() : (-m*step).toInt(); + Int new_end = linear_expr.apply(i.end()); return Interval{new_begin, new_step, new_end}; } @@ -132,7 +132,7 @@ Interval preImage(const Interval& i, const LinearExpr& linear_expr) } if (linear_expr.isConstant()) { - return Interval{0, 1, Inf}; + return kOneDimUniverse; } return image(i, linear_expr.inverse()); @@ -275,33 +275,33 @@ Map MapDetail::inverse(const Set& s, const Expression& expr) Interval lessImage(const LinearExpr& linear_expr1 , const LinearExpr& linear_expr2) { - RATIONAL m1 = linear_expr1.slope(); - RATIONAL m2 = linear_expr2.slope(); + Rational m1 = linear_expr1.slope(); + Rational m2 = linear_expr2.slope(); if (m1 == m2) { - RATIONAL h1 = linear_expr1.offset(); - RATIONAL h2 = linear_expr2.offset(); + Rational h1 = linear_expr1.offset(); + Rational h2 = linear_expr2.offset(); if (h1 < h2) { - return Interval{0, 1, Inf}; + return kOneDimUniverse; } } else { - RATIONAL point = linear_expr1.intersectionPoint(linear_expr2); + Rational point = linear_expr1.intersectionPoint(linear_expr2); if (point >= 0) { - NAT floor = point.floor(); - NAT ceil = point.ceiling(); + Int floor = point.floor(); + Int ceil = point.ceiling(); if (ceil == floor) { - NAT floor_minus = floor == 0 ? 0 : floor - 1; - NAT ceil_plus = ceil == Inf ? Inf : ceil + 1; - Interval kth = m1 < m2 ? Interval{ceil_plus, 1, Inf} - : Interval {0, 1, floor_minus}; + Int floor_minus = floor == kNegInf ? kNegInf : floor - 1; + Int ceil_plus = ceil == kPosInf ? kPosInf : ceil + 1; + Interval kth = m1 < m2 ? Interval{ceil_plus, 1, kPosInf} + : Interval {kNegInf, 1, floor_minus}; return kth; } else { - Interval kth = m1 < m2 ? Interval{ceil, 1, Inf} - : Interval {0, 1, floor}; + Interval kth = m1 < m2 ? Interval{ceil, 1, kPosInf} + : Interval {kNegInf, 1, floor}; return kth; } } else { if (m1 < m2) { - return Interval{0, 1, Inf}; + return kOneDimUniverse; } } } @@ -315,8 +315,7 @@ std::vector lessImage(const ExpressionImpl& expr1 std::vector result; unsigned int arity = expr1.size(); - Interval universe_one_dim{0, 1, Inf}; - MultiDimInter less_image{arity, universe_one_dim}; + MultiDimInter less_image{arity, kOneDimUniverse}; for (unsigned int k = 0; k < arity; ++k) { LinearExpr linear_expr1 = expr1[k]; LinearExpr linear_expr2 = expr2[k]; @@ -330,14 +329,14 @@ std::vector lessImage(const ExpressionImpl& expr1 } } - RATIONAL cross = linear_expr1.intersectionPoint(linear_expr2); + Rational cross = linear_expr1.intersectionPoint(linear_expr2); if (cross.floor() == cross.ceiling()) { - less_image[k] = Interval{cross.toNat(), 1, cross.toNat()}; + less_image[k] = Interval{cross.toInt(), 1, cross.toInt()}; } else { break; } } else if (linear_expr1 == linear_expr2) { - less_image[k] = universe_one_dim; + less_image[k] = kOneDimUniverse; } else { break; } @@ -394,12 +393,12 @@ Set MapDetail::lessImage(const Expression& expr1, const Expression& expr2) void partition(const Interval& i, const LinearExpr& linear_expr , AtomicMapVector& result) { - INT h = linear_expr.offset().toInt(); - INT absh = std::abs(h); + Int h = linear_expr.offset().toInt(); + Int absh = std::abs(h); for (int j = 1; j <= absh; ++j) { - NAT new_begin = i.begin() + j - 1; - Interval jth_piece{new_begin, (NAT) absh, i.end()}; - RATIONAL jth_off; + Int new_begin = i.begin() + j - 1; + Interval jth_piece{new_begin, absh, i.end()}; + Rational jth_off; if (h > 0) { jth_off = jth_piece.end() + h; } else { @@ -415,29 +414,28 @@ AtomicMapVector reduce(const Interval& i, const LinearExpr& linear_expr) AtomicMapVector result; // No partition of the piece is needed - RATIONAL zero(0, 1); - INT h = linear_expr.offset().toInt(); - NAT st = i.step(); - if (h == (INT) st) { - NAT hi = i.end(); - if (st < Inf - hi) { - LinearExpr convergence_value{zero, static_cast(hi + st)}; + Int h = linear_expr.offset().toInt(); + Int st = i.step(); + if (h == st) { + Int hi = i.end(); + if (st < kPosInf - hi) { + LinearExpr convergence_value{Rational{0}, hi + st}; result.emplace_back(i, convergence_value); return result; } - } else if (h == (INT) -st) { - NAT lo = i.begin(); + } else if (h == -st) { + Int lo = i.begin(); if (lo >= st) { - LinearExpr convergence_value{zero, static_cast(lo - st)}; + LinearExpr convergence_value{Rational{0}, lo - st}; result.emplace_back(i, convergence_value); return result; } } // Partition of the piece needed - if (h % (INT) st == 0) { + if (h % st == 0) { // Is convenient the partition of the piece? - if ((INT) i.cardinal() > h*h) { + if ((Int) i.cardinal() > h*h) { partition(i, linear_expr, result); } else { result.emplace_back(i, linear_expr); @@ -638,13 +636,13 @@ MapVector MapDetail::imageMultiplicity(const Map& m) if (law.isInjective()) { Set result_domain = m.image(); - Expression result_expr{MD_NAT{domain.arity(), 1}}; + Expression result_expr{IntTuple{domain.arity(), 1}}; result.emplace_back(result_domain, result_expr); return result; } if (law.isConstant()) { - result.emplace_back(m.image(), Expression{MD_NAT{domain.arity() + result.emplace_back(m.image(), Expression{IntTuple{domain.arity() , m.domain().cardinal()}}); return result; } diff --git a/sbg/multidim_inter.cpp b/sbg/multidim_inter.cpp index a788f8d8..4c7dd885 100755 --- a/sbg/multidim_inter.cpp +++ b/sbg/multidim_inter.cpp @@ -31,9 +31,9 @@ namespace detail { MultiDimInter::MultiDimInter() : _intervals() {} -MultiDimInter::MultiDimInter(const MD_NAT& x) : _intervals() +MultiDimInter::MultiDimInter(const IntTuple& x) : _intervals() { - for (const NAT xi : x) { + for (const Int xi : x) { _intervals.emplace_back(Interval{xi, 1, xi}); } } @@ -143,9 +143,9 @@ unsigned int MultiDimInter::cardinal() const bool MultiDimInter::isEmpty() const { return _intervals.empty(); } -MD_NAT MultiDimInter::minElem() const +IntTuple MultiDimInter::minElem() const { - MD_NAT result; + IntTuple result; for (const Interval& i : _intervals) { result.pushBack(i.begin()); @@ -154,9 +154,9 @@ MD_NAT MultiDimInter::minElem() const return result; } -MD_NAT MultiDimInter::maxElem() const +IntTuple MultiDimInter::maxElem() const { - MD_NAT result; + IntTuple result; for (const Interval& i : _intervals) { result.pushBack(i.end()); @@ -200,12 +200,12 @@ MultiDimInter MultiDimInter::cartesianProduct(const MultiDimInter& other) const std::size_t MultiDimInter::arity() const { return _intervals.size(); } -MultiDimInter MultiDimInter::offset(const MD_NAT& off) const +MultiDimInter MultiDimInter::translate(const IntTuple& t) const { MultiDimInter result; for (unsigned int j = 0; j < arity(); ++j) { - result.pushBack(operator[](j).offset(off[j])); + result.pushBack(operator[](j).translate(t[j])); } return result; diff --git a/sbg/multidim_inter.hpp b/sbg/multidim_inter.hpp index c90a5182..e9abea64 100755 --- a/sbg/multidim_inter.hpp +++ b/sbg/multidim_inter.hpp @@ -28,8 +28,8 @@ #ifndef SBGRAPH_SBG_MULTIDIM_INTER_HPP_ #define SBGRAPH_SBG_MULTIDIM_INTER_HPP_ +#include "sbg/integer.hpp" #include "sbg/interval.hpp" -#include "sbg/natural.hpp" #include "sbg/perimeter.hpp" #include "rapidjson/document.h" @@ -60,7 +60,7 @@ class MultiDimInter { /** * @brief Construct a mdi with a single element \p x. */ - MultiDimInter(const MD_NAT& x); + MultiDimInter(const IntTuple& x); /** * @brief Construct a one-dimensional mdi with the same elements as \p i. @@ -101,8 +101,8 @@ class MultiDimInter { */ unsigned int cardinal() const; bool isEmpty() const; - MD_NAT minElem() const; - MD_NAT maxElem() const; + IntTuple minElem() const; + IntTuple maxElem() const; MultiDimInter intersection(const MultiDimInter& other) const; MultiDimInter cartesianProduct(const MultiDimInter& other) const; @@ -117,7 +117,7 @@ class MultiDimInter { /** * @brief Sum a constant value to every element of the mdi. */ - MultiDimInter offset(const MD_NAT& off) const; + MultiDimInter translate(const IntTuple& t) const; /** * @brief Operation that given two disjoint mdis returns the lesser one. diff --git a/sbg/natural.hpp b/sbg/natural.hpp deleted file mode 100755 index 5d2023b5..00000000 --- a/sbg/natural.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/** @file natural.hpp - - @brief Naturals (one and multi-dimensional) implementation - -
- - 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 SBGRAPH_SBG_NATURAL_HPP_ -#define SBGRAPH_SBG_NATURAL_HPP_ - -#include -#include -#include - -namespace SBG { - -namespace LIB { - -//////////////////////////////////////////////////////////////////////////////// -// Naturals implementation ----------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// - -using NAT = long long unsigned int; -constexpr NAT Inf = std::numeric_limits::max(); - -//////////////////////////////////////////////////////////////////////////////// -// Naturals implementation ----------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// - -class MD_NAT { -public: - using VNAT = std::vector; - using Iterator = VNAT::iterator; - using ConstIterator = VNAT::const_iterator; - - /** - * @brief Constructs a zero-dimensional mdnat. - */ - MD_NAT(); - - /** - * @brief Constructs a one-dimensional mdnat with value x. - */ - MD_NAT(const NAT x); - - /** - * @brief Constructs a nmbr_copies-dimensional mdnat with value x in every - * dimension. - */ - MD_NAT(const std::size_t k, NAT x); - - /** - * @brief Range constructor. - */ - MD_NAT(Iterator b, Iterator e); - - Iterator begin(); - Iterator end(); - ConstIterator begin() const; - ConstIterator end() const; - - /** - * @brief Add a dimension to the mdnat, and assign to it the value of x. - */ - void pushBack(const NAT x); - - NAT& operator[](std::size_t n); - const NAT& operator[](std::size_t n) const; - - bool operator==(const MD_NAT& other) const; - bool operator!=(const MD_NAT& other) const; - - /** - * @brief A mdnat x1 is less than other mdnat x2 iff there is some dimension - * i for which x1[i] < x2[i] and for every j < i, x1[j] == x2[j]. - */ - bool operator<(const MD_NAT& other) const; - - bool operator<=(const MD_NAT& other) const; - - MD_NAT operator+(const MD_NAT& other) const; - - /** - * @brief Number of dimensions of the mdnat, i.e. arity(1, 1, 1) = 3. - */ - std::size_t arity() const; - -private: - VNAT _value; -}; -std::ostream& operator<<(std::ostream& out, const MD_NAT& md); - -} // namespace LIB - -} // namespace SBG - -#endif // SBGRAPH_SBG_NATURAL_HPP_ diff --git a/sbg/ord_pwmap.cpp b/sbg/ord_pwmap.cpp index 689ef0ae..7a9fb962 100644 --- a/sbg/ord_pwmap.cpp +++ b/sbg/ord_pwmap.cpp @@ -363,9 +363,9 @@ OrdPWMap OrdPWMap::restrict(const Set& subdom) const } OrdPWMap result; - NAT global_pos = 0; + unsigned int global_pos = 0; Perimeter subdom_perimeter = subdom.perimeter(); - const MD_NAT subdom_max_perimeter = subdom_perimeter.max(); + const IntTuple subdom_max_perimeter = subdom_perimeter.max(); for (const MapEntry& entry : _pieces) { const Perimeter& entry_perimeter = entry.perimeter(); if (subdom_perimeter.overlap(entry_perimeter)) { @@ -426,14 +426,14 @@ OrdPWMap OrdPWMap::composition(const OrdPWMap& other) const { OrdPWMap result; - NAT global_pos = 0; + unsigned int global_pos = 0; for (const MapEntry& other_entry : other._pieces) { Map other_map = other_entry.map(); Set img = other_map.image(); Perimeter img_perimeter = img.perimeter(); result.advanceHint(global_pos, other_entry); - MD_NAT img_max_perimeter = img_perimeter.max(); + IntTuple img_max_perimeter = img_perimeter.max(); for (const MapEntry& entry : _pieces) { const Perimeter& entry_perimeter = entry.perimeter(); diff --git a/sbg/ord_set.cpp b/sbg/ord_set.cpp index c41e5a9e..d87a5ebb 100644 --- a/sbg/ord_set.cpp +++ b/sbg/ord_set.cpp @@ -63,7 +63,7 @@ bool overlap(const MultiDimInter& mdi1, const MultiDimInter& mdi2) OrderedSet::OrderedSet() : _pieces() {} -OrderedSet::OrderedSet(const MD_NAT& x) : _pieces() +OrderedSet::OrderedSet(const IntTuple& x) : _pieces() { _pieces.push_back(MultiDimInter{x}); } @@ -92,13 +92,12 @@ OrderedSet::OrderedSet(const FixedPointsInfo& info) : _pieces() { if (info) { std::vector solutions = info.value(); - Interval universe_one_dim{0, 1, Inf}; MultiDimInter result_mdi; for (const Solution& jth_solution : solutions) { if (jth_solution.kind() == SolutionKind::kFixed) { result_mdi.pushBack(jth_solution.value().value()); } else if (jth_solution.kind() == SolutionKind::kFree) { - result_mdi.pushBack(universe_one_dim); + result_mdi.pushBack(kOneDimUniverse); } } pushBack(result_mdi); @@ -133,7 +132,7 @@ void OrderedSet::pushBack(const MultiDimInter& mdi) _pieces.insert(it.base(), mdi); } -NAT OrderedSet::advanceHint(NAT hint, const MultiDimInter& mdi) +Int OrderedSet::advanceHint(Int hint, const MultiDimInter& mdi) { auto it = _pieces.begin(); auto end = _pieces.end(); @@ -148,7 +147,7 @@ NAT OrderedSet::advanceHint(NAT hint, const MultiDimInter& mdi) return hint; } -void OrderedSet::insertHint(const NAT hint, const MultiDimInter& mdi) +void OrderedSet::insertHint(const Int hint, const MultiDimInter& mdi) { if (mdi.isEmpty()) { return; @@ -231,14 +230,14 @@ unsigned int OrderedSet::cardinal() const bool OrderedSet::isEmpty() const { return _pieces.empty(); } -MD_NAT OrderedSet::minElem() const +IntTuple OrderedSet::minElem() const { return _pieces.begin()->minElem(); } -MD_NAT OrderedSet::maxElem() const +IntTuple OrderedSet::maxElem() const { - MD_NAT result = _pieces.begin()->maxElem(); + IntTuple result = _pieces.begin()->maxElem(); for (const MultiDimInter& mdi : _pieces) { result = std::max(result, mdi.maxElem()); @@ -267,11 +266,11 @@ OrderedSet OrderedSet::intersectionEpilogue(const OrderedSet& lhs indexes.push_front(i); } - NAT global_position = 0; + Int global_position = 0; auto short_begin = short_set.begin(); for (const MultiDimInter& long_elem : long_set) { - const MD_NAT long_min = long_elem.minElem(); - const MD_NAT long_max = long_elem.maxElem(); + const IntTuple long_min = long_elem.minElem(); + const IntTuple long_max = long_elem.maxElem(); auto prev_index = indexes.before_begin(); auto curr_index = indexes.begin(); @@ -380,27 +379,26 @@ OrderedSet OrderedSet::complementAtom() const } MultiDimInter during_mdi = dense_mdi; - Interval universe_one_dim{0, 1, Inf}; - MultiDimInter univ{mdi.arity(), universe_one_dim}; + MultiDimInter univ{mdi.arity(), kOneDimUniverse}; std::size_t dim = 0; std::size_t global_position = 0; for (const Interval& i : mdi) { std::size_t local_pos = global_position; // Before interval - if (i.begin() != 0) { + if (i.begin() != kNegInf) { Interval i_res{0, 1, i.begin() - 1}; if (!i_res.isEmpty()) { univ[dim] = i_res; result.insert(result.begin() + local_pos, univ); ++local_pos; ++global_position; - univ[dim] = universe_one_dim; + univ[dim] = kOneDimUniverse; } } // "During" interval - if (i.begin() < Inf && i.step() > 1) { + if (i.begin() < kPosInf && i.step() > 1) { for (unsigned int j = 0; j < i.step() - 1; ++j) { Interval i_res{i.begin() + j + 1, i.step(), i.end()}; if (!i_res.isEmpty()) { @@ -412,13 +410,13 @@ OrderedSet OrderedSet::complementAtom() const } // After interval - if (i.end() < Inf) { - Interval i_res{i.end() + 1, 1, Inf}; + if (i.end() < kPosInf) { + Interval i_res{i.end() + 1, 1, kPosInf}; if (!i_res.isEmpty()) { univ[dim] = i_res; result.insert(result.begin() + local_pos, univ); ++local_pos; - univ[dim] = universe_one_dim; + univ[dim] = kOneDimUniverse; } } univ[dim] = dense_mdi[dim]; @@ -453,7 +451,7 @@ void OrderedSet::intersectionComplement(const OrderedSet& result._pieces.insert(result.end(), std::make_move_iterator(_pieces.begin()) , std::make_move_iterator(it)); - NAT global_position = 0; + Int global_position = 0; for (; it != _pieces.end(); ++it) { const MultiDimInter& elem = *it; global_position = result.advanceHint(global_position, elem); @@ -600,12 +598,12 @@ OrderedSet OrderedSet::disjointCup(OrderedSet&& other) && return OrderedSet{std::move(result)}; } -OrderedSet OrderedSet::offset(const MD_NAT& off) const +OrderedSet OrderedSet::translate(const IntTuple& t) const { OrderedSet result; for (const MultiDimInter& mdi : _pieces) { - result.pushBack(mdi.offset(off)); + result.pushBack(mdi.translate(t)); } return result; @@ -613,16 +611,16 @@ OrderedSet OrderedSet::offset(const MD_NAT& off) const Perimeter OrderedSet::perimeter() const { - MD_NAT min; - MD_NAT max; + IntTuple min; + IntTuple max; if (!isEmpty()) { std::size_t arity = this->arity(); - min = MD_NAT{arity, Inf}; - max = MD_NAT{arity, 0}; + min = IntTuple{arity, kPosInf}; + max = IntTuple{arity, kNegInf}; for (const MultiDimInter& mdi : _pieces) { - MD_NAT candidate_min = mdi.minElem(); - MD_NAT candidate_max = mdi.maxElem(); + IntTuple candidate_min = mdi.minElem(); + IntTuple candidate_max = mdi.maxElem(); for (size_t i = 0; i < arity; ++i) { min[i] = std::min(min[i], candidate_min[i]); max[i] = std::max(max[i], candidate_max[i]); diff --git a/sbg/ord_set.hpp b/sbg/ord_set.hpp index cd0d2a0f..770b8915 100644 --- a/sbg/ord_set.hpp +++ b/sbg/ord_set.hpp @@ -24,11 +24,10 @@ #ifndef SBGRAPH_SBG_ORD_SET_HPP_ #define SBGRAPH_SBG_ORD_SET_HPP_ -#include "sbg/expression.hpp" #include "sbg/fixed_points.hpp" +#include "sbg/integer.hpp" #include "sbg/interval.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" #include "sbg/perimeter.hpp" #include "rapidjson/document.h" @@ -53,7 +52,7 @@ class OrderedSet { using ConstIt = OrdMDICollection::const_iterator; OrderedSet(); - OrderedSet(const MD_NAT& x); + OrderedSet(const IntTuple& x); OrderedSet(const detail::Interval& i); OrderedSet(const detail::MultiDimInter& mdi); OrderedSet(const OrdMDICollection& pieces); @@ -73,8 +72,8 @@ class OrderedSet { unsigned int cardinal() const; bool isEmpty() const; - MD_NAT minElem() const; - MD_NAT maxElem() const; + IntTuple minElem() const; + IntTuple maxElem() const; OrderedSet intersection(const OrderedSet& other) const; OrderedSet cup(const OrderedSet& other) const &; OrderedSet cup(OrderedSet&& other) const &; @@ -91,13 +90,13 @@ class OrderedSet { OrderedSet disjointCup(const OrderedSet& other) &&; OrderedSet disjointCup(OrderedSet&& other) const &; OrderedSet disjointCup(OrderedSet&& other) &&; - OrderedSet offset(const MD_NAT& off) const; + OrderedSet translate(const IntTuple& t) const; Perimeter perimeter() const; void compact(); private: - NAT advanceHint(NAT hint, const MultiDimInter& mdi); - void insertHint(const NAT hint, const MultiDimInter& mdi); + Int advanceHint(Int hint, const MultiDimInter& mdi); + void insertHint(const Int hint, const MultiDimInter& mdi); OrderedSet intersectionEpilogue(const OrderedSet& lhs, const OrderedSet& rhs) const; diff --git a/sbg/ord_unidim_dense_set.cpp b/sbg/ord_unidim_dense_set.cpp index c04e9122..cfeb3505 100644 --- a/sbg/ord_unidim_dense_set.cpp +++ b/sbg/ord_unidim_dense_set.cpp @@ -85,7 +85,7 @@ OrdUnidimDenseSet::OrdIntervalCollection OrdUnidimDenseSet::OrdUnidimDenseSet() : _pieces() {} -OrdUnidimDenseSet::OrdUnidimDenseSet(const NAT x) : _pieces() +OrdUnidimDenseSet::OrdUnidimDenseSet(const Int x) : _pieces() { _pieces.emplace_back(x); } @@ -113,7 +113,7 @@ OrdUnidimDenseSet::OrdUnidimDenseSet(const FixedPointsInfo& info) if (jth_solution.kind() == SolutionKind::kFixed) { _pieces.emplace_back(jth_solution.value().value()); } else { - _pieces.emplace_back(0, 1, Inf); + _pieces.emplace_back(kOneDimUniverse); } } } @@ -220,14 +220,14 @@ unsigned int OrdUnidimDenseSet::cardinal() const bool OrdUnidimDenseSet::isEmpty() const { return _pieces.empty(); } -MD_NAT OrdUnidimDenseSet::minElem() const +IntTuple OrdUnidimDenseSet::minElem() const { - return MD_NAT(_pieces.front().begin()); + return IntTuple(_pieces.front().begin()); } -MD_NAT OrdUnidimDenseSet::maxElem() const +IntTuple OrdUnidimDenseSet::maxElem() const { - return MD_NAT(_pieces.back().end()); + return IntTuple(_pieces.back().end()); } OrdUnidimDenseSet OrdUnidimDenseSet::intersection(const OrdUnidimDenseSet& @@ -290,7 +290,7 @@ OrdUnidimDenseSet OrdUnidimDenseSet::complement() const OrdUnidimDenseSet result; if (isEmpty()) { - result._pieces.emplace_back(0, 1, Inf); + result._pieces.emplace_back(kOneDimUniverse); return result; } @@ -298,7 +298,7 @@ OrdUnidimDenseSet OrdUnidimDenseSet::complement() const result._pieces.emplace_back(0, 1, _pieces.front().minElem() - 1); // Complement between pieces of the set - NAT last_interval_end = _pieces.front().maxElem(); + Int last_interval_end = _pieces.front().maxElem(); unsigned int j = 0; for (const Interval& i : _pieces) { if (j != 0) { @@ -311,7 +311,7 @@ OrdUnidimDenseSet OrdUnidimDenseSet::complement() const } // Complement after maximum element of the set - result._pieces.emplace_back(last_interval_end + 1, 1, Inf); + result._pieces.emplace_back(last_interval_end + 1, 1, kPosInf); return result; } @@ -394,12 +394,12 @@ OrdUnidimDenseSet OrdUnidimDenseSet::disjointCup(OrdUnidimDenseSet&& other) && return traverse(least, other); } -OrdUnidimDenseSet OrdUnidimDenseSet::offset(const MD_NAT& offset) const +OrdUnidimDenseSet OrdUnidimDenseSet::translate(const IntTuple& t) const { OrdUnidimDenseSet result; for (const Interval& i : _pieces) { - result.pushBack(i.offset(offset[0])); + result.pushBack(i.translate(t[0])); } return result; diff --git a/sbg/ord_unidim_dense_set.hpp b/sbg/ord_unidim_dense_set.hpp index 30ac1b23..ffb6a516 100644 --- a/sbg/ord_unidim_dense_set.hpp +++ b/sbg/ord_unidim_dense_set.hpp @@ -27,11 +27,10 @@ #ifndef SBGRAPH_SBG_ORD_UNIDIM_DENSE_SET_HPP_ #define SBGRAPH_SBG_ORD_UNIDIM_DENSE_SET_HPP_ -#include "sbg/expression.hpp" #include "sbg/fixed_points.hpp" +#include "sbg/integer.hpp" #include "sbg/interval.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" #include "sbg/perimeter.hpp" #include "rapidjson/document.h" @@ -56,7 +55,7 @@ class OrdUnidimDenseSet { using ConstIt = OrdIntervalCollection::const_iterator; OrdUnidimDenseSet(); - OrdUnidimDenseSet(const NAT x); + OrdUnidimDenseSet(const Int x); OrdUnidimDenseSet(const detail::Interval& i); OrdUnidimDenseSet(const OrdIntervalCollection& pieces); OrdUnidimDenseSet(OrdIntervalCollection&& pieces); @@ -75,8 +74,8 @@ class OrdUnidimDenseSet { unsigned int cardinal() const; bool isEmpty() const; - MD_NAT minElem() const; - MD_NAT maxElem() const; + IntTuple minElem() const; + IntTuple maxElem() const; OrdUnidimDenseSet intersection(const OrdUnidimDenseSet& other) const; OrdUnidimDenseSet cup(const OrdUnidimDenseSet& other) const &; OrdUnidimDenseSet cup(const OrdUnidimDenseSet& other) &&; @@ -93,7 +92,7 @@ class OrdUnidimDenseSet { OrdUnidimDenseSet disjointCup(const OrdUnidimDenseSet& other) &&; OrdUnidimDenseSet disjointCup(OrdUnidimDenseSet&& other) const &; OrdUnidimDenseSet disjointCup(OrdUnidimDenseSet&& other) &&; - OrdUnidimDenseSet offset(const MD_NAT& offset) const; + OrdUnidimDenseSet translate(const IntTuple& t) const; Perimeter perimeter() const; void compact(); diff --git a/sbg/perimeter.cpp b/sbg/perimeter.cpp index 9dac1e0d..4dc7fcd4 100755 --- a/sbg/perimeter.cpp +++ b/sbg/perimeter.cpp @@ -27,12 +27,12 @@ namespace LIB { // Set perimeter --------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -Perimeter::Perimeter(const MD_NAT& min, const MD_NAT& max) +Perimeter::Perimeter(const IntTuple& min, const IntTuple& max) : _min(min), _max(max) {} -const MD_NAT& Perimeter::min() const { return _min; } +const IntTuple& Perimeter::min() const { return _min; } -const MD_NAT& Perimeter::max() const { return _max; } +const IntTuple& Perimeter::max() const { return _max; } bool Perimeter::overlap(const Perimeter& other) const { diff --git a/sbg/perimeter.hpp b/sbg/perimeter.hpp index cbf95340..ea03edd0 100755 --- a/sbg/perimeter.hpp +++ b/sbg/perimeter.hpp @@ -28,7 +28,7 @@ #ifndef SBGRAPH_SBG_PERIMETER_HPP_ #define SBGRAPH_SBG_PERIMETER_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" namespace SBG { @@ -36,16 +36,16 @@ namespace LIB { class Perimeter { public: - Perimeter(const MD_NAT& min, const MD_NAT& max); + Perimeter(const IntTuple& min, const IntTuple& max); - const MD_NAT& min() const; - const MD_NAT& max() const; + const IntTuple& min() const; + const IntTuple& max() const; bool overlap(const Perimeter& other) const; private: - MD_NAT _min; - MD_NAT _max; + IntTuple _min; + IntTuple _max; }; } // namespace LIB diff --git a/sbg/rational.cpp b/sbg/rational.cpp index 40a8b87b..a4b5d1eb 100755 --- a/sbg/rational.cpp +++ b/sbg/rational.cpp @@ -27,13 +27,13 @@ namespace LIB { // Constructors/Destructors ---------------------------------------------------- -RATIONAL::RATIONAL() : _value() {} +Rational::Rational() : _value() {} -RATIONAL::RATIONAL(INT n) : _value(RATIONAL::RATIONALT{n, 1}) {} +Rational::Rational(Int n) : _value(Rational::RationalT{n, 1}) {} -RATIONAL::RATIONAL(const RATIONAL::RATIONALT& value) : _value(value) {} +Rational::Rational(const Rational::RationalT& value) : _value(value) {} -RATIONAL::RATIONAL(INT n, INT d) : _value() +Rational::Rational(Int n, Int d) : _value() { boost::rational v{n, d}; _value = v; @@ -41,80 +41,72 @@ RATIONAL::RATIONAL(INT n, INT d) : _value() // Getters --------------------------------------------------------------------- -const RATIONAL::RATIONALT& RATIONAL::value() const { return _value; } +const Rational::RationalT& Rational::value() const { return _value; } -INT RATIONAL::numerator() const { return _value.numerator(); } +Int Rational::numerator() const { return _value.numerator(); } -INT RATIONAL::denominator() const { return _value.denominator(); } +Int Rational::denominator() const { return _value.denominator(); } // Operators ------------------------------------------------------------------- -bool RATIONAL::operator==(const RATIONAL& r) const +bool Rational::operator==(const Rational& r) const { return _value == r._value; } -bool RATIONAL::operator!=(const RATIONAL& r) const +bool Rational::operator!=(const Rational& r) const { return _value != r._value; } -bool RATIONAL::operator<(const RATIONAL& r) const +bool Rational::operator<(const Rational& r) const { return _value < r._value; } -bool RATIONAL::operator>(const RATIONAL& r) const +bool Rational::operator>(const Rational& r) const { return _value > r._value; } -bool RATIONAL::operator>=(const RATIONAL& r) const +bool Rational::operator>=(const Rational& r) const { return _value >= r._value; } -bool RATIONAL::operator==(const INT& other) const +bool Rational::operator==(const Int& other) const { return numerator() == other && denominator() == 1; } -RATIONAL RATIONAL::operator-() const +Rational Rational::operator-() const { - return RATIONAL{-_value}; + return Rational{-_value}; } -RATIONAL RATIONAL::operator+(const RATIONAL& other) const +Rational Rational::operator+(const Rational& other) const { - return RATIONAL{_value + other._value}; + return Rational{_value + other._value}; } -RATIONAL RATIONAL::operator-(const RATIONAL& other) const +Rational Rational::operator-(const Rational& other) const { - return RATIONAL{_value - other._value}; + return Rational{_value - other._value}; } -RATIONAL RATIONAL::operator*(const RATIONAL& other) const +Rational Rational::operator*(const Rational& other) const { - return RATIONAL{_value*other._value}; + return Rational{_value*other._value}; } -RATIONAL RATIONAL::operator/(const RATIONAL& other) const +Rational Rational::operator/(const Rational& other) const { - return RATIONAL{_value/other._value}; + return Rational{_value/other._value}; } -// Extra operations ------------------------------------------------------------ +// Member functions ------------------------------------------------------------ -NAT RATIONAL::toNat() const -{ - if (denominator() == 1 && 0 <= _value) { - return numerator(); - } - return 0; -} - -INT RATIONAL::toInt() const +Int Rational::toInt() const { if (denominator() == 1) { return numerator(); @@ -122,21 +114,21 @@ INT RATIONAL::toInt() const return 0; } -INT RATIONAL::floor() const +Int Rational::floor() const { - return boost::rational_cast(_value); + return boost::rational_cast(_value); } -INT RATIONAL::ceiling() const +Int Rational::ceiling() const { - INT trunc = boost::rational_cast(_value); + Int trunc = boost::rational_cast(_value); return _value == trunc ? trunc : trunc + 1; } -std::ostream& operator<<(std::ostream& out, const RATIONAL& r) +std::ostream& operator<<(std::ostream& out, const Rational& r) { - RATIONAL::RATIONALT rv = r.value(); - INT num = rv.numerator(), den = rv.denominator(); + Rational::RationalT rv = r.value(); + Int num = rv.numerator(), den = rv.denominator(); if (num == 0) { out << "0"; diff --git a/sbg/rational.hpp b/sbg/rational.hpp index 5e0f9314..35f307bd 100755 --- a/sbg/rational.hpp +++ b/sbg/rational.hpp @@ -21,10 +21,10 @@ ******************************************************************************/ -#ifndef SBGRAPH_SBG_RATIONAL_HPP_ -#define SBGRAPH_SBG_RATIONAL_HPP_ +#ifndef SBGRAPH_SBG_Rational_HPP_ +#define SBGRAPH_SBG_Rational_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include @@ -39,74 +39,66 @@ namespace LIB { // Rationals implementation ---------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/** @typedef INT - * - * @brief Integers implementation, used in rationals definition. - */ -using INT = long long int; -constexpr INT INT_Inf = std::numeric_limits::max(); - /** * @brief Used as coefficients and slopes in linear expressions. */ -class RATIONAL { +class Rational { public: - using RATIONALT = boost::rational; + using RationalT = boost::rational; /** * @brief Zero constructor. */ - RATIONAL(); + Rational(); /** * @brief Construct rational r = n/1. */ - RATIONAL(INT n); + Rational(Int n); /** * @brief Copy constructor. */ - RATIONAL(const RATIONALT& value); + Rational(const RationalT& value); /** * @brief Construct rational r = n/d. */ - RATIONAL(INT n, INT d); - - RATIONAL(const RATIONAL& r) = default; - RATIONAL(RATIONAL&& r) = default; - - const RATIONALT& value() const; - INT numerator() const; - INT denominator() const; - - RATIONAL& operator=(const RATIONAL& other) = default; - RATIONAL& operator=(RATIONAL&& other) = default; - bool operator==(const RATIONAL& other) const; - bool operator!=(const RATIONAL& other) const; - bool operator<(const RATIONAL& other) const; - bool operator>(const RATIONAL& other) const; - bool operator>=(const RATIONAL& other) const; - bool operator==(const INT& other) const; - - RATIONAL operator-() const; - RATIONAL operator+(const RATIONAL& other) const; - RATIONAL operator-(const RATIONAL& other) const; - RATIONAL operator*(const RATIONAL& other) const; - RATIONAL operator/(const RATIONAL& other) const; - - NAT toNat() const; - INT toInt() const; - INT floor() const; - INT ceiling() const; + Rational(Int n, Int d); + + Rational(const Rational& r) = default; + Rational(Rational&& r) = default; + + const RationalT& value() const; + Int numerator() const; + Int denominator() const; + + Rational& operator=(const Rational& other) = default; + Rational& operator=(Rational&& other) = default; + bool operator==(const Rational& other) const; + bool operator!=(const Rational& other) const; + bool operator<(const Rational& other) const; + bool operator>(const Rational& other) const; + bool operator>=(const Rational& other) const; + bool operator==(const Int& other) const; + + Rational operator-() const; + Rational operator+(const Rational& other) const; + Rational operator-(const Rational& other) const; + Rational operator*(const Rational& other) const; + Rational operator/(const Rational& other) const; + + Int toInt() const; + Int floor() const; + Int ceiling() const; private: - RATIONALT _value; + RationalT _value; }; -std::ostream& operator<<(std::ostream& out, const RATIONAL& r); +std::ostream& operator<<(std::ostream& out, const Rational& r); } // namespace LIB } // namespace SBG -#endif // SBGRAPH_SBG_RATIONAL_HPP_ +#endif // SBGRAPH_SBG_Rational_HPP_ diff --git a/sbg/sbg.cpp b/sbg/sbg.cpp index ba8d034b..ba19ebb3 100644 --- a/sbg/sbg.cpp +++ b/sbg/sbg.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include "sbg/natural.hpp" #include "sbg/sbg.hpp" +#include "sbg/integer.hpp" #include "util/debug.hpp" #include @@ -66,9 +66,9 @@ void SBG::addSetVertex(const Set& vertices) } else if (!vertices.isEmpty()) { Set set_vertices = _Vmap.image(); std::size_t arity = vertices.arity(); - MD_NAT max = set_vertices.isEmpty() ? MD_NAT{arity, 0} + IntTuple max = set_vertices.isEmpty() ? IntTuple{arity, 0} : set_vertices.maxElem(); - _Vmap.emplace(vertices, max + MD_NAT{arity, 1}); + _Vmap.emplace(vertices, max + IntTuple{arity, 1}); _V = std::move(_V).cup(std::move(vertices)); } } @@ -85,10 +85,11 @@ void SBG::addSetEdge(const PWMap& pw1, const PWMap& pw2) if (!edges.isEmpty()) { Set set_edges = _Emap.image(); std::size_t arity = edges.arity(); - MD_NAT max = set_edges.isEmpty() ? MD_NAT{arity, 0} : set_edges.maxElem(); + IntTuple max = set_edges.isEmpty() ? IntTuple{arity, 0} + : set_edges.maxElem(); _map1 = std::move(_map1).concatenation(pw1); _map2 = std::move(_map2).concatenation(pw2); - _Emap.emplace(edges, max + MD_NAT{arity, 1}); + _Emap.emplace(edges, max + IntTuple{arity, 1}); _E = std::move(_E).cup(std::move(edges)); } } else { diff --git a/sbg/sbg.hpp b/sbg/sbg.hpp index 5a149ae1..caab7504 100644 --- a/sbg/sbg.hpp +++ b/sbg/sbg.hpp @@ -116,7 +116,7 @@ inline void SBG::foreachSetVertex(FuncT&& f) const { Set remaining = _Vmap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } @@ -127,7 +127,7 @@ inline void SBG::foreachSetEdge(FuncT&& f) const { Set remaining = _Emap.image(); while (!remaining.isEmpty()) { - const MD_NAT& x = remaining.minElem(); + const IntTuple& x = remaining.minElem(); f(x); remaining = remaining.difference(Set{x}); } diff --git a/sbg/set.cpp b/sbg/set.cpp index 60ab2924..1f0969b8 100644 --- a/sbg/set.cpp +++ b/sbg/set.cpp @@ -59,7 +59,7 @@ Set::Set() : _impl() } } -Set::Set(const MD_NAT& x) : _impl() +Set::Set(const IntTuple& x) : _impl() { SetKind kind = SET_IMPL.kind(); switch (kind) { @@ -85,7 +85,7 @@ Set::Set(const MD_NAT& x) : _impl() } } -Set::Set(MD_NAT&& x) : _impl() +Set::Set(IntTuple&& x) : _impl() { SetKind kind = SET_IMPL.kind(); switch (kind) { @@ -111,7 +111,7 @@ Set::Set(MD_NAT&& x) : _impl() } } -Set::Set(const NAT lo, const NAT step, const NAT hi) : _impl() +Set::Set(const Int lo, const Int step, const Int hi) : _impl() { SetKind kind = SET_IMPL.kind(); switch (kind) { @@ -203,12 +203,12 @@ bool Set::isEmpty() const return std::visit([](const auto& a) { return a.isEmpty(); }, _impl); } -MD_NAT Set::minElem() const +IntTuple Set::minElem() const { return std::visit([](const auto& a) { return a.minElem(); }, _impl); } -MD_NAT Set::maxElem() const +IntTuple Set::maxElem() const { return std::visit([](const auto& a) { return a.maxElem(); }, _impl); } @@ -337,10 +337,10 @@ Set Set::disjointCup(Set&& other) && , std::move(_impl), std::move(other._impl)); } -Set Set::offset(const MD_NAT& off) const +Set Set::translate(const IntTuple& t) const { return std::visit( - [&off](const auto& a) -> Set { return Set{a.offset(off)}; } + [&t](const auto& a) -> Set { return Set{a.translate(t)}; } , _impl); } diff --git a/sbg/set.hpp b/sbg/set.hpp index 2887c8d6..7ef05be5 100644 --- a/sbg/set.hpp +++ b/sbg/set.hpp @@ -2,13 +2,13 @@ @brief SBG Set - A SBG Set is a structure that represents sets of multi-dimensional naturals + A SBG Set is a structure that represents sets of multi-dimensional integers (all with the same number of dimensions). Currently three compact implementations are supported: - UnorderedSet that keeps no order, but supports multi-dimensional values. - OrderedSet that supports multi-dimensional values while also keeping an internal order that enhances performance. - - OrdUnidimDenseSet that can represent sets of one dimensional naturals and + - OrdUnidimDenseSet that can represent sets of one dimensional integers and that is optimized by keeping an ordered collection of MDIs.
@@ -37,7 +37,7 @@ #include "sbg/fixed_points.hpp" #include "sbg/interval.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/ord_set.hpp" #include "sbg/ord_unidim_dense_set.hpp" #include "sbg/set.hpp" @@ -75,9 +75,9 @@ class SetAccessKey; class Set { public: Set(); - Set(const MD_NAT& x); - Set(MD_NAT&& x); - Set(const NAT lo, const NAT st, const NAT hi); + Set(const IntTuple& x); + Set(IntTuple&& x); + Set(const Int lo, const Int st, const Int hi); Set(const FixedPointsInfo& info); bool operator==(const Set& other) const; @@ -88,8 +88,8 @@ class Set { unsigned int cardinal() const; bool isEmpty() const; - MD_NAT minElem() const; - MD_NAT maxElem() const; + IntTuple minElem() const; + IntTuple maxElem() const; Set intersection(const Set& other) const &; Set cup(const Set& other) const &; Set cup(const Set& other) &&; @@ -106,7 +106,7 @@ class Set { Set disjointCup(const Set& other) &&; Set disjointCup(Set&& other) const &; Set disjointCup(Set&& other) &&; - Set offset(const MD_NAT& off) const; + Set translate(const IntTuple& t) const; Perimeter perimeter() const; void compact(); rapidjson::Value toJSON(rapidjson::Document::AllocatorType& alloc) const; diff --git a/sbg/set_detail.cpp b/sbg/set_detail.cpp index 62e84c00..bdf0146a 100755 --- a/sbg/set_detail.cpp +++ b/sbg/set_detail.cpp @@ -35,16 +35,16 @@ SetImpl SetAccessKey::impl(Set s) const { return s._impl; } Set SetAccessKey::createSet(SetImpl s_impl) const { return Set{s_impl}; } template -std::vector SetAccessKey::flatten(const SetImplT& s) const +std::vector SetAccessKey::flatten(const SetImplT& s) const { - std::vector result; + std::vector result; auto pieces = s._pieces; result.reserve(pieces.size()); std::size_t arity = s.arity(); for (const MultiDimInter& mdi : pieces) { - MD_NAT min_elem = mdi.minElem(); - MD_NAT x = min_elem; + IntTuple min_elem = mdi.minElem(); + IntTuple x = min_elem; unsigned int mdi_sz = mdi.cardinal(); unsigned int div = mdi_sz; for (unsigned int j = 0; j < mdi_sz; ++j) { @@ -61,12 +61,12 @@ std::vector SetAccessKey::flatten(const SetImplT& s) const return result; } -std::vector SetAccessKey::flatten(const OrdUnidimDenseSet& s) const +std::vector SetAccessKey::flatten(const OrdUnidimDenseSet& s) const { - std::vector result; + std::vector result; for (const Interval& i : s._pieces) { - for (NAT j = i.begin(); j <= i.end(); j += i.step()) { + for (Int j = i.begin(); j <= i.end(); j += i.step()) { result.emplace_back(j); } } @@ -74,7 +74,7 @@ std::vector SetAccessKey::flatten(const OrdUnidimDenseSet& s) const return result; } -std::vector SetAccessKey::flatten(const Set& s) const +std::vector SetAccessKey::flatten(const Set& s) const { auto flatten_evaluator = Util::Overload { [&](const UnorderedSet& a) @@ -89,7 +89,7 @@ std::vector SetAccessKey::flatten(const Set& s) const { return flatten(a); }, - [&](const auto& a) { return std::vector{}; } + [&](const auto& a) { return std::vector{}; } }; return std::visit(flatten_evaluator, s._impl); } diff --git a/sbg/set_detail.hpp b/sbg/set_detail.hpp index e9825466..f7b10702 100755 --- a/sbg/set_detail.hpp +++ b/sbg/set_detail.hpp @@ -27,9 +27,10 @@ #ifndef SBGRAPH_SBG_SET_DETAIL_HPP_ #define SBGRAPH_SBG_SET_DETAIL_HPP_ -#include "sbg/set.hpp" +#include "sbg/integer.hpp" #include "sbg/ord_set.hpp" #include "sbg/ord_unidim_dense_set.hpp" +#include "sbg/set.hpp" #include @@ -39,13 +40,13 @@ namespace LIB { namespace detail { -using MaybeMD_NAT = std::optional; +using MaybeIntTuple = std::optional; class SetAccessKey { public: SetImpl impl(Set s) const; Set createSet(SetImpl s_impl) const; - std::vector flatten(const Set& s) const; + std::vector flatten(const Set& s) const; OrderedSet::OrdMDICollection pieces(OrderedSet s) const; OrdUnidimDenseSet::OrdIntervalCollection pieces(OrdUnidimDenseSet s) const; @@ -54,8 +55,8 @@ class SetAccessKey { SetAccessKey() = default; template - std::vector flatten(const SetImplT& s) const; - std::vector flatten(const OrdUnidimDenseSet& s) const; + std::vector flatten(const SetImplT& s) const; + std::vector flatten(const OrdUnidimDenseSet& s) const; friend class SetAccess; }; diff --git a/sbg/unord_set.cpp b/sbg/unord_set.cpp index 2ee04511..0c29342f 100644 --- a/sbg/unord_set.cpp +++ b/sbg/unord_set.cpp @@ -46,7 +46,7 @@ bool overlap(const UnorderedSet& lhs, const UnorderedSet& rhs) UnorderedSet::UnorderedSet() : _pieces() {} -UnorderedSet::UnorderedSet(const MD_NAT& x) : _pieces() +UnorderedSet::UnorderedSet(const IntTuple& x) : _pieces() { _pieces.emplace_back(MultiDimInter{x}); } @@ -75,13 +75,12 @@ UnorderedSet::UnorderedSet(const FixedPointsInfo& info) : _pieces() { if (info) { std::vector solutions = info.value(); - Interval universe_one_dim{0, 1, Inf}; MultiDimInter result_mdi; for (const Solution& jth_solution : solutions) { if (jth_solution.kind() == SolutionKind::kFixed) { result_mdi.pushBack(jth_solution.value().value()); } else if (jth_solution.kind() == SolutionKind::kFree) { - result_mdi.pushBack(universe_one_dim); + result_mdi.pushBack(kOneDimUniverse); } } pushBack(result_mdi); @@ -166,9 +165,9 @@ unsigned int UnorderedSet::cardinal() const bool UnorderedSet::isEmpty() const { return _pieces.empty(); } -MD_NAT UnorderedSet::minElem() const +IntTuple UnorderedSet::minElem() const { - MD_NAT result = _pieces.begin()->minElem(); + IntTuple result = _pieces.begin()->minElem(); for (const MultiDimInter& mdi : _pieces) { result = std::min(result, mdi.minElem()); @@ -177,9 +176,9 @@ MD_NAT UnorderedSet::minElem() const return result; } -MD_NAT UnorderedSet::maxElem() const +IntTuple UnorderedSet::maxElem() const { - MD_NAT result = _pieces.begin()->maxElem(); + IntTuple result = _pieces.begin()->maxElem(); for (const MultiDimInter& mdi : _pieces) { result = std::max(result, mdi.maxElem()); @@ -262,23 +261,22 @@ UnorderedSet UnorderedSet::complementAtom() const } MultiDimInter during_mdi = dense_mdi; - Interval universe_one_dim{0, 1, Inf}; - MultiDimInter univ{mdi.arity(), universe_one_dim}; + MultiDimInter univ{mdi.arity(), kOneDimUniverse}; std::size_t dim = 0; for (const Interval& i : mdi) { // Before interval - if (i.begin() != 0) { + if (i.begin() != kNegInf) { Interval i_res{0, 1, i.begin() - 1}; if (!i_res.isEmpty()) { univ[dim] = i_res; result.push_back(univ); - univ[dim] = universe_one_dim; + univ[dim] = kOneDimUniverse; } } // "During" interval - if (i.begin() < Inf && i.step() > 1) { + if (i.begin() < kPosInf && i.step() > 1) { for (unsigned int j = 0; j < i.step() - 1; ++j) { Interval i_res{i.begin() + j + 1, i.step(), i.end()}; if (!i_res.isEmpty()) { @@ -289,12 +287,12 @@ UnorderedSet UnorderedSet::complementAtom() const } // After interval - if (i.end() < Inf) { - Interval i_res{i.end() + 1, 1, Inf}; + if (i.end() < kPosInf) { + Interval i_res{i.end() + 1, 1, kPosInf}; if (!i_res.isEmpty()) { univ[dim] = i_res; result.push_back(univ); - univ[dim] = universe_one_dim; + univ[dim] = kOneDimUniverse; } } univ[dim] = dense_mdi[dim]; @@ -402,12 +400,12 @@ UnorderedSet UnorderedSet::disjointCup(UnorderedSet&& other) && return UnorderedSet{std::move(result)}; } -UnorderedSet UnorderedSet::offset(const MD_NAT& off) const +UnorderedSet UnorderedSet::translate(const IntTuple& t) const { UnorderedSet result; for (const MultiDimInter& mdi : _pieces) { - result.pushBack(mdi.offset(off)); + result.pushBack(mdi.translate(t)); } return result; @@ -415,16 +413,16 @@ UnorderedSet UnorderedSet::offset(const MD_NAT& off) const Perimeter UnorderedSet::perimeter() const { - MD_NAT min; - MD_NAT max; + IntTuple min; + IntTuple max; if (!isEmpty()) { std::size_t arity = this->arity(); - min = MD_NAT{arity, Inf}; - max = MD_NAT{arity, 0}; + min = IntTuple{arity, kPosInf}; + max = IntTuple{arity, kNegInf}; for (const MultiDimInter& mdi : _pieces) { - MD_NAT candidate_min = mdi.minElem(); - MD_NAT candidate_max = mdi.maxElem(); + IntTuple candidate_min = mdi.minElem(); + IntTuple candidate_max = mdi.maxElem(); for (size_t i = 0; i < arity; ++i) { min[i] = std::min(min[i], candidate_min[i]); max[i] = std::max(max[i], candidate_max[i]); diff --git a/sbg/unord_set.hpp b/sbg/unord_set.hpp index 6315b6b1..1e2cf4d3 100644 --- a/sbg/unord_set.hpp +++ b/sbg/unord_set.hpp @@ -24,11 +24,10 @@ #ifndef SBGRAPH_SBG_UNORD_SET_HPP_ #define SBGRAPH_SBG_UNORD_SET_HPP_ -#include "sbg/expression.hpp" #include "sbg/fixed_points.hpp" +#include "sbg/integer.hpp" #include "sbg/interval.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" #include "sbg/perimeter.hpp" #include "rapidjson/document.h" @@ -53,7 +52,7 @@ class UnorderedSet { using ConstIt = MDIUnordCollection::const_iterator; UnorderedSet(); - UnorderedSet(const MD_NAT& x); + UnorderedSet(const IntTuple& x); UnorderedSet(const detail::Interval& i); UnorderedSet(const detail::MultiDimInter& mdi); UnorderedSet(const MDIUnordCollection& pieces); @@ -73,8 +72,8 @@ class UnorderedSet { unsigned int cardinal() const; bool isEmpty() const; - MD_NAT minElem() const; - MD_NAT maxElem() const; + IntTuple minElem() const; + IntTuple maxElem() const; UnorderedSet intersection(const UnorderedSet& other) const; UnorderedSet cup(const UnorderedSet& other) const &; UnorderedSet cup(UnorderedSet&& other) const &; @@ -91,7 +90,7 @@ class UnorderedSet { UnorderedSet disjointCup(const UnorderedSet& other) &&; UnorderedSet disjointCup(UnorderedSet&& other) const &; UnorderedSet disjointCup(UnorderedSet&& other) &&; - UnorderedSet offset(const MD_NAT& off) const; + UnorderedSet translate(const IntTuple& off) const; Perimeter perimeter() const; void compact(); diff --git a/test/eval/gt_data/pw_map2.log b/test/eval/gt_data/pw_map2.log index f0ae1bae..85deb408 100644 --- a/test/eval/gt_data/pw_map2.log +++ b/test/eval/gt_data/pw_map2.log @@ -2,7 +2,7 @@ >>>>>>>>> Parser result <<<<<<<<<<< ----------------------------------- -nmbr_dims = 2; +arity = 2; N = -1; <<>>; diff --git a/test/eval/gt_data/pw_map3.log b/test/eval/gt_data/pw_map3.log index a1d1cdda..405fb92a 100644 --- a/test/eval/gt_data/pw_map3.log +++ b/test/eval/gt_data/pw_map3.log @@ -2,7 +2,7 @@ >>>>>>>>> Parser result <<<<<<<<<<< ----------------------------------- -nmbr_dims = 3; +arity = 3; <<>>; combine(<<{[1:1:10] x [1:1:10] x [1:1:10], [1:1:10] x [20:3:30] x [20:3:30]} ↦ 1*x+0|1*x+0|1*x+0, {[1:1:10] x [20:3:30] x [35:5:50], [35:5:50] x [35:5:50] x [20:3:30]} ↦ 3*x+0|3*x+0|1*x+1>>, <<{[1:1:20] x [1:1:20] x [1:1:20]} ↦ 1*x+1|1*x+0|1*x+0>>); diff --git a/test/eval/gt_data/set.log b/test/eval/gt_data/set.log index 4807f449..b31ea7cc 100644 --- a/test/eval/gt_data/set.log +++ b/test/eval/gt_data/set.log @@ -114,7 +114,7 @@ s2/\s1 --> {[200:300], [425:430], [550:1000], [1:100], [150:199], [450:549]} -{[1:1:100]} - --> {[0:0], [101:18446744073709551615]} + --> {[0:0], [101:9223372036854775807]} {}=={} --> true diff --git a/test/matching_TestRL1.test b/test/matching_TestRL1.test index 008a0028..d8278a95 100644 --- a/test/matching_TestRL1.test +++ b/test/matching_TestRL1.test @@ -125,5 +125,5 @@ match( |, {[E12+1:1:E13]} -> |0*x+13|>> X: F Y: U - , 4 + , 1 ); diff --git a/test/performance/boost/scalar_graph.hpp b/test/performance/boost/scalar_graph.hpp index 7f979035..92c38140 100644 --- a/test/performance/boost/scalar_graph.hpp +++ b/test/performance/boost/scalar_graph.hpp @@ -26,7 +26,7 @@ #ifndef SBGRAPH_TEST_PERFORMANCE_BOOST_SCALAR_GRAPH_HPP_ #define SBGRAPH_TEST_PERFORMANCE_BOOST_SCALAR_GRAPH_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include @@ -36,9 +36,9 @@ namespace perf { namespace detail { -using Vertex = SBG::LIB::NAT; +using Vertex = SBG::LIB::Int; using VertexVector = std::vector; -using Edge = std::pair; +using Edge = std::pair; using EdgeVector = std::vector; using Graph = boost::adjacency_list&& partition) { Graph graph(E.begin(), E.end(), number_vertices); @@ -72,10 +72,10 @@ void ScalarGraphBuilder::translateVertices() _partition.reserve(V.cardinal()); Set X = _bsbg.X(); - NAT count = 0; + Int count = 0; SetAccessKey key = SetAccess::key(); - std::vector vertices = key.flatten(V); - for (const MD_NAT& v : vertices) { + std::vector vertices = key.flatten(V); + for (const IntTuple& v : vertices) { _vertex_map[v] = count; _partition.emplace_back( SBG::LIB::Set{v}.intersection(X).isEmpty()); @@ -95,8 +95,8 @@ EdgeVector ScalarGraphBuilder::getEdgeList() const PWMap& map1 = _bsbg.map1(); const PWMap& map2 = _bsbg.map2(); SetAccessKey key = SetAccess::key(); - std::vector edges = key.flatten(E); - for (const MD_NAT& e : edges) { + std::vector edges = key.flatten(E); + for (const IntTuple& e : edges) { // Get endings of edge Set domain = SBG::LIB::Set{e}; Vertex v1 = _vertex_map[map1.image(domain).minElem()]; diff --git a/test/performance/boost/scalar_graph_builder.hpp b/test/performance/boost/scalar_graph_builder.hpp index 22ac3ef0..6966ce79 100644 --- a/test/performance/boost/scalar_graph_builder.hpp +++ b/test/performance/boost/scalar_graph_builder.hpp @@ -29,7 +29,7 @@ #define SBGRAPH_TEST_PERFORMANCE_BOOST_SCALAR_GRAPH_BUILDER_HPP_ #include "sbg/bipartite_sbg.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "test/performance/boost/scalar_graph.hpp" #include "util/logger.hpp" @@ -47,14 +47,14 @@ class ScalarGraphBuilder { ScalarGraphBuilder(SBG::LIB::BipartiteSBG bsbg); BipartiteGraph build(); - BipartiteGraph build(SBG::LIB::NAT number_vertices, EdgeVector& edges + BipartiteGraph build(SBG::LIB::Int number_vertices, EdgeVector& edges , std::vector&& partition); void translateVertices(); EdgeVector getEdgeList(); private: const SBG::LIB::BipartiteSBG _bsbg; ///< Input bipartite SBG to convert - std::map _vertex_map; + std::map _vertex_map; ///< Map from SBG vertex identifier to Graph element std::vector _partition; }; diff --git a/test/performance/boost/scc_graph_builder.cpp b/test/performance/boost/scc_graph_builder.cpp index bef93f9d..ebd66bed 100644 --- a/test/performance/boost/scc_graph_builder.cpp +++ b/test/performance/boost/scc_graph_builder.cpp @@ -51,18 +51,18 @@ SCCGraphBuilder::SCCGraphBuilder(BipartiteGraph&& bgraph DirectedGraph SCCGraphBuilder::build() { - SBG::LIB::NAT number_vertices = translateVertices(); + SBG::LIB::Int number_vertices = translateVertices(); EdgeVector edges = getEdgeList(); return build(number_vertices, edges); } -DirectedGraph SCCGraphBuilder::build(SBG::LIB::NAT number_vertices +DirectedGraph SCCGraphBuilder::build(SBG::LIB::Int number_vertices , EdgeVector& E) { return DirectedGraph(E.begin(), E.end(), number_vertices); } -SBG::LIB::NAT SCCGraphBuilder::translateVertices() +SBG::LIB::Int SCCGraphBuilder::translateVertices() { _vertex_map.reserve(boost::num_edges(_bgraph.graph())); diff --git a/test/performance/boost/scc_graph_builder.hpp b/test/performance/boost/scc_graph_builder.hpp index 9756674c..29f770fb 100644 --- a/test/performance/boost/scc_graph_builder.hpp +++ b/test/performance/boost/scc_graph_builder.hpp @@ -28,7 +28,7 @@ #ifndef SBGRAPH_TEST_PERFORMANCE_BOOST_SCC_GRAPH_BUILDER_HPP_ #define SBGRAPH_TEST_PERFORMANCE_BOOST_SCC_GRAPH_BUILDER_HPP_ -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "test/performance/boost/scalar_graph.hpp" #include @@ -65,8 +65,8 @@ class SCCGraphBuilder { SCCGraphBuilder(BipartiteGraph&& g, VertexVector&& matching); DirectedGraph build(); - DirectedGraph build(SBG::LIB::NAT number_vertices, EdgeVector& edges); - SBG::LIB::NAT translateVertices(); + DirectedGraph build(SBG::LIB::Int number_vertices, EdgeVector& edges); + SBG::LIB::Int translateVertices(); EdgeVector getEdgeList(); private: diff --git a/test/performance/set_bm.cpp b/test/performance/set_bm.cpp index 565f7116..6f01cba4 100644 --- a/test/performance/set_bm.cpp +++ b/test/performance/set_bm.cpp @@ -19,7 +19,6 @@ #include "sbg/interval.hpp" #include "sbg/multidim_inter.hpp" -#include "sbg/natural.hpp" #include "sbg/set.hpp" #include "test/performance/utils.hpp" @@ -34,7 +33,6 @@ namespace perf { namespace detail { -using SBG::LIB::NAT; using SBG::LIB::detail::Interval; using SBG::LIB::Set; diff --git a/test/performance/utils.cpp b/test/performance/utils.cpp index 4c114028..eb11bf09 100644 --- a/test/performance/utils.cpp +++ b/test/performance/utils.cpp @@ -24,8 +24,8 @@ #include "eval/pretty_print.hpp" #include "sbg/bipartite_sbg.hpp" #include "sbg/expression.hpp" +#include "sbg/integer.hpp" #include "sbg/interval.hpp" -#include "sbg/natural.hpp" #include "sbg/pw_map.hpp" #include "sbg/rational.hpp" #include "sbg/set.hpp" @@ -43,8 +43,8 @@ namespace perf { namespace detail { -using SBG::LIB::NAT; -using SBG::LIB::RATIONAL; +using SBG::LIB::Int; +using SBG::LIB::Rational; using SBG::LIB::detail::Interval; using SBG::LIB::Set; using SBG::LIB::Expression; @@ -136,9 +136,9 @@ MatchData calculateMatching(std::string filename, int N, int copies) // Set Construction ------------------------------------------------------------ //////////////////////////////////////////////////////////////////////////////// -std::pair nonDisjointPieces(NAT set_sz) +std::pair nonDisjointPieces(Int set_sz) { - NAT inter_sz = 100; + Int inter_sz = 100; Set s1; Set s2; @@ -147,7 +147,7 @@ std::pair nonDisjointPieces(NAT set_sz) Set jth_s1{i1.begin(), i1.step(), i1.end()}; s1 = s1.disjointCup(jth_s1); - NAT off = inter_sz/2; + Int off = inter_sz/2; Interval i2{off + (h*inter_sz), 1, off + (h + 1)*inter_sz - 1}; Set jth_s2{i2.begin(), i2.step(), i2.end()}; s2 = s2.disjointCup(jth_s2); @@ -160,13 +160,13 @@ std::pair nonDisjointPieces(NAT set_sz) return std::make_pair(std::move(s1), std::move(s2)); } -std::pair interlacedPieces(NAT set_sz) +std::pair interlacedPieces(Int set_sz) { - NAT inter_sz = 100; + Int inter_sz = 100; Set s1; Set s2; - for (SBG::LIB::NAT j = 0; j < set_sz; j += 2) { + for (SBG::LIB::Int j = 0; j < set_sz; j += 2) { Set jth_s1{j*inter_sz, 1, (j + 1)*inter_sz - 1}; s1 = std::move(s1.disjointCup(jth_s1)); Set jth_s2{(j + 1)*inter_sz, 1, (j + 2)*inter_sz - 1}; @@ -180,21 +180,21 @@ std::pair interlacedPieces(NAT set_sz) // PWMap Construction ---------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -PWMap denseDom(NAT map_sz) +PWMap denseDom(Int map_sz) { - NAT inter_sz = 100; - NAT set_sz = 10; + Int inter_sz = 100; + Int set_sz = 10; PWMap pw; for (unsigned int j = 0; j < map_sz; ++j) { Set domain; - NAT offset = j*set_sz*inter_sz; + Int offset = j*set_sz*inter_sz; for (unsigned int h = 0; h < set_sz; ++h) { Interval i{offset + (h*inter_sz), 1, offset + (h + 1)*inter_sz - 1}; Set jth_domain{i.begin(), i.step(), i.end()}; domain = std::move(domain).disjointCup(std::move(jth_domain)); } - Expression id{RATIONAL{1}, RATIONAL{0}}; + Expression id{Rational{1}, Rational{0}}; pw.emplace(domain, id); } @@ -202,10 +202,10 @@ PWMap denseDom(NAT map_sz) return pw; } -std::pair minAdjMaps(NAT map_sz) +std::pair minAdjMaps(Int map_sz) { - NAT inter_sz = 100; - NAT set_sz = 10; + Int inter_sz = 100; + Int set_sz = 10; Set second_dim{0, 1, inter_sz - 1}; PWMap pw1; @@ -213,20 +213,20 @@ std::pair minAdjMaps(NAT map_sz) for (unsigned int j = 0; j < map_sz; ++j) { Set domain1; Set domain2; - NAT offset = j*set_sz*inter_sz; + Int offset = j*set_sz*inter_sz; for (unsigned int h = 0; h < set_sz; ++h) { Interval i1{offset + (h*inter_sz), 1, offset + (h + 1)*inter_sz - 1}; Set jth_domain1{i1.begin(), i1.step(), i1.end()}; domain1 = std::move(domain1).disjointCup(std::move(jth_domain1)); - NAT offset2 = offset + inter_sz/2; + Int offset2 = offset + inter_sz/2; Interval i2{offset2 + (h*inter_sz), 1, offset2 + (h + 1)*inter_sz - 1}; Set jth_domain2{i2.begin(), i2.step(), i2.end()}; domain2 = std::move(domain2).disjointCup(std::move(jth_domain2)); } - Expression id{RATIONAL{1}, RATIONAL{0}}; - Expression minus_one{RATIONAL{1}, RATIONAL{-1, 1}}; + Expression id{Rational{1}, Rational{0}}; + Expression minus_one{Rational{1}, Rational{-1, 1}}; pw1.emplace(domain1, id); pw2.emplace(domain2, minus_one); @@ -235,10 +235,10 @@ std::pair minAdjMaps(NAT map_sz) return {pw1, pw2}; } -std::pair interlacedMaps(NAT map_sz) +std::pair interlacedMaps(Int map_sz) { - NAT inter_sz = 100; - NAT set_sz = 10; + Int inter_sz = 100; + Int set_sz = 10; Set second_dim{0, 1, inter_sz - 1}; PWMap pw1; @@ -246,13 +246,13 @@ std::pair interlacedMaps(NAT map_sz) for (unsigned int j = 0; j < map_sz; ++j) { Set domain1; Set domain2; - NAT offset = j*set_sz*inter_sz; + Int offset = j*set_sz*inter_sz; for (unsigned int h = 0; h < set_sz; h += 2) { Interval i1{offset + (h*inter_sz), 1, offset + (h + 1)*inter_sz - 1}; Set jth_domain1{i1.begin(), i1.step(), i1.end()}; domain1 = std::move(domain1).disjointCup(std::move(jth_domain1)); - NAT offset2 = offset + inter_sz; + Int offset2 = offset + inter_sz; Interval i2{offset2 + (h*inter_sz), 1, offset2 + (h + 1)*inter_sz - 1}; Set jth_domain2{i2.begin(), i2.step(), i2.end()}; domain2 = std::move(domain2).disjointCup(std::move(jth_domain2)); @@ -269,10 +269,10 @@ std::pair interlacedMaps(NAT map_sz) return {pw1, pw2}; } -std::pair nonDisjointMaps(NAT map_sz) +std::pair nonDisjointMaps(Int map_sz) { - NAT inter_sz = 100; - NAT set_sz = 10; + Int inter_sz = 100; + Int set_sz = 10; Set second_dim{0, 1, inter_sz - 1}; PWMap pw1; @@ -280,13 +280,13 @@ std::pair nonDisjointMaps(NAT map_sz) for (unsigned int j = 0; j < map_sz; ++j) { Set domain1; Set domain2; - NAT offset = j*set_sz*inter_sz; + Int offset = j*set_sz*inter_sz; for (unsigned int h = 0; h < set_sz; ++h) { Interval i1{offset + (h*inter_sz), 1, offset + (h + 1)*inter_sz - 1}; Set jth_domain1{i1.begin(), i1.step(), i1.end()}; domain1 = std::move(domain1).disjointCup(std::move(jth_domain1)); - NAT offset2 = offset + inter_sz/2; + Int offset2 = offset + inter_sz/2; Interval i2{offset2 + (h*inter_sz), 1, offset2 + (h + 1)*inter_sz - 1}; Set jth_domain2{i2.begin(), i2.step(), i2.end()}; domain2 = std::move(domain2).disjointCup(std::move(jth_domain2)); @@ -303,16 +303,16 @@ std::pair nonDisjointMaps(NAT map_sz) return {pw1, pw2}; } -PWMap reducibleMaps(NAT map_sz) +PWMap reducibleMaps(Int map_sz) { - NAT inter_sz = 100; - NAT set_sz = 10; + Int inter_sz = 100; + Int set_sz = 10; Set second_dim{0, 1, inter_sz - 1}; PWMap pw; for (unsigned int j = 0; j < map_sz; ++j) { Set domain; - NAT offset = j*set_sz*inter_sz; + Int offset = j*set_sz*inter_sz; for (unsigned int h = 0; h < set_sz; ++h) { Interval i{offset + (h*inter_sz), 1, offset + (h + 1)*inter_sz - 1}; Set jth_domain{i.begin(), i.step(), i.end()}; @@ -320,8 +320,8 @@ PWMap reducibleMaps(NAT map_sz) } domain = domain.cartesianProduct(second_dim); - Expression plus_one{RATIONAL{1}, RATIONAL{1}}; - Expression id{RATIONAL{1}, RATIONAL{0}}; + Expression plus_one{Rational{1}, Rational{1}}; + Expression id{Rational{1}, Rational{0}}; Expression expr = plus_one.cartesianProduct(id); pw.emplace(domain, expr); diff --git a/test/performance/utils.hpp b/test/performance/utils.hpp index ec31e225..8cc09f8a 100644 --- a/test/performance/utils.hpp +++ b/test/performance/utils.hpp @@ -28,7 +28,7 @@ #include "algorithms/matching/match_data.hpp" #include "sbg/bipartite_sbg.hpp" -#include "sbg/natural.hpp" +#include "sbg/integer.hpp" #include "sbg/pw_map.hpp" #include "sbg/set.hpp" @@ -40,7 +40,7 @@ namespace perf { namespace detail { -using SBG::LIB::NAT; +using SBG::LIB::Int; using SBG::LIB::Set; using SBG::LIB::PWMap; using SBG::LIB::BipartiteSBG; @@ -89,7 +89,7 @@ MatchData calculateMatching(std::string filename, int N, int copies); * {[50:149]x[0:99], [150:249]x[0:99], ..., [N-49:N+50]x[0:99]} * where N = set_sz*100-1. */ -std::pair nonDisjointPieces(NAT set_sz); +std::pair nonDisjointPieces(Int set_sz); /* * @brief Creates two dense sets, where the first one is: @@ -98,7 +98,7 @@ std::pair nonDisjointPieces(NAT set_sz); * {[100:199], [300:399], ..., [N-99:N]} * where N = set_sz*100-1. */ -std::pair interlacedPieces(NAT set_sz); +std::pair interlacedPieces(Int set_sz); //////////////////////////////////////////////////////////////////////////////// // PWMap Construction ---------------------------------------------------------- @@ -111,7 +111,7 @@ std::pair interlacedPieces(NAT set_sz); * , ..., {[N-999:N-900], ..., [N-99:N]} -> |x|>>. * where N = map_sz*1e3-1. */ -PWMap denseDom(NAT map_sz); +PWMap denseDom(Int map_sz); /* * @brief Creates two PWs with a dense domain, where the first one is: @@ -124,7 +124,7 @@ PWMap denseDom(NAT map_sz); * , ..., {[N-949:N-850], ..., [N-49:N+50]} -> |x-1|>> * where N = map_sz*1e3-1. */ -std::pair minAdjMaps(NAT map_sz); +std::pair minAdjMaps(Int map_sz); /* * @brief Creates two PWs with a dense domain, where the first one is: @@ -137,7 +137,7 @@ std::pair minAdjMaps(NAT map_sz); * , ..., {[N-899:N-800]x[0:99], ..., [N-99:N]x[0:99]} -> |x|x|>> * where N = map_sz*1e3-1. */ -std::pair interlacedMaps(NAT map_sz); +std::pair interlacedMaps(Int map_sz); /* * @brief Creates two PWs with a dense domain, where the first one is: @@ -150,12 +150,12 @@ std::pair interlacedMaps(NAT map_sz); * , ..., {[N-949:N-850]x[0:99], ..., [N-49:N+50]x[0:99]} -> |x|x|>> * where N = map_sz*1e3-1. */ -std::pair nonDisjointMaps(NAT map_sz); +std::pair nonDisjointMaps(Int map_sz); /** * @brief TODO */ -PWMap reducibleMaps(NAT map_sz); +PWMap reducibleMaps(Int map_sz); } // namespace detail