Skip to content

Commit ad68c52

Browse files
committed
Major refactoring and fixes to yield same results as master branch
1 parent 7f7a326 commit ad68c52

File tree

10 files changed

+413
-349
lines changed

10 files changed

+413
-349
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ project(mrio_disaggregate)
1212
add_executable(mrio_disaggregate src/main.cpp)
1313

1414
target_include_directories(mrio_disaggregate PRIVATE include)
15-
target_compile_options(mrio_disaggregate PRIVATE "-std=c++11")
15+
target_compile_options(mrio_disaggregate PUBLIC -std=c++17)
16+
set_property(TARGET mrio_disaggregate PROPERTY CXX_STANDARD 17)
1617

1718
set_advanced_cpp_warnings(mrio_disaggregate)
1819
set_build_type_specifics(mrio_disaggregate)
@@ -26,7 +27,7 @@ target_link_libraries(mrio_disaggregate PRIVATE libmrio)
2627
include(lib/settingsnode/settingsnode.cmake)
2728
include_settingsnode(mrio_disaggregate)
2829

29-
include_yaml_cpp(mrio_disaggregate ON "yaml-cpp-0.6.2")
30+
include_yaml_cpp(mrio_disaggregate ON GIT_TAG "yaml-cpp-0.6.3")
3031

3132
add_cpp_tools(mrio_disaggregate)
3233
add_cpp_tools(libmrio)

cmake

Submodule cmake updated 1 file

include/MRIOTable.h

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,19 @@ class Table {
5656
const I& divide_by,
5757
const I& first_index,
5858
const I& last_index) noexcept;
59-
template<typename... Arguments>
60-
inline T build_sum_r(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s, const Arguments&... other) const noexcept;
61-
template<typename... Arguments>
62-
inline T build_sum_j(const Sector<I>* j, const Region<I>* s, const Arguments&... other) const noexcept;
63-
template<typename... Arguments>
64-
inline T build_sum_s(const Sector<I>* j, const Region<I>* s, const Arguments&... other) const noexcept;
65-
template<typename Inner, typename... Arguments>
66-
inline void add_sum(T& res, const std::vector<Inner*>& vec, const Arguments&... params) const noexcept;
67-
template<typename Inner, typename... Arguments>
68-
inline void add_sum(T& res, const std::vector<std::unique_ptr<Inner>>& vec, const Arguments&... params) const noexcept;
69-
template<typename... Arguments>
70-
inline void add_sum(T& res, const std::vector<std::unique_ptr<Sector<I>>>& vec, const bool, const Arguments&... params) const noexcept;
71-
template<typename Inner, typename... Arguments>
72-
inline void add_sum(T& res, const Inner* k, const Arguments&... params) const noexcept;
73-
inline void add_sum(T& res, const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
74-
template<typename... Arguments>
75-
inline T build_basesum_j(const Sector<I>* j, const Region<I>* s, const Arguments&... other) const noexcept;
76-
template<typename Inner, typename... Arguments>
77-
inline void add_basesum(T& res, const std::vector<Inner*>& vec, const Arguments&... params) const noexcept;
78-
template<typename Inner, typename... Arguments>
79-
inline void add_basesum(T& res, const std::vector<std::unique_ptr<Inner>>& vec, const Arguments&... params) const noexcept;
80-
template<typename... Arguments>
81-
inline void add_basesum(T& res, const std::vector<std::unique_ptr<Sector<I>>>& vec, const bool, const Arguments&... params) const noexcept;
82-
template<typename Inner, typename... Arguments>
83-
inline void add_basesum(T& res, const Inner* k, const Arguments&... params) const noexcept;
84-
inline void add_basesum(T& res, const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
59+
60+
template<bool use_base>
61+
void build_sum_source(T& res, const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
62+
template<bool use_base, typename Arg_i, typename Arg_r>
63+
void build_sum_target(T& res, Arg_i&& i, Arg_r&& r, const Sector<I>* j, const Region<I>* s) const noexcept;
64+
template<bool use_base, int c, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
65+
void add_sum(T& res, const std::vector<Arg1*>& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4) const noexcept;
66+
template<bool use_base, int c, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
67+
void add_sum(T& res, const std::vector<std::unique_ptr<Arg1>>& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4) const noexcept;
68+
template<bool use_base, int c, typename Arg3, typename Arg4>
69+
void add_sum(T& res, const std::vector<std::unique_ptr<Sector<I>>>& arg1, bool, Arg3&& arg3, Arg4&& arg4) const noexcept;
70+
template<bool use_base, int c, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
71+
void add_sum(T& res, const Arg1* arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4) const noexcept;
8572

8673
public:
8774
Table() {}
@@ -91,8 +78,6 @@ class Table {
9178
inline const IndexSet<I>& index_set() const { return index_set_; }
9279
void insert_subsectors(const std::string& name, const std::vector<std::string>& subsectors);
9380
void insert_subregions(const std::string& name, const std::vector<std::string>& subregions);
94-
T sum(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
95-
T basesum(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
9681
void write_to_csv(std::ostream& indicesstream, std::ostream& datastream) const;
9782
void write_to_mrio(std::ostream& outstream) const;
9883
#ifdef LIBMRIO_WITH_NETCDF
@@ -104,6 +89,9 @@ class Table {
10489
void read_from_netcdf(const std::string& filename, const T& threshold);
10590
#endif
10691

92+
T sum(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
93+
T basesum(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const noexcept;
94+
10795
inline T& at(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) {
10896
assert(index_set_.at(i, r) >= 0);
10997
assert(index_set_.at(j, s) >= 0);

include/ProxyData.h

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,55 @@ class Sector;
4848
template<typename T, typename I>
4949
class Table;
5050

51+
template<typename I>
52+
struct FullIndex {
53+
const Sector<I>* i;
54+
const Region<I>* r;
55+
const Sector<I>* j;
56+
const Region<I>* s;
57+
};
58+
59+
template<typename T, typename I, typename Func>
60+
inline void do_for_all_sub(Func func, const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) {
61+
func(i, r, j, s);
62+
}
63+
64+
template<typename T, typename I, typename Inner, typename... Arguments>
65+
inline void do_for_all_sub(const Inner* k, const Arguments&... params) {
66+
do_for_all_sub<T, I>(params..., k);
67+
}
68+
69+
template<typename T, typename I, typename Inner, typename... Arguments>
70+
inline void do_for_all_sub(const std::vector<Inner*>& vec, const Arguments&... params) {
71+
for (const auto k : vec) {
72+
do_for_all_sub<T, I>(params..., k);
73+
}
74+
}
75+
76+
template<typename T, typename I, typename Func, typename... Arguments>
77+
inline typename std::enable_if<!(std::is_same<Func, const Region<I>*>::value || std::is_same<Func, const Sector<I>*>::value), void>::type for_all_sub(
78+
Func func, const Arguments&... params) {
79+
do_for_all_sub<T, I>(params..., func);
80+
}
81+
82+
template<typename T, typename I, typename... Arguments>
83+
inline void for_all_sub(const Region<I>* r, const Arguments&... params) {
84+
if (r->has_sub()) {
85+
for_all_sub<T, I>(params..., r->as_super()->sub());
86+
} else {
87+
for_all_sub<T, I>(params..., r);
88+
}
89+
}
90+
91+
template<typename T, typename I, typename... Arguments>
92+
inline void for_all_sub(const Sector<I>* i, const Arguments&... params) {
93+
if (i->has_sub()) {
94+
for_all_sub<T, I>(params..., i->as_super()->sub());
95+
} else {
96+
for_all_sub<T, I>(params..., i);
97+
}
98+
}
99+
51100
template<typename T, typename I>
52101
class ProxyData {
53102
protected:
@@ -76,8 +125,7 @@ class ProxyData {
76125
};
77126
struct ProxyIndex {
78127
enum class Type { SECTOR, SUBSECTOR, REGION, SUBREGION };
79-
ProxyIndex(bool mapped_p, Type type_p)
80-
: mapped(mapped_p), type(type_p), sub(type_p == Type::SUBSECTOR || type_p == Type::SUBREGION) {}
128+
ProxyIndex(bool mapped_p, Type type_p) : mapped(mapped_p), type(type_p), sub(type_p == Type::SUBSECTOR || type_p == Type::SUBREGION) {}
81129
const bool mapped;
82130
const bool sub;
83131
const Type type;
@@ -97,17 +145,23 @@ class ProxyData {
97145
ProxyIndex* r = nullptr;
98146
ProxyIndex* j = nullptr;
99147
ProxyIndex* s = nullptr;
148+
Application() = default;
149+
Application(Application* application1, Application* application2);
150+
Application(ProxyIndex* i_p, ProxyIndex* r_p, ProxyIndex* j_p, ProxyIndex* s_p) : i(i_p), r(r_p), j(j_p), s(s_p) {}
151+
inline T get_flow(const Table<T, I>& table, const Sector<I>* i_p, const Region<I>* r_p, const Sector<I>* j_p, const Region<I>* s_p) const;
152+
inline T get_flow_share_denominator(
153+
const Table<T, I>& table, const Sector<I>* i_p, const Region<I>* r_p, const Sector<I>* j_p, const Region<I>* s_p) const;
100154
inline bool applies_to(const Sector<I>* i_p, const Region<I>* r_p, const Sector<I>* j_p, const Region<I>* s_p) const {
101-
return (i == nullptr || i->sub == i_p->is_sub()) && (r == nullptr || r->sub == r_p->is_sub()) && (j == nullptr || j->sub == j_p->is_sub())
102-
&& (s == nullptr || s->sub == s_p->is_sub());
155+
return (i == nullptr || i->sub == i_p->has_sub()) && (r == nullptr || r->sub == r_p->has_sub()) && (j == nullptr || j->sub == j_p->has_sub())
156+
&& (s == nullptr || s->sub == s_p->has_sub());
103157
}
104158
#ifdef LIBMRIO_VERBOSE
105159
friend std::ostream& operator<<(std::ostream& os, const Application& a) {
106160
return os << (a.i == nullptr ? "" : "i") << (a.r == nullptr ? "" : "r") << (a.j == nullptr ? "" : "j") << (a.s == nullptr ? "" : "s");
107161
}
108162
#endif
109-
T get_flow_share(const Table<T, I>& table, const Sector<I>* i_p, const Region<I>* r_p, const Sector<I>* j_p, const Region<I>* s_p) const;
110163
};
164+
111165
std::vector<T> data;
112166
std::vector<std::unique_ptr<ProxyIndex>> indices;
113167
std::vector<std::unique_ptr<Application>> applications;
@@ -142,8 +196,11 @@ class ProxyData {
142196

143197
public:
144198
explicit ProxyData(IndexSet<I> table_indices_p) : table_indices(std::move(table_indices_p)) {}
145-
bool apply(T& result, const Table<T, I>& table, const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) const;
146199
void read_from_file(const settings::SettingsNode& settings_node);
200+
void approximate(
201+
const std::vector<FullIndex<I>>& full_indices, Table<T, I>& table, Table<std::size_t, I> quality, const Table<T, I>& last_table, std::size_t d) const;
202+
void adjust(
203+
const std::vector<FullIndex<I>>& full_indices, Table<T, I>& table, Table<std::size_t, I> quality, const Table<T, I>& basetable, std::size_t d) const;
147204
};
148205
} // namespace mrio
149206

include/disaggregation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ template<typename T, typename I>
3030
class Table;
3131

3232
template<typename T, typename I>
33-
mrio::Table<T, I> disaggregate(const mrio::Table<T, I>& basetable, const settings::SettingsNode& settings);
33+
Table<T, I> disaggregate(const Table<T, I>& basetable, const settings::SettingsNode& settings);
34+
3435
} // namespace mrio
3536

3637
#endif

libmrio.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ add_library(libmrio STATIC
1010
${CMAKE_CURRENT_LIST_DIR}/src/MRIOTable.cpp
1111
${CMAKE_CURRENT_LIST_DIR}/src/ProxyData.cpp)
1212
target_include_directories(libmrio PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/lib/cpp-library)
13-
target_compile_options(libmrio PRIVATE "-std=c++11")
13+
target_compile_options(libmrio PUBLIC -std=c++17)
14+
set_property(TARGET libmrio PROPERTY CXX_STANDARD 17)
1415

1516
option(LIBMRIO_PARALLELIZATION "" ON)
1617
if(LIBMRIO_PARALLELIZATION)
@@ -26,7 +27,7 @@ if(LIBMRIO_WITH_NETCDF)
2627
message(STATUS "NetCDF library: ${NETCDF_LIBRARY}")
2728
target_link_libraries(libmrio PRIVATE netcdf)
2829

29-
include_netcdf_cxx4(libmrio ON v4.3.0)
30+
include_netcdf_cxx4(libmrio ON GIT_TAG "v4.3.0")
3031
target_compile_definitions(libmrio PUBLIC LIBMRIO_WITH_NETCDF)
3132
endif()
3233

0 commit comments

Comments
 (0)