Skip to content

Commit

Permalink
multiple disaggregation bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
swillner committed Jul 7, 2017
1 parent aad40bb commit 60ee0bf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
16 changes: 12 additions & 4 deletions include/Disaggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ class Disaggregation {
size[3] = size4;
data.resize(size1 * size2 * size3 * size4, std::numeric_limits<T>::quiet_NaN());
};
T& operator()(const IndexPart<I>* i1) noexcept { return data[i1->level_index()]; };
T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2) noexcept { return data[i1->level_index() + (i2->level_index()) * size[0]]; };
T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3) noexcept {
inline T& at(const IndexPart<I>* i1) { return data.at(i1->level_index()); };
inline T& at(const IndexPart<I>* i1, const IndexPart<I>* i2) { return data.at(i1->level_index() + (i2->level_index()) * size[0]); };
inline T& at(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3) {
return data.at(i1->level_index() + (i2->level_index() + (i3->level_index()) * size[1]) * size[0]);
};
inline T& at(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3, const IndexPart<I>* i4) {
return data.at(i1->level_index() + (i2->level_index() + (i3->level_index() + i4->level_index() * size[2]) * size[1]) * size[0]);
};
inline T& operator()(const IndexPart<I>* i1) { return data[i1->level_index()]; };
inline T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2) { return data[i1->level_index() + (i2->level_index()) * size[0]]; };
inline T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3) {
return data[i1->level_index() + (i2->level_index() + (i3->level_index()) * size[1]) * size[0]];
};
T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3, const IndexPart<I>* i4) noexcept {
inline T& operator()(const IndexPart<I>* i1, const IndexPart<I>* i2, const IndexPart<I>* i3, const IndexPart<I>* i4) {
return data[i1->level_index() + (i2->level_index() + (i3->level_index() + i4->level_index() * size[2]) * size[1]) * size[0]];
};
};
Expand Down
20 changes: 10 additions & 10 deletions include/MRIOIndexSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Sector : public IndexPart<I> {
virtual SuperSector<I>* as_super() = 0;
virtual const SuperSector<I>* as_super() const = 0;
virtual const SuperSector<I>* super() const = 0;
virtual const bool has_sub() const = 0;
virtual bool has_sub() const = 0;
};
template<typename I>
class SubSector : public Sector<I> {
Expand All @@ -86,7 +86,7 @@ class SubSector : public Sector<I> {
SuperSector<I>* as_super() override { return nullptr; };
const SuperSector<I>* as_super() const override { return nullptr; };
const SuperSector<I>* parent() const override { return parent_; };
const bool has_sub() const override { return false; };
bool has_sub() const override { return false; };
};
template<typename I>
class SuperRegion;
Expand All @@ -106,7 +106,7 @@ class SuperSector : public Sector<I> {
SuperSector<I>* as_super() override { return this; };
const SuperSector<I>* as_super() const override { return this; };
const SuperSector<I>* parent() const override { return nullptr; };
const bool has_sub() const override { return sub_.size() > 0; };
bool has_sub() const override { return sub_.size() > 0; };
};

template<typename I>
Expand All @@ -123,7 +123,7 @@ class Region : public IndexPart<I> {
virtual SuperRegion<I>* as_super() = 0;
virtual const SuperRegion<I>* as_super() const = 0;
virtual const SuperRegion<I>* super() const = 0;
virtual const bool has_sub() const = 0;
virtual bool has_sub() const = 0;
};
template<typename I>
class SubRegion : public Region<I> {
Expand All @@ -140,7 +140,7 @@ class SubRegion : public Region<I> {
SuperRegion<I>* as_super() override { return nullptr; };
const SuperRegion<I>* as_super() const override { return nullptr; };
const SuperRegion<I>* parent() const override { return parent_; };
const bool has_sub() const override { return false; };
bool has_sub() const override { return false; };
};
template<typename I>
class SuperRegion : public Region<I> {
Expand All @@ -158,7 +158,7 @@ class SuperRegion : public Region<I> {
SuperRegion<I>* as_super() override { return this; };
const SuperRegion<I>* as_super() const override { return this; };
const SuperRegion<I>* parent() const override { return nullptr; };
const bool has_sub() const override { return sub_.size() > 0; };
bool has_sub() const override { return sub_.size() > 0; };
};

template<typename I>
Expand Down Expand Up @@ -235,8 +235,8 @@ class IndexSet {
(subregion_it == (*superregion_it)->sub().end()) ? static_cast<Region<I>*>(superregion_it->get()) : static_cast<Region<I>*>(*subregion_it),
index};
};
const bool operator==(const total_iterator& rhs) const { return index == rhs.index; };
const bool operator!=(const total_iterator& rhs) const { return !(*this == rhs); };
bool operator==(const total_iterator& rhs) const { return index == rhs.index; };
bool operator!=(const total_iterator& rhs) const { return !(*this == rhs); };
};
total_iterator tbegin() const { return total_iterator::begin(*this); };
total_iterator tend() const { return total_iterator::end(*this); };
Expand Down Expand Up @@ -288,11 +288,11 @@ class IndexSet {
return *this;
};
const Index operator*() const { return {*sector_it, region_it->get()}; };
const bool operator==(const super_iterator& rhs) const {
bool operator==(const super_iterator& rhs) const {
return (region_it == rhs.region_it && sector_it == rhs.sector_it)
|| (region_it == parent->superregions().end() && rhs.region_it == rhs.parent->superregions().end());
};
const bool operator!=(const super_iterator& rhs) const { return !(*this == rhs); };
bool operator!=(const super_iterator& rhs) const { return !(*this == rhs); };
};
super_iterator sbegin() const { return super_iterator::begin(this); };
super_iterator send() const { return super_iterator::end(this); };
Expand Down
2 changes: 2 additions & 0 deletions src/Disaggregation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void Disaggregation<T, I>::initialize(const settings::SettingsNode& settings) {
} else {
throw std::runtime_error("Unknown type");
}
}
for (const auto& d : settings.as_sequence()) {
for (const auto& proxy : d["proxies"].as_sequence()) {
read_proxy_file(proxy["file"].as<std::string>(), proxy["level"].as<int>(), proxy["year"].as<int>());
}
Expand Down
18 changes: 9 additions & 9 deletions src/MRIOTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,24 +542,24 @@ void Table<T, I>::insert_region_offset_y(const SuperRegion<I>* r,
template<typename T, typename I>
void Table<T, I>::debug_out() const {
#ifdef DEBUGOUT
cout << "\n====\n";
cout << std::setprecision(3) << std::fixed;
std::cout << "\n====\n";
std::cout << std::setprecision(3) << std::fixed;
for (const auto& y : index_set_.total_indices) {
cout << index_set_.at(y.sector, y.region) << " " << y.sector->name << " " << (!y.sector->parent() ? " " : y.sector->parent()->name) << " "
std::cout << index_set_.at(y.sector, y.region) << " " << y.sector->name << " " << (!y.sector->parent() ? " " : y.sector->parent()->name) << " "
<< (y.sector->parent() ? *y.sector->parent() : *y.sector) << " " << (*y.sector) << " " << y.sector->level_index() << " " << y.region->name << " "
<< (!y.region->parent() ? " " : y.region->parent()->name) << " " << (y.region->parent() ? *y.region->parent() : *y.region) << " "
<< (*y.region) << " " << y.region->level_index() << " | ";
for (const auto& x : index_set_.total_indices) {
if (data[x.index * index_set_.size() + y.index] == 0) {
cout << " . ";
if (data[x.index * index_set_.size() + y.index] <= 0) {
std::cout << " . ";
} else {
cout << data[x.index * index_set_.size() + y.index];
std::cout << data[x.index * index_set_.size() + y.index];
}
cout << " ";
std::cout << " ";
}
cout << "\n";
std::cout << "\n";
}
cout << "====\n";
std::cout << "====\n";
#endif
}

Expand Down

0 comments on commit 60ee0bf

Please sign in to comment.