Commit 4b5d80c1 authored by Houtan Bastani's avatar Houtan Bastani

rework substitution of diff nodes using new node comparison methods

parent 00d276b5
......@@ -5399,7 +5399,7 @@ DynamicModel::substituteUnaryOps(vector<int> &eqnumbers)
}
void
DynamicModel::substituteDiff(StaticModel &static_model, ExprNode::subst_table_t &diff_subst_table)
DynamicModel::substituteDiff(ExprNode::subst_table_t &diff_subst_table)
{
set<int> used_local_vars;
for (const auto & equation : equations)
......@@ -5409,21 +5409,21 @@ DynamicModel::substituteDiff(StaticModel &static_model, ExprNode::subst_table_t
diff_table_t diff_table;
for (auto & it : local_variables_table)
if (used_local_vars.find(it.first) != used_local_vars.end())
it.second->findDiffNodes(static_model, diff_table);
it.second->findDiffNodes(diff_table);
for (const auto & equation : equations)
equation->findDiffNodes(static_model, diff_table);
equation->findDiffNodes(diff_table);
// Substitute in model local variables
vector<BinaryOpNode *> neweqs;
for (auto & it : local_variables_table)
it.second = it.second->substituteDiff(static_model, diff_table, diff_subst_table, neweqs);
it.second = it.second->substituteDiff(diff_table, diff_subst_table, neweqs);
// Substitute in equations
for (auto & equation : equations)
{
auto *substeq = dynamic_cast<BinaryOpNode *>(equation->
substituteDiff(static_model, diff_table, diff_subst_table, neweqs));
substituteDiff(diff_table, diff_subst_table, neweqs));
assert(substeq != nullptr);
equation = substeq;
}
......
......@@ -432,7 +432,7 @@ public:
void substituteUnaryOps(vector<int> &eqnumbers);
//! Substitutes diff operator
void substituteDiff(StaticModel &static_model, ExprNode::subst_table_t &diff_subst_table);
void substituteDiff(ExprNode::subst_table_t &diff_subst_table);
//! Table to undiff LHS variables for pac vector z
void getUndiffLHSForPac(vector<int> &lhs, vector<expr_t> &lhs_expr_t, vector<bool> &diff, vector<int> &orig_diff_var,
......
This diff is collapsed.
This diff is collapsed.
......@@ -372,7 +372,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
// Create auxiliary variable and equations for Diff operators that appear in VAR equations
ExprNode::subst_table_t diff_subst_table;
dynamic_model.substituteDiff(diff_static_model, diff_subst_table);
dynamic_model.substituteDiff(diff_subst_table);
// Var Model
map<string, vector<string>> var_model_eq_tags;
......
......@@ -715,12 +715,14 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, expr_t e
}
int
SymbolTable::addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false)
SymbolTable::addDiffLagAuxiliaryVar(int index, expr_t expr_arg,
int lag,
int orig_symb_id, int orig_lag) noexcept(false)
{
ostringstream varname;
int symb_id;
varname << "AUX_DIFF_LAG_" << index;
varname << "AUX_DIFF_" << index << "_LAG_" << lag;
try
{
......
......@@ -293,7 +293,7 @@ public:
int addDiffAuxiliaryVar(int index, expr_t expr_arg) noexcept(false);
int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false);
//! Takes care of timing between diff statements
int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false);
int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int lag, int orig_symb_id, int orig_lag) noexcept(false);
//! An Auxiliary variable for a unary op
int addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id = -1, int orig_lag = 0) noexcept(false);
//! Returns the number of auxiliary variables
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment