Skip to content
Snippets Groups Projects
Select Git revision
3 results Searching

SubModel.hh

Blame
  • Forked from Dynare / preprocessor
    Source project has a limited visibility.
    SteadyStateModel.cc 5.08 KiB
    /*
     * Copyright (C) 2010-2011 Dynare Team
     *
     * This file is part of Dynare.
     *
     * Dynare is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * Dynare is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
     */
    
    #include <cassert>
    #include <algorithm>
    
    #include "SteadyStateModel.hh"
    
    SteadyStateModel::SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg, const StaticModel &static_model_arg) :
      DataTree(symbol_table_arg, num_constants, external_functions_table), static_model(static_model_arg)
    {
    }
    
    void
    SteadyStateModel::addDefinition(int symb_id, expr_t expr)
    {
      AddVariable(symb_id); // Create the variable node to be used in write method
    
      assert(symbol_table.getType(symb_id) == eEndogenous
             || symbol_table.getType(symb_id) == eModFileLocalVariable
             || symbol_table.getType(symb_id) == eParameter);
    
      // Add the variable
      vector<int> v;
      v.push_back(symb_id);
      recursive_order.push_back(v);
      def_table[v] = expr;
    }
    
    void
    SteadyStateModel::addMultipleDefinitions(const vector<int> &symb_ids, expr_t expr)
    {
      for (size_t i = 0; i < symb_ids.size(); i++)
        {
          AddVariable(symb_ids[i]); // Create the variable nodes to be used in write method
          assert(symbol_table.getType(symb_ids[i]) == eEndogenous
                 || symbol_table.getType(symb_ids[i]) == eModFileLocalVariable
                 || symbol_table.getType(symb_ids[i]) == eParameter);
        }
      recursive_order.push_back(symb_ids);
      def_table[symb_ids] = expr;
    }
    
    void
    SteadyStateModel::checkPass(bool ramsey_policy) const
    {
      vector<int> so_far_defined;
    
      for (size_t i = 0; i < recursive_order.size(); i++)
        {
          const vector<int> &symb_ids = recursive_order[i];
    
          // Check that symbols are not already defined
          for (size_t j = 0; j < symb_ids.size(); j++)