Merge branch 'master' into ecb-master
commit
6afa241ad2
103
ExprNode.cc
103
ExprNode.cc
|
@ -195,7 +195,8 @@ ExprNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output
|
|||
void
|
||||
ExprNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
@ -345,7 +346,8 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
void
|
||||
NumConstNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
output << datatree.num_constants.get(id);
|
||||
}
|
||||
|
@ -669,7 +671,8 @@ VariableNode::containsExternalFunction() const
|
|||
void
|
||||
VariableNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
|
@ -679,7 +682,7 @@ VariableNode::writeJsonOutput(ostream &output,
|
|||
}
|
||||
|
||||
output << datatree.symbol_table.getName(symb_id);
|
||||
if (lag != 0)
|
||||
if (isdynamic && lag != 0)
|
||||
output << "(" << lag << ")";
|
||||
}
|
||||
|
||||
|
@ -1974,7 +1977,8 @@ UnaryOpNode::containsExternalFunction() const
|
|||
void
|
||||
UnaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
|
@ -2057,7 +2061,7 @@ UnaryOpNode::writeJsonOutput(ostream &output,
|
|||
return;
|
||||
case oSteadyState:
|
||||
output << "(";
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ")";
|
||||
return;
|
||||
case oSteadyStateParamDeriv:
|
||||
|
@ -2108,7 +2112,7 @@ UnaryOpNode::writeJsonOutput(ostream &output,
|
|||
}
|
||||
|
||||
// Write argument
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
|
@ -2324,9 +2328,10 @@ UnaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType out
|
|||
void
|
||||
UnaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
arg->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3481,7 +3486,8 @@ BinaryOpNode::containsExternalFunction() const
|
|||
void
|
||||
BinaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
||||
|
@ -3504,9 +3510,9 @@ BinaryOpNode::writeJsonOutput(ostream &output,
|
|||
default:
|
||||
;
|
||||
}
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ",";
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ")";
|
||||
return;
|
||||
}
|
||||
|
@ -3514,9 +3520,9 @@ BinaryOpNode::writeJsonOutput(ostream &output,
|
|||
if (op_code == oPowerDeriv)
|
||||
{
|
||||
output << "get_power_deriv(";
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ",";
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << "," << powerDerivOrder << ")";
|
||||
return;
|
||||
}
|
||||
|
@ -3536,7 +3542,7 @@ BinaryOpNode::writeJsonOutput(ostream &output,
|
|||
}
|
||||
|
||||
// Write left argument
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
|
@ -3603,7 +3609,7 @@ BinaryOpNode::writeJsonOutput(ostream &output,
|
|||
}
|
||||
|
||||
// Write right argument
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
|
@ -3801,10 +3807,11 @@ BinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType ou
|
|||
void
|
||||
BinaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4788,7 +4795,8 @@ TrinaryOpNode::containsExternalFunction() const
|
|||
void
|
||||
TrinaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
|
||||
|
@ -4808,11 +4816,11 @@ TrinaryOpNode::writeJsonOutput(ostream &output,
|
|||
break;
|
||||
}
|
||||
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ",";
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ",";
|
||||
arg3->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
arg3->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ")";
|
||||
}
|
||||
|
||||
|
@ -4895,11 +4903,12 @@ TrinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType o
|
|||
void
|
||||
TrinaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg3->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
arg3->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -5573,7 +5582,8 @@ AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, Ex
|
|||
void
|
||||
AbstractExternalFunctionNode::writeJsonExternalFunctionArguments(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
for (vector<expr_t>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
|
@ -5581,7 +5591,7 @@ AbstractExternalFunctionNode::writeJsonExternalFunctionArguments(ostream &output
|
|||
if (it != arguments.begin())
|
||||
output << ",";
|
||||
|
||||
(*it)->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
(*it)->writeJsonOutput(output, temporary_terms, tef_terms, isdynamic);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5751,7 +5761,8 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign
|
|||
void
|
||||
ExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<ExternalFunctionNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
|
@ -5761,7 +5772,7 @@ ExternalFunctionNode::writeJsonOutput(ostream &output,
|
|||
}
|
||||
|
||||
output << datatree.symbol_table.getName(symb_id) << "(";
|
||||
writeJsonExternalFunctionArguments(output, temporary_terms, tef_terms);
|
||||
writeJsonExternalFunctionArguments(output, temporary_terms, tef_terms, isdynamic);
|
||||
output << ")";
|
||||
}
|
||||
|
||||
|
@ -5877,14 +5888,15 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
|
|||
void
|
||||
ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
|
||||
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
for (vector<expr_t>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
(*it)->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
(*it)->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
|
||||
if (!alreadyWrittenAsTefTerm(symb_id, tef_terms))
|
||||
{
|
||||
|
@ -5904,7 +5916,7 @@ ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
|||
ef << ", \"external_function_term_dd\": \"TEFDD_" << indx << "\"";
|
||||
|
||||
ef << ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "(";
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
|
||||
ef << ")\"}}";
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
|
@ -5994,7 +6006,8 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
|||
void
|
||||
FirstDerivExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<FirstDerivExternalFunctionNode *>(this));
|
||||
|
@ -6209,7 +6222,8 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
|
|||
void
|
||||
FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
|
||||
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
@ -6219,7 +6233,7 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &
|
|||
if (first_deriv_symb_id == symb_id)
|
||||
{
|
||||
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6242,7 +6256,7 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &
|
|||
<< ", \"value\": \"" << datatree.symbol_table.getName(first_deriv_symb_id) << "(";
|
||||
}
|
||||
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
|
||||
ef << ")\"}}";
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
|
@ -6375,7 +6389,8 @@ SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
|||
void
|
||||
SecondDerivExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<SecondDerivExternalFunctionNode *>(this));
|
||||
|
@ -6568,7 +6583,8 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
|
|||
void
|
||||
SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
|
||||
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
@ -6578,7 +6594,7 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string>
|
|||
if (second_deriv_symb_id == symb_id)
|
||||
{
|
||||
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6602,7 +6618,7 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string>
|
|||
<< ", \"value\": \"" << datatree.symbol_table.getName(second_deriv_symb_id) << "(";
|
||||
}
|
||||
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms, isdynamic);
|
||||
ef << ")\"}}" << endl;
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
|
@ -6968,7 +6984,8 @@ VarExpectationNode::substituteStaticAuxiliaryVariable() const
|
|||
void
|
||||
VarExpectationNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const
|
||||
{
|
||||
output << "var_expectation("
|
||||
<< "forecast_horizon = " << forecast_horizon
|
||||
|
|
48
ExprNode.hh
48
ExprNode.hh
|
@ -225,7 +225,7 @@ enum ExprNodeOutputType
|
|||
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||
|
||||
//! Writes output of node in JSON syntax
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic = true) const = 0;
|
||||
|
||||
virtual int precedenceJson(const temporary_terms_t &temporary_terms) const;
|
||||
|
||||
|
@ -238,7 +238,8 @@ enum ExprNodeOutputType
|
|||
//! Allows the insertion of commas if necessary
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic = true) const;
|
||||
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -508,7 +509,7 @@ public:
|
|||
};
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
|
||||
|
@ -562,7 +563,7 @@ public:
|
|||
VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg);
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, int > &reference_count,
|
||||
|
@ -649,14 +650,15 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -746,14 +748,15 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -859,14 +862,15 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -937,7 +941,7 @@ protected:
|
|||
int getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const throw (UnknownFunctionNameAndArgs);
|
||||
//! Helper function to write output arguments of any given external function
|
||||
void writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
void writeJsonExternalFunctionArguments(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
void writeJsonExternalFunctionArguments(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
public:
|
||||
AbstractExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
|
||||
const vector<expr_t> &arguments_arg);
|
||||
|
@ -946,14 +950,15 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const = 0;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic = true) const = 0;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic = true) const = 0;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1020,13 +1025,14 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1064,7 +1070,7 @@ public:
|
|||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||
int equation) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1074,7 +1080,8 @@ public:
|
|||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1107,7 +1114,7 @@ public:
|
|||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||
int equation) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1117,7 +1124,8 @@ public:
|
|||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
deriv_node_temp_terms_t &tef_terms,
|
||||
const bool isdynamic) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1188,7 +1196,7 @@ public:
|
|||
virtual bool isVarModelReferenced(const string &model_info_name) const;
|
||||
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
|
||||
virtual expr_t substituteStaticAuxiliaryVariable() const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
34
ModFile.cc
34
ModFile.cc
|
@ -1413,15 +1413,23 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|
|||
original_model_output << "}" << endl;
|
||||
}
|
||||
|
||||
ostringstream steady_state_model_output;
|
||||
steady_state_model_output << "";
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
steady_state_model.writeJsonSteadyStateFile(steady_state_model_output,
|
||||
transformpass || computingpass);
|
||||
|
||||
if (json_output_mode == standardout)
|
||||
{
|
||||
if (transformpass || computingpass)
|
||||
cout << "\"transformed_model\": ";
|
||||
cout << "\"transformed_modfile\": ";
|
||||
else
|
||||
cout << "\"model\": ";
|
||||
cout << "\"modfile\": ";
|
||||
cout << output.str();
|
||||
if (!original_model_output.str().empty())
|
||||
cout << ", \"original_model\": " << original_model_output.str();
|
||||
if (!steady_state_model_output.str().empty())
|
||||
cout << ", \"steady_state_model\": " << steady_state_model_output.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1469,6 +1477,28 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|
|||
jsonOutputFile << original_model_output.str();
|
||||
jsonOutputFile.close();
|
||||
}
|
||||
if (!steady_state_model_output.str().empty())
|
||||
{
|
||||
if (basename.size())
|
||||
{
|
||||
string fname(basename);
|
||||
fname += "_steady_state_model.json";
|
||||
jsonOutputFile.open(fname.c_str(), ios::out | ios::binary);
|
||||
if (!jsonOutputFile.is_open())
|
||||
{
|
||||
cerr << "ERROR: Can't open file " << fname << " for writing" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Missing file name" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
jsonOutputFile << steady_state_model_output.str();
|
||||
jsonOutputFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2197,6 +2197,38 @@ StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeJsonAuxVarRecursiveDefinitions(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
temporary_terms_t temporary_terms;
|
||||
|
||||
for (int i = 0; i < (int) aux_equations.size(); i++)
|
||||
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction())
|
||||
{
|
||||
vector<string> efout;
|
||||
dynamic_cast<ExprNode *>(aux_equations[i])->writeJsonExternalFunctionOutput(efout,
|
||||
temporary_terms,
|
||||
tef_terms,
|
||||
false);
|
||||
for (vector<string>::const_iterator it = efout.begin(); it != efout.end(); it++)
|
||||
{
|
||||
if (it != efout.begin())
|
||||
output << ", ";
|
||||
output << *it;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int) aux_equations.size(); i++)
|
||||
{
|
||||
output << ", {\"lhs\": \"";
|
||||
aux_equations[i]->get_arg1()->writeJsonOutput(output, temporary_terms, tef_terms, false);
|
||||
output << "\", \"rhs\": \"";
|
||||
dynamic_cast<BinaryOpNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->get_arg2()->writeJsonOutput(output, temporary_terms, tef_terms, false);
|
||||
output << "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) const
|
||||
{
|
||||
|
|
|
@ -192,6 +192,7 @@ public:
|
|||
void writeSetAuxiliaryVariables(const string &basename, const bool julia) const;
|
||||
void writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const;
|
||||
void writeLatexAuxVarRecursiveDefinitions(ostream &output) const;
|
||||
void writeJsonAuxVarRecursiveDefinitions(ostream &output) const;
|
||||
|
||||
//! To ensure that no exogenous is present in the planner objective
|
||||
//! See #1264
|
||||
|
|
|
@ -270,3 +270,47 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode
|
|||
static_model.writeAuxVarInitval(output, oCSteadyStateFile);
|
||||
output << "}" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComputingPass) const
|
||||
{
|
||||
if (def_table.size() == 0)
|
||||
return;
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
vector<pair<string, string> > eqtags;
|
||||
temporary_terms_t tt_empty;
|
||||
|
||||
output << "{\"steady_state_model\": [";
|
||||
|
||||
for (size_t i = 0; i < def_table.size(); i++)
|
||||
{
|
||||
const vector<int> &symb_ids = def_table[i].first;
|
||||
if (i != 0)
|
||||
output << ",";
|
||||
output << "{\"lhs\": ";
|
||||
if (symb_ids.size() > 1)
|
||||
output << "[";
|
||||
for (size_t j = 0; j < symb_ids.size(); j++)
|
||||
{
|
||||
if (j != 0)
|
||||
output << ",";
|
||||
variable_node_map_t::const_iterator it =
|
||||
variable_node_map.find(make_pair(symb_ids[j], 0));
|
||||
assert(it != variable_node_map.end());
|
||||
output << "\"";
|
||||
dynamic_cast<ExprNode *>(it->second)->writeJsonOutput(output, tt_empty, tef_terms, false);
|
||||
output << "\"";
|
||||
}
|
||||
if (symb_ids.size() > 1)
|
||||
output << "]";
|
||||
output << ", \"rhs\":\"";
|
||||
def_table[i].second->writeJsonOutput(output, tt_empty, tef_terms, false);
|
||||
output << "\"}" << endl;
|
||||
}
|
||||
|
||||
if (transformComputingPass)
|
||||
static_model.writeJsonAuxVarRecursiveDefinitions(output);
|
||||
|
||||
output << "]}";
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
void writeSteadyStateFileC(const string &basename, bool ramsey_model) const;
|
||||
//! Writes LaTeX file with the equations of the dynamic model (for the steady state model)
|
||||
void writeLatexSteadyStateFile(const string &basename) const;
|
||||
//! Writes JSON output
|
||||
void writeJsonSteadyStateFile(ostream &output, bool transformComputingPass) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue