Skip to content

Commit

Permalink
Fixed issue when recursively creating Market objects. Changed vector …
Browse files Browse the repository at this point in the history
…of children to unique_ptr

Signed-off-by: Piet Gömpel <pietgoempel@gmail.com>
  • Loading branch information
Pietfried committed Oct 11, 2024
1 parent 04559b2 commit ceb5851
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/EnergyManager/EnergyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ std::vector<types::energy::EnforcedLimits> EnergyManager::run_optimizer(types::e
optimized_values.reserve(brokers.size());

for (auto broker : brokers) {
auto local_market = broker->get_local_market();
auto& local_market = broker->get_local_market();
const auto sold_energy = local_market.get_sold_energy();

if (sold_energy.size() > 0) {
Expand Down
10 changes: 3 additions & 7 deletions modules/EnergyManager/Market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,10 @@ Market::Market(types::energy::EnergyFlowRequest& _energy_flow_request, const flo

// Recursion: create one Market for each child
for (auto& flow_child : _energy_flow_request.children) {
_children.emplace_back(flow_child, _nominal_ac_voltage, this);
_children.emplace_back(std::make_unique<Market>(flow_child, _nominal_ac_voltage, this));
}
}

const std::vector<Market>& Market::children() {
return _children;
}

ScheduleRes Market::get_sold_energy() {
return sold_root;
}
Expand All @@ -271,7 +267,7 @@ void Market::get_list_of_evses(std::vector<Market*>& list) {
}

for (auto& child : _children) {
child.get_list_of_evses(list);
child->get_list_of_evses(list);
}
}

Expand All @@ -282,7 +278,7 @@ std::vector<Market*> Market::get_list_of_evses() {
}

for (auto& child : _children) {
child.get_list_of_evses(list);
child->get_list_of_evses(list);
}
return list;
}
Expand Down
3 changes: 1 addition & 2 deletions modules/EnergyManager/Market.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Market {
ScheduleRes get_sold_energy();

Market* parent();
const std::vector<Market>& children();

float nominal_ac_voltage();

Expand All @@ -77,7 +76,7 @@ class Market {

private:
Market* _parent;
std::vector<Market> _children;
std::vector<std::unique_ptr<Market>> _children;
float _nominal_ac_voltage;

// main data structures
Expand Down

0 comments on commit ceb5851

Please sign in to comment.