PlannerObjectiveStatement: turn model_tree into a std::unique_ptr
Avoids an unnecessary copy.master
parent
5e89921ea1
commit
c5cc61b110
|
@ -2400,8 +2400,8 @@ ModelComparisonStatement::writeJsonOutput(ostream& output) const
|
|||
output << "}";
|
||||
}
|
||||
|
||||
PlannerObjectiveStatement::PlannerObjectiveStatement(const PlannerObjective& model_tree_arg) :
|
||||
model_tree {model_tree_arg}
|
||||
PlannerObjectiveStatement::PlannerObjectiveStatement(unique_ptr<PlannerObjective> model_tree_arg) :
|
||||
model_tree {move(model_tree_arg)}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2409,8 +2409,8 @@ void
|
|||
PlannerObjectiveStatement::checkPass(ModFileStructure& mod_file_struct,
|
||||
[[maybe_unused]] WarningConsolidation& warnings)
|
||||
{
|
||||
assert(model_tree.equation_number() == 1);
|
||||
if (model_tree.exoPresentInEqs())
|
||||
assert(model_tree->equation_number() == 1);
|
||||
if (model_tree->exoPresentInEqs())
|
||||
{
|
||||
cerr << "ERROR: You cannot include exogenous variables (or variables of undeclared type) in "
|
||||
"the planner objective. Please "
|
||||
|
@ -2424,13 +2424,13 @@ PlannerObjectiveStatement::checkPass(ModFileStructure& mod_file_struct,
|
|||
const PlannerObjective&
|
||||
PlannerObjectiveStatement::getPlannerObjective() const
|
||||
{
|
||||
return model_tree;
|
||||
return *model_tree;
|
||||
}
|
||||
|
||||
void
|
||||
PlannerObjectiveStatement::computingPass(const ModFileStructure& mod_file_struct)
|
||||
{
|
||||
model_tree.computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false);
|
||||
model_tree->computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false);
|
||||
computing_pass_called = true;
|
||||
}
|
||||
|
||||
|
@ -2439,14 +2439,14 @@ PlannerObjectiveStatement::writeOutput(ostream& output, const string& basename,
|
|||
[[maybe_unused]] bool minimal_workspace) const
|
||||
{
|
||||
output << "M_.NNZDerivatives_objective = [";
|
||||
for (int i = 1; i < static_cast<int>(model_tree.getNNZDerivatives().size()); i++)
|
||||
output << (i > model_tree.getComputedDerivsOrder() ? -1 : model_tree.getNNZDerivatives()[i])
|
||||
for (int i = 1; i < static_cast<int>(model_tree->getNNZDerivatives().size()); i++)
|
||||
output << (i > model_tree->getComputedDerivsOrder() ? -1 : model_tree->getNNZDerivatives()[i])
|
||||
<< ";";
|
||||
output << "];" << endl << "M_.objective_tmp_nbr = [";
|
||||
for (const auto& temporary_terms_derivative : model_tree.getTemporaryTermsDerivatives())
|
||||
for (const auto& temporary_terms_derivative : model_tree->getTemporaryTermsDerivatives())
|
||||
output << temporary_terms_derivative.size() << "; ";
|
||||
output << "];" << endl;
|
||||
model_tree.writeStaticFile(basename + ".objective", false, "", {}, false);
|
||||
model_tree->writeStaticFile(basename + ".objective", false, "", {}, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2455,9 +2455,9 @@ PlannerObjectiveStatement::writeJsonOutput(ostream& output) const
|
|||
output << R"({"statementName": "planner_objective")"
|
||||
<< ", ";
|
||||
if (computing_pass_called)
|
||||
model_tree.writeJsonComputingPassOutput(output, false);
|
||||
model_tree->writeJsonComputingPassOutput(output, false);
|
||||
else
|
||||
model_tree.writeJsonOutput(output);
|
||||
model_tree->writeJsonOutput(output);
|
||||
|
||||
output << "}";
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#ifndef _COMPUTINGTASKS_HH
|
||||
#define _COMPUTINGTASKS_HH
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
|
||||
|
@ -618,11 +619,11 @@ public:
|
|||
class PlannerObjectiveStatement : public Statement
|
||||
{
|
||||
private:
|
||||
PlannerObjective model_tree;
|
||||
unique_ptr<PlannerObjective> model_tree;
|
||||
bool computing_pass_called {false};
|
||||
|
||||
public:
|
||||
explicit PlannerObjectiveStatement(const PlannerObjective& model_tree_arg);
|
||||
explicit PlannerObjectiveStatement(unique_ptr<PlannerObjective> model_tree_arg);
|
||||
/*! \todo check there are only endogenous variables at the current period in the objective
|
||||
(no exogenous, no lead/lag) */
|
||||
void checkPass(ModFileStructure& mod_file_struct, WarningConsolidation& warnings) override;
|
||||
|
@ -631,7 +632,7 @@ public:
|
|||
void writeOutput(ostream& output, const string& basename, bool minimal_workspace) const override;
|
||||
void writeJsonOutput(ostream& output) const override;
|
||||
//! Return a reference the Planner Objective model tree
|
||||
const PlannerObjective& getPlannerObjective() const;
|
||||
[[nodiscard]] const PlannerObjective& getPlannerObjective() const;
|
||||
};
|
||||
|
||||
class BVARDensityStatement : public Statement
|
||||
|
|
|
@ -2235,7 +2235,7 @@ ParsingDriver::end_planner_objective(expr_t expr)
|
|||
expr_t eq = model_tree->AddEqual(expr, model_tree->Zero);
|
||||
model_tree->addEquation(eq, location.begin.line);
|
||||
|
||||
mod_file->addStatement(make_unique<PlannerObjectiveStatement>(*planner_objective));
|
||||
mod_file->addStatement(make_unique<PlannerObjectiveStatement>(move(planner_objective)));
|
||||
|
||||
// Handle undeclared variables (see #81)
|
||||
bool exit_after_write = false;
|
||||
|
|
Loading…
Reference in New Issue