📄 syst_graph.cpp
字号:
if(used_as_base[sig_num]) continue;
sig_id = (Sdg_Vert_Descr->at(sig_num))->signal_id;
*DebugFile << " " << sig_id->GetName() << endl;
}
#endif
exit(0);
}
#ifdef _DEBUG
sig_id = (Sdg_Vert_Descr->at(base_sig_num))->signal_id;
*DebugFile << "\nbase signal is " << sig_id->GetName() << endl;
#endif
//---------------------------------------------------------
// Work down the column corresponding to the base signal to
// find inbound edges. For each edge found, attempt to
// propagate parameters back to the edge's source signal
for( sig_num = 0; sig_num < num_nodes; sig_num++)
{
edge_num = Sig_Dep_Graph->GetEdgeNum( sig_num, base_sig_num );
if(edge_num < 0 ) continue;
//
//else
is_forward = false;
#ifdef _DEBUG
sig_id = (Sdg_Vert_Descr->at(sig_num))->signal_id;
*DebugFile << "looking backward to " << sig_id->GetName() << endl;
#endif
Propagate( base_sig_num, edge_num, sig_num, is_forward);
}
//-------------------------------------------------------------
// Work across the row corresponding to the base signal to
// find outbound edges. For each edge found, attempt to
// propagate parameters forward to the edge's destination signal.
for( sig_num = 0; sig_num < num_nodes; sig_num++)
{
edge_num = Sig_Dep_Graph->GetEdgeNum( base_sig_num, sig_num );
if(edge_num < 0 ) continue;
//
//else
is_forward = true;
#ifdef _DEBUG
sig_id = (Sdg_Vert_Descr->at(sig_num))->signal_id;
*DebugFile << "looking forward to " << sig_id->GetName() << endl;
#endif
Propagate( base_sig_num, edge_num, sig_num, is_forward);
}
} // end of while(num_base_sigs_used < Num_Regular_Sigs)
return;
}
//============================================================
void SystemGraph::TopoSortSDG(void)
{
int num_nodes = Sig_Dep_Graph->GetNumVerts();
Sorted_Sig_Nodes = new int[num_nodes];
for(int i=0; i<num_nodes; i++)
{
Sorted_Sig_Nodes[i] = i;
}
return;
}
//=======================================================================
void SystemGraph::Propagate( int base_sig_num,
int edge_num,
int sig_num,
bool is_forward )
{
double t_base, t_sig;
double r_edge;
int n_base, n_sig;
int r_def, t_def, n_def;
int config_key;
bool is_const_intvl;
t_base = (Sdg_Vert_Descr->at(base_sig_num))->samp_intvl;
n_base = (Sdg_Vert_Descr->at(base_sig_num))->block_size;
r_edge = (Sdg_Edge_Descr->at(edge_num))->resamp_rate;
is_const_intvl = (Sdg_Edge_Descr->at(edge_num))->is_const_intvl;
t_sig = (Sdg_Vert_Descr->at(sig_num))->samp_intvl;
n_sig = (Sdg_Vert_Descr->at(sig_num))->block_size;
r_def = 0;
t_def = 0;
n_def = 0;
if( r_edge > 0.0 ) r_def = 1;
if( t_sig > 0.0) t_def = 2;
if( n_sig >0 ) n_def = 4;
config_key = r_def + t_def + n_def;
if(is_forward) config_key +=8;
if(is_const_intvl) config_key +=16;
switch (config_key)
{
case 0: //backward, nothing defined
// no action possible
#ifdef _DEBUG
*DebugFile << " case 0 - no action possible" << endl;
#endif
return;
case 1: //backward, resampling rate is defined
// compute sampling rate : Tn = R * Tb
// compute block size : Nn = Nb / R
t_sig = r_edge * t_base;
n_sig = int(n_base / r_edge);
#ifdef _DEBUG
*DebugFile << " case 1:\n"
<< " new samp intvl = " << t_sig
<< " new block size = " << n_sig
<< endl;
#endif
break;
case 2: //backward, sampling interval defined
// compute resampling rate : R = Tn / Tb
// compute block size : Nn = Nb / R
r_edge = t_sig/t_base;
n_sig = int(n_base/r_edge);
#ifdef _DEBUG
*DebugFile << " case 2:\n"
<< " new block size = " << n_sig
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 3: //backward, resampling rate and
//sampling interval are defined
// compute block size : Nn = Nb / R
// check sampling interval : (Tn == R * Tb)?
n_sig = int(n_base / r_edge);
if( t_sig != (r_edge * t_base))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 3" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent input/output sampling intervals" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 3:\n"
<< " new block size = " << n_sig
<< endl;
#endif
break;
case 4: //backward, block size is defined
// compute resampling rate : R = Nb / Nn
// compute sampling interval : Tn = R * Tb
r_edge = float(n_base) / n_sig;
t_sig = r_edge * t_base;
#ifdef _DEBUG
*DebugFile << " case 4:\n"
<< " new samp interval = " << t_sig
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 5: //backward, resampling rate and block size defined
// compute sampling interval : Tn = R * Tb
// check block size : (Nb == R * Nn)?
t_sig = r_edge * t_base;
if( n_base != (r_edge * n_sig))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 5" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output block sizes" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 5:\n"
<< " new samp interval = " << t_sig
<< endl;
#endif
break;
case 6: //backward, sampling interval and block size defined
// compute resampling rate : R = Tn / Tb
// check block size : (Nb == R * Nn)?
r_edge = t_sig / t_base;
if( n_base != (r_edge * n_sig))
{ //error
#ifdef _DEBUG
*DebugFile << " error in case 6" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output block sizes" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 6:\n"
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 7: //backward, all parameters are defined
// check : (Tn == R * Tb)?
// check : (Nb == R * Nn)?
if( t_sig != (r_edge * t_base))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 7a" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output sampling intervals" << endl;
exit(0);
}
if( n_base != ceil(r_edge * n_sig))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 7b" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output block sizes" << endl;
ErrorStream << "n_base = " << n_base << endl;
ErrorStream << "r_edge = " << r_edge << endl;
ErrorStream << "n_sig = " << n_sig << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 7 - all parameters defined" << endl;
#endif
break;
case 8: //forward, nothing defined
// no action possible
#ifdef _DEBUG
*DebugFile << " case 8 - no action possible" << endl;
#endif
return;
case 9: //forward, resampling rate is defined
// compute sampling interval : Tn = Tb / R
// compute block size : Nn = R * Nb
t_sig = t_base / r_edge;
n_sig = int(ceil(r_edge * n_base));
#ifdef _DEBUG
*DebugFile << " case 9:\n"
<< " new samp interval = " << t_sig
<< " new block size = " << n_sig
<< endl;
#endif
break;
case 10: //forward, sampling interval defined
// compute resampling rate : R = Tb / Tn
// compute block size : Nn = R * Nb
r_edge = t_base / t_sig;
n_sig = int(r_edge * n_base);
#ifdef _DEBUG
*DebugFile << " case 10:\n"
<< " new block size = " << n_sig
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 11: //forward, resampling rate and
// sampling interval defined
// compute block size : Nn = R * Nb
// check sampling interval : (Tb == R * Tn)?
n_sig = int(r_edge * n_base);
if(t_base != r_edge * t_sig)
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 11" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output sampling intervals" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 11:\n"
<< " new samp interval = " << t_sig
<< " new block size = " << n_sig
<< endl;
#endif
break;
case 12: //forward, block size is defined
// compute resampling rate : R = Nn / Nb
// compute sampling interval : Tn = Tb / R
r_edge = n_sig / n_base;
t_sig = t_base / r_edge;
#ifdef _DEBUG
*DebugFile << " case 12:\n"
<< " new samp interval = " << t_sig
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 13: //forward, resampling rate and
// block size are defined
// compute sampling interval : Tn = Tb / R
// check block size : (Nn == R * Nb)?
t_sig = t_base / r_edge;
if(n_sig != (r_edge * n_base))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 13" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output block sizes" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 13:\n"
<< " new samp interval = " << t_sig
<< endl;
#endif
break;
case 14: //forward, sampling interval and
// block size are defined
// compute resampling rate : R = Tb / Tn
// check block size : (Nn == R * Nb)?
r_edge = t_base / t_sig;
if( n_sig != (r_edge * n_base))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 14" << endl;
*DebugFile << " ( n_sig != (r_edge * n_base))" << endl;
*DebugFile << " n_sig = " << n_sig << endl;
*DebugFile << " r_edge = " << r_edge << endl;
*DebugFile << " n_base = " << n_base << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
ErrorStream << "resampling rate in instance '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetInstanceName()
<< "' of model '"
<< ((Sdg_Edge_Descr->at(edge_num))->model_id)->GetModelName()
<< "'\n is inconsistent with input/output block sizes" << endl;
exit(0);
}
#ifdef _DEBUG
*DebugFile << " case 14:\n"
<< " new resamp rate = " << r_edge
<< endl;
#endif
break;
case 15: //forward, all parameters are defined
// check : (Tb == R * Tn)?
// check : (Nn == R * Nb)?
if( t_base != (r_edge * t_sig))
{ // error
#ifdef _DEBUG
*DebugFile << " error in case 15a" << endl;
#endif
ErrorStream << "\n\n********* FATAL ERROR ************" << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -