Commit 1d926025 authored by ferhat's avatar ferhat
Browse files

- sparse_dll option works fine with feedback variables

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2851 ac1d8469-bf42-47a9-8791-bf33cf982152
parent f5920bbc
......@@ -58,7 +58,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global oo_ M_;
global oo_ M_ T9025 T1149 T11905;
cvg=0;
iter=0;
Per_u_=0;
......@@ -73,8 +73,33 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
reduced = 0;
while ~(cvg==1 | iter>maxit_),
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, periods, 0, y_kmin, Blck_size);
% for i=1:periods;
% disp([sprintf('%5.14f ',[T9025(i) T1149(i) T11905(i)])]);
% end;
% return;
residual = r(:,y_kmin+1:y_kmin+1+y_kmax_l);
%num2str(residual,' %1.6f')
%jac_ = g1(1:(y_kmin)*Blck_size, 1:(y_kmin+1+y_kmax_l)*Blck_size);
%jac_
g1a=g1(:, y_kmin*Blck_size+1:(periods+y_kmin)*Blck_size);
b = b -g1(:, 1:y_kmin_l*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)'-g1(:, (periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
term1 = g1(:, 1:y_kmin_l*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)';
term2 = g1(:, (periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
b = b - term1 - term2;
% fid = fopen(['result' num2str(iter)],'w');
% fg1a = full(g1a);
% fprintf(fid,'%d\n',size(fg1a,1));
% fprintf(fid,'%d\n',size(fg1a,2));
% fprintf(fid,'%5.14f\n',fg1a);
% fprintf(fid,'%d\n',size(b,1));
% fprintf(fid,'%5.14f\n',b);
% fclose(fid);
% return;
%ipconfigb_ = b(1:(1+y_kmin)*Blck_size);
%b_
[max_res, max_indx]=max(max(abs(r')));
if(~isreal(r))
max_res = (-max_res^2)^0.5;
......@@ -151,6 +176,14 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
dx = g1a\b- ya;
ya = ya + lambda*dx;
y(1+y_kmin:periods+y_kmin,y_index)=reshape(ya',length(y_index),periods)';
% v = '';
% for i=1:(size(y_index,2))
% v = [v ' %1.6f'];
% end;
% v = [v '\n'];
% v
% sprintf(v,y(:,y_index)')
% return;
elseif(simulation_method==2),
flag1=1;
while(flag1>0)
......
This diff is collapsed.
......@@ -32,7 +32,11 @@
#ifdef LINBCG
# include "linbcg.hh"
#endif
#include "mex.h"
#ifndef DEBUG_EX
#include "mex.h"
#else
#include "mex_interface.hh"
#endif
//#define DEBUGC
......
......@@ -23,7 +23,6 @@ Mem_Mngr::Mem_Mngr()
{
swp_f=false;
swp_f_b=0;
//verbose=false;
}
void
Mem_Mngr::Print_heap()
......@@ -44,6 +43,7 @@ Mem_Mngr::init_Mem()
NZE_Mem=NULL;
NZE_Mem_add=NULL;
CHUNK_heap_pos=0;
NZE_Mem_Allocated.clear();
}
void Mem_Mngr::fixe_file_name(string filename_arg)
......@@ -60,7 +60,7 @@ Mem_Mngr::init_CHUNK_BLCK_SIZE(int u_count)
NonZeroElem*
Mem_Mngr::mxMalloc_NZE()
{
int i;
long int i;
if (!Chunk_Stack.empty()) /*An unused block of memory available inside the heap*/
{
NonZeroElem* p1 = Chunk_Stack.back();
......@@ -69,32 +69,27 @@ Mem_Mngr::mxMalloc_NZE()
}
else if (CHUNK_heap_pos<CHUNK_SIZE) /*there is enough allocated memory space available we keep it at the top of the heap*/
{
int i=CHUNK_heap_pos++;
i=CHUNK_heap_pos++;
return(NZE_Mem_add[i]);
}
else /*We have to allocate extra memory space*/
{
//mexPrintf("CHUNK_SIZE=%d CHUNK_BLCK_SIZE=%d Nb_CHUNK=%d\n",CHUNK_SIZE,CHUNK_BLCK_SIZE,Nb_CHUNK);
CHUNK_SIZE+=CHUNK_BLCK_SIZE;
/*mexPrintf("Allocate %f Ko\n",double(CHUNK_BLCK_SIZE)*double(sizeof(NonZeroElem))/double(1024));
mexEvalString("drawnow;");*/
Nb_CHUNK++;
#ifdef MEM_ALLOC_CHK
mexPrintf("CHUNK_BLCK_SIZE=%d\n",CHUNK_BLCK_SIZE);
#endif
NZE_Mem=(NonZeroElem*)mxMalloc(CHUNK_BLCK_SIZE*sizeof(NonZeroElem));
//mexPrintf("in mxMalloc NZE_Mem=%x CHUNK_heap_pos=%d CHUNK_BLCK_SIZE=%d Nb_CHUNK=%d\n",NZE_Mem, CHUNK_heap_pos, CHUNK_BLCK_SIZE, Nb_CHUNK);
NZE_Mem=(NonZeroElem*)mxMalloc(CHUNK_BLCK_SIZE*sizeof(NonZeroElem)); /*The block of memory allocated*/
NZE_Mem_Allocated.push_back(NZE_Mem);
if(!NZE_Mem)
{
mexPrintf("Not enough memory available\n");
mexEvalString("drawnow;");
}
#ifdef MEM_ALLOC_CHK
mexPrintf("CHUNK_SIZE=%d\n",CHUNK_SIZE);
#endif
NZE_Mem_add=(NonZeroElem**)mxRealloc(NZE_Mem_add, CHUNK_SIZE*sizeof(NonZeroElem*));
#ifdef MEM_ALLOC_CHK
mexPrintf("ok\n");
#endif
NZE_Mem_add=(NonZeroElem**)mxRealloc(NZE_Mem_add, CHUNK_SIZE*sizeof(NonZeroElem*)); /*We have to redefine the size of pointer on the memory*/
if(!NZE_Mem_add)
{
mexPrintf("Not enough memory available\n");
mexEvalString("drawnow;");
}
for (i=CHUNK_heap_pos;i<CHUNK_SIZE;i++)
{
NZE_Mem_add[i]=(NonZeroElem*)(NZE_Mem+(i-CHUNK_heap_pos));
......@@ -109,36 +104,13 @@ void
Mem_Mngr::mxFree_NZE(void* pos)
{
int i, gap;
/*if(verbose)
{
mexPrintf("pos=%x Nb_CHUNK=%d CHUNK_BLCK_SIZE=%d\n",pos,Nb_CHUNK, CHUNK_BLCK_SIZE);
mexEvalString("drawnow;");
}
*/
for (i=0;i<Nb_CHUNK;i++)
{
/*if(verbose)
{
mexPrintf("i=%d\n",i);
mexEvalString("drawnow;");
mexPrintf("NZE_Mem_add[i*CHUNK_BLCK_SIZE]=%d\n",NZE_Mem_add[i*CHUNK_BLCK_SIZE]);
mexEvalString("drawnow;");
}*/
gap=((uint64_t)(pos)-(uint64_t)(NZE_Mem_add[i*CHUNK_BLCK_SIZE]))/sizeof(NonZeroElem);
if ((gap<CHUNK_BLCK_SIZE) && (gap>=0))
break;
}
/*if(verbose)
{
mexPrintf("push_back()\n");
mexEvalString("drawnow;");
}*/
Chunk_Stack.push_back((NonZeroElem*)pos);
/*if(verbose)
{
mexPrintf("End\n");
mexEvalString("drawnow;");
}*/
}
......@@ -151,9 +123,6 @@ Mem_Mngr::write_swp_f(int *save_op_all,long int *nop_all)
if (!SaveCode_swp.is_open())
{
mexPrintf("open the swp file for writing\n");
#ifdef PRINT_OUT
mexPrintf("file opened\n");
#endif
SaveCode_swp.open((filename + ".swp").c_str(), std::ios::out | std::ios::binary);
if (!SaveCode_swp.is_open())
{
......@@ -161,9 +130,6 @@ Mem_Mngr::write_swp_f(int *save_op_all,long int *nop_all)
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
}
#ifdef PRINT_OUT
mexPrintf("done\n");
#endif
}
SaveCode_swp.write(reinterpret_cast<char *>(nop_all), sizeof(*nop_all));
SaveCode_swp.write(reinterpret_cast<char *>(save_op_all), (*nop_all)*sizeof(int));
......@@ -177,9 +143,6 @@ Mem_Mngr::read_swp_f(int **save_op_all,long int *nop_all)
swp_f=true;
if (!SaveCode_swp.is_open())
{
#ifdef PRINT_OUT
mexPrintf("file opened\n");
#endif
mexPrintf("open the file %s\n",(filename + ".swp").c_str());
SaveCode_swp.open((filename + ".swp").c_str(), std::ios::in | std::ios::binary);
j=SaveCode_swp.is_open();
......@@ -191,9 +154,6 @@ Mem_Mngr::read_swp_f(int **save_op_all,long int *nop_all)
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
}
#ifdef PRINT_OUT
mexPrintf("done\n");
#endif
SaveCode_swp.seekg(0);
}
......@@ -277,14 +237,10 @@ Mem_Mngr::chk_avail_mem(int **save_op_all,long int *nop_all,long int *nopa_all,i
void
Mem_Mngr::Free_All()
{
int i;
/*mexPrintf("Nb_CHUNK=%d\n",Nb_CHUNK);
mexEvalString("drawnow;");*/
for (i=0;i<Nb_CHUNK;i++)
while(NZE_Mem_Allocated.size())
{
/*mexPrintf("NZE_Mem_add[%d]=%x\n",i*CHUNK_BLCK_SIZE,NZE_Mem_add[i*CHUNK_BLCK_SIZE]);
mexEvalString("drawnow;");*/
mxFree(NZE_Mem_add[i*CHUNK_BLCK_SIZE]);
mxFree(NZE_Mem_Allocated.back());
NZE_Mem_Allocated.pop_back();
}
mxFree(NZE_Mem_add);
init_Mem();
......
......@@ -20,9 +20,14 @@
#ifndef MEM_MNGR_HH_INCLUDED
#define MEM_MNGR_HH_INCLUDED
//#include <stack>
#include <vector>
#include <fstream>
#include "mex.h"
#ifndef DEBUG_EX
#include "mex.h"
#else
#include "mex_interface.hh"
#endif
using namespace std;
struct NonZeroElem
......@@ -59,6 +64,7 @@ private:
int CHUNK_heap_pos/*, CHUNK_heap_max_size*/;
NonZeroElem** NZE_Mem_add;
NonZeroElem* NZE_Mem;
vector<NonZeroElem*> NZE_Mem_Allocated;
int swp_f_b;
fstream SaveCode_swp;
string filename;
......
This diff is collapsed.
......@@ -41,7 +41,7 @@ using namespace std;
struct t_save_op_s
{
short int lag, operat;
int first, second;
long int first, second;
};
const int IFLD =0;
......@@ -52,24 +52,10 @@ const int IFLDZ =4;
const int IFMUL =5;
const int IFSTP =6;
const int IFADD =7;
const double eps=1e-7;
const double eps=1e-10;
const double very_big=1e24;
const int alt_symbolic_count_max=1;
struct t_table_y
{
int index, nb;
int *u_index, *y_index;
};
struct t_table_u
{
t_table_u* pNext;
unsigned char type;
int index;
int op1, op2;
};
class SparseMatrix
{
......@@ -107,6 +93,8 @@ class SparseMatrix
void Delete_u(int pos);
void Clear_u();
void Print_u();
void CheckIt(int y_size, int y_kmin, int y_kmax, int Size, int periods, int iter);
void Check_the_Solution(int periods, int y_kmin, int y_kmax, int Size, double *u, int* pivot, int* b);
int complete(int beg_t, int Size, int periods, int *b);
double bksub( int tbreak, int last_period, int Size, double slowc_l
#ifdef PROFILER
......@@ -118,19 +106,11 @@ class SparseMatrix
void run_it(int nop_all,int *op_all);
void run_u_period1(int periods);
void close_swp_file();
void read_file_table_u(t_table_u **table_u, t_table_u **F_table_u, t_table_u **i_table_u, t_table_u **F_i_table_u, int *nb_table_u, bool i_to_do, bool shifting, int *nb_add_u_count, int y_kmin, int y_kmax, int u_size);
void read_file_table_y(t_table_y **table_y, t_table_y **i_table_y, int *nb_table_y, bool i_to_do, bool shifting, int y_kmin, int y_kmax, int u_size, int y_size);
void close_SaveCode();
stack<double> Stack;
int nb_prologue_table_u, nb_first_table_u, nb_middle_table_u, nb_last_table_u;
int nb_prologue_table_y, nb_first_table_y, nb_middle_table_y, nb_last_table_y;
int middle_count_loop;
char type;
t_table_u *prologue_table_u, *first_table_u, *first_i_table_u, *middle_table_u, *middle_i_table_u, *last_table_u;
t_table_y *prologue_table_y, *first_table_y, *middle_table_y, *middle_i_table_y, *last_table_y;
t_table_u *F_prologue_table_u, *F_first_table_u, *F_first_i_table_u, *F_middle_table_u, *F_middle_i_table_u, *F_last_table_u;
fstream SaveCode;
string filename;
int max_u, min_u;
......@@ -142,7 +122,7 @@ class SparseMatrix
NonZeroElem **FNZE_R, **FNZE_C;
int nb_endo, u_count_init;
int *pivot, *pivotk;
int *pivot, *pivotk, *pivot_save;
double *pivotv, *pivotva;
int *b;
bool *line_done;
......@@ -154,7 +134,7 @@ class SparseMatrix
int u_count_alloc, u_count_alloc_save;
double markowitz_c_s;
double res1a;
long int nop_all, /*nopa_all,*/ nop1, nop2;
long int nop_all, nop1, nop2;
map<pair<pair<int, int> ,int>, int> IM_i;
protected:
double *u, *y, *ya;
......@@ -166,7 +146,8 @@ protected:
int u_count, tbreak_g;
int iter;
double *direction;
int start_compare;
int restart;
};
......
......@@ -178,10 +178,7 @@ main( int argc, const char* argv[] )
mxFree(ya);
if(direction)
mxFree(direction);
free(params);
}
#else
......
......@@ -20,87 +20,20 @@
#ifndef SIMULATE_HH_INCLUDED
#define SIMULATE_HH_INCLUDED
/*#include <stack>
#include <set>
#include <vector>
#include <cmath>
#include <iostream>
#include <fstream>*/
//#include <ctime>
//#include <string>
/*#include <map>
#include <algorithm>
#include "CodeInterpreter.hh"
#include "SymbolTableTypes.hh"*/
#include "Interpreter.hh"
//#include "Mem_Mngr.hh"
/*#include "LinBCG.hh"*/
#include "mex.h"
/*#include "ExprNode.hh"*/
//#define pow pow1
/*typedef struct Variable_l
{
int* Index;
};
typedef struct tBlock
{
int Size, Sized, Type, Max_Lead, Max_Lag, Simulation_Type, Nb_Lead_Lag_Endo;
int *Variable, *dVariable, *Equation;
int *variable_dyn_index, *variable_dyn_leadlag;
IM_compact *IM_lead_lag;
};
typedef struct tModel_Block
{
int Size;
tBlock * List;
};
#define MARKOVITZ
#define PRINT_OUT_p
//#define RECORD_ALL
//#define DEBUGC
//#define PRINT_OUT
//#define PRINT_OUT_y1
//#define PRINT_u
//#define PRINT_OUT_b
//#define PRINT_OUT_y
//#define DEBUG
//#define EXTENDED
//#define FLOAT
//#define WRITE_u
//#define MEMORY_LEAKS
//#define N_MX_ALLOC
//#define MEM_ALLOC_CHK
#define NEW_ALLOC
//#define PROFILER
//#ifdef EXTENDED
//typedef long double double;
//#else
//typedef double double;
//#endif
*/
#ifndef DEBUG_EX
#include "mex.h"
#else
#include "mex_interface.hh"
#endif
using namespace std;
/*std::multimap<std::pair<int,int>, int> var_in_equ_and_lag_i, equ_in_var_and_lag_i;
int *pivota=NULL, *save_op_all=NULL;
#ifdef RECORD_ALL
bool record_all=false;
#endif
long int nopa_all;
*/
int /*Per_y_, Per_u_, it_, */nb_row_x, nb_row_xd, u_size, y_size, x_size, y_kmin, y_kmax, y_decal;
int nb_row_x, nb_row_xd, u_size, y_size, x_size, y_kmin, y_kmax, y_decal;
int periods, maxit_;
double *params, markowitz_c, slowc, slowc_save;
double *u, *y, *x, *r, *g1, *g2, *ya;
......
......@@ -5,9 +5,9 @@
using namespace std;
int
mexPrintf(string str, ...)
mexPrintf(/*string */const char *str, ...)
{
va_list vl;
/*va_list vl;
size_t found, found_p=0;
found=str.find_first_of("%");
va_start(vl,str);
......@@ -49,7 +49,16 @@ mexPrintf(string str, ...)
found=str.find_first_of("%",found_p);
}
printf(str.substr(found_p, str.size()-found_p+1).c_str());
return 0;
return 0;*/
va_list args;
int retval;
va_start (args, str);
retval = vprintf (str, args);
va_end (args);
return retval;
}
void
......
......@@ -5,7 +5,7 @@
#include <stdarg.h>
using namespace std;
int mexPrintf(const string str, ...);
int mexPrintf(/*const string*/const char* str, ...);
void mexErrMsgTxt(const string str);
void* mxMalloc(int amount);
void* mxRealloc(void* to_extend, int amount);
......
......@@ -328,7 +328,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
ModelBlock->Block_List[count_Block].Type = type;
ModelBlock->Block_List[count_Block].Nb_Recursives = recurs_Size;
ModelBlock->Block_List[count_Block].Temporary_InUse = new temporary_terms_inuse_type();
ModelBlock->Block_List[count_Block].Chaine_Rule_Derivatives = new chaine_rule_derivatives_type();
ModelBlock->Block_List[count_Block].Chain_Rule_Derivatives = new chain_rule_derivatives_type();
ModelBlock->Block_List[count_Block].Temporary_InUse->clear();
ModelBlock->Block_List[count_Block].Simulation_Type = SimType;
ModelBlock->Block_List[count_Block].Equation = (int *) malloc(ModelBlock->Block_List[count_Block].Size * sizeof(int));
......@@ -341,7 +341,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
first_count_equ = *count_Equ;
tmp_var = (int *) malloc(size * sizeof(int));
tmp_endo = (int *) malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
tmp_other_endo = (int *) malloc(symbol_table.endo_nbr() * sizeof(int));
tmp_other_endo = (int *) malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
tmp_size = (int *) malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
tmp_size_other_endo = (int *) malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
tmp_size_exo = (int *) malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
......@@ -349,7 +349,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
memset(tmp_size_other_endo, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_size, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_endo, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_other_endo, 0, symbol_table.endo_nbr()*sizeof(int));
memset(tmp_other_endo, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
nb_lead_lag_endo = 0;
Lag_Endo = Lead_Endo = Lag_Other_Endo = Lead_Other_Endo = Lag_Exo = Lead_Exo = 0;
......@@ -438,7 +438,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
{
if (!tmp_variable_evaluated[j])
{
tmp_other_endo[j] = 1;
tmp_other_endo[incidencematrix.Model_Max_Lag + k]++;
tmp_nb_other_endo++;
}
if (k > 0 && k > Lead_Other_Endo)
......@@ -679,7 +679,7 @@ BlockTriangular::Free_Block(Model_Block *ModelBlock) const
delete ModelBlock->Block_List[blk].Temporary_Terms_in_Equation[i];
free(ModelBlock->Block_List[blk].Temporary_Terms_in_Equation);
delete (ModelBlock->Block_List[blk].Temporary_InUse);
delete ModelBlock->Block_List[blk].Chaine_Rule_Derivatives;
delete ModelBlock->Block_List[blk].Chain_Rule_Derivatives;
}
free(ModelBlock->Block_List);
free(ModelBlock);
......@@ -728,12 +728,13 @@ BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations,
}
else
{
//vector<pair<int, NodeID> > List_of_Op_RHS;
//the equation could be normalized by a permutation of the rhs and the lhs
if (d_endo_variable == result.end()) //the equation is linear in the endogenous and could be normalized using the derivative
{
Equation_Simulation_Type = E_EVALUATE_S;
//cout << " gone normalized : ";
res = equations[eq]->normalizeLinearInEndoEquation(var, derivative->second);
res = equations[eq]->normalizeLinearInEndoEquation(var, derivative->second/*, List_of_Op_RHS*/);
/*res.second->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
cout << " done\n";*/
}
......@@ -854,10 +855,11 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
return (Type);
}
map<pair<pair<int, int>, pair<pair<int, int>, int> >, int>
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int>
BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
{
map<pair<pair<int, int>, pair<pair<int, int>, int> >, int> Derivatives;
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> Derivatives;
Derivatives.clear();
int nb_endo = symbol_table.endo_nbr();
/*ModelBlock.Block_List[Blck].first_order_determinstic_simulation_derivatives = new*/
......@@ -876,11 +878,8 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
cout << "varr=" << varr << " eqr=" << eqr << " lag=" << lag << "\n";*/
if(IM[varr+eqr*nb_endo])
{
/*if(eq<ModelBlock->Block_List[blck].Nb_Recursives and var<ModelBlock->Block_List[blck].Nb_Recursives)
{*/
bool OK = true;
map<pair<pair<int, int>, pair<pair<int, int>, int> >, int>::const_iterator its = Derivatives.find(make_pair(make_pair(eqr, eq), make_pair(make_pair(varr, var), lag)));
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int>::const_iterator its = Derivatives.find(make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr)));
if(its!=Derivatives.end())
{
if(its->second == 2)
......@@ -890,20 +889,21 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
if(OK)
{
if (ModelBlock->Block_List[blck].Equation_Type[eq] == E_EVALUATE_S and eq<ModelBlock->Block_List[blck].Nb_Recursives)
Derivatives[make_pair(make_pair(eqr, eq), make_pair(make_pair(varr, var), lag))] = 1;
//It's a normalized equation, we have to recompute the derivative using chain rule derivative function*/
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 1;
else
Derivatives[make_pair(make_pair(eqr, eq),make_pair(make_pair(varr, var), lag))] = 0;
//It's a feedback equation we can use the derivatives
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 0;
}
/*}
else if(eq<ModelBlock->Block_List[blck].Nb_Recursives and var<ModelBlock->Block_List[blck].Nb_Recursives)*/
if(var<ModelBlock->Block_List[blck].Nb_Recursives)
{
int eqs = ModelBlock->Block_List[blck].Equation[var];
for(int vars=ModelBlock->Block_List[blck].Nb_Recursives; vars<ModelBlock->Block_List[blck].Size; vars++)
{
int varrs = ModelBlock->Block_List[blck].Variable[vars];
if(Derivatives.find(make_pair(make_pair(eqs, var), make_pair(make_pair(varrs, vars), lag)))!=Derivatives.end())
Derivatives[make_pair(make_pair(eqr, eq),make_pair(make_pair(varrs, vars), lag))] = 2;
//A new derivative need to be computed using the chain rule derivative function (a feedback variable appear in a recursive equation)
if(Derivatives.find(make_pair(make_pair(lag, make_pair(var, vars)), make_pair(eqs, varrs)))!=Derivatives.end())