📄 rcp_05.cc
字号:
// file: $isip/class/sp/Recipe/rcp_05.cc// version: $Id: rcp_05.cc,v 1.16 2003/04/01 02:06:46 duncan Exp $//// isip include files//#include "Recipe.h"#include <FrontEndBase.h>#include <FtrBuffer.h>#include <Sdb.h>#include <CoefficientLabel.h>#include <AlgorithmContainer.h>// method: findComponent//// arguments:// SingleLinkedList<Component>& comp: (output) the component we find// const FrontEndBase& fend: (input) the FrontEndBase we use// const String& coef_name: (input) coefficient name// // return: a boolean value indicating status//// determine the sequence of processes to apply from the available inputs,// desired output, and graph of recipes.//boolean Recipe::findComponent(SingleLinkedList<Component>& comp_a, const FrontEndBase& fend_a, const String& coef_name_a) { // check the arguments // if (coef_name_a.length() < 1) { return Error::handle(name(), L"findComponent", ERR, __FILE__, __LINE__); } // create an input vector // Vector<String> inputs(1); inputs(0).assign(coef_name_a); // find the component // return findComponent(comp_a, fend_a, inputs);}// method: findComponent//// arguments:// SingleLinkedList<Component>& comp: (output) the recipe we find// const FrontEndBase& fend: (input) the FrontEndBase we use// Vector<String>& inputs: (input) coefficients we need// // return: a boolean value indicating status//// determine from the available inputs, desired output, and graph of// recipes a sequence of processes to apply//boolean Recipe::findComponent(SingleLinkedList<Component>& comp_a, const FrontEndBase& fend_a, Vector<String>& inputs_a) { // check the debug level // if (debug_level_d >= Integral::ALL) { recipe_d.debug(L"recipe"); } // set all nodes to white // recipe_d.setColor(Integral::WHITE); // visit the name of the output // for (long i = inputs_a.length() - 1; i >= 0; i--) { if (!reverseVisitDfs(fend_a, inputs_a(i))) { comp_a.debug(L"comp_a"); fend_a.debug(L"fend_a"); inputs_a.debug(L"inputs_a"); return Error::handle(name(), L"findComponent", ERR_NOPATH, __FILE__, __LINE__); } } // invert the color of all nodes. right now only black nodes are // needed to produce the output for the given inputs. // for (boolean more_nodes = recipe_d.gotoFirst(); more_nodes; more_nodes = recipe_d.gotoNext()) { GraphVertex<Component>* v = (GraphVertex<Component>*)recipe_d.getCurr(); if (recipe_d.getColor(v) == Integral::BLACK) { recipe_d.setColor(v, Integral::WHITE); } else { recipe_d.setColor(v, Integral::BLACK); } } // perform a partial topological sort of the Components // return recipe_d.topologicalSort(comp_a, true);}// method: reverseVisitDfs//// arguments:// const FrontEndBase& fend: (input) the FrontEndBase we use// const String& name: (input) needed coefficient name// // return: a boolean value indicating status: can we produce the named feature?//// determine a path back to all input names from the specified// name. mark all nodes along this path as black, mark intermeadiate// nodes as gray. this allows for a depth-first-search, though it is// backwards through the graph so less efficient.//boolean Recipe::reverseVisitDfs(const FrontEndBase& fend_a, const String& name_a) { // if the name is an available input, of course it can be found // if (fend_a.isNameInput(name_a)) { return true; } // local variables // boolean found = false; boolean unavailable = false; // loop over all vertices // for (boolean more_nodes = recipe_d.gotoFirst(); more_nodes; more_nodes = recipe_d.gotoNext()) { GraphVertex<Component>* v = (GraphVertex<Component>*)recipe_d.getCurr(); // dfs lets us skip over gray vertices // if (recipe_d.getColor(v) == Integral::GREY) { continue; } // is the output of this vertex our desired node? // if (v->getItem()->getOutputName().ne(name_a)) { continue; } // if this is a black node then it already has a path back, good news // if (recipe_d.getColor(v) == Integral::BLACK) { // make sure we don't have multiple paths // if (found) { return Error::handle(name(), L"reverseVisitDfs", ERR_MPATH, __FILE__, __LINE__); } found = true; } // if this is a white node then we should evaluate it // else { // mark the node as seen but not complete // recipe_d.setColor(v, Integral::GREY); // get the needed input names // // Vector<String> input_names; // v->getItem()->getPreName(input_names); unavailable = false; // loop through each input // for (long i = 0; i < v->getItem()->getNumInputs(); i++) { if (!reverseVisitDfs(fend_a, v->getItem()->getInputName(i))) { unavailable = true; break; } } // if all paths back were available, this is a good node // if (!unavailable) { recipe_d.setColor(v, Integral::BLACK); // make sure we don't have multiple paths // if (found) { return Error::handle(name(), L"reverseVisitDfs", ERR_MPATH, __FILE__, __LINE__); } found = true; } } } // return if the path back to input was found // return found;}// method: delayComponent//// arguments:// Vector< SingleLinkedList<Component> >& dcomp: (output) delayed list// FtrBuffer& buf: (output) feature buffer// FrontEndBase& fend: (input) the FrontEndBase we use// SingleLinkedList<Component>& temp_list: (input) list to delay// // return: a boolean value indicating status//// determine from the available inputs, desired output, and graph of// recipes a sequence of processes to apply//boolean Recipe::delayComponent(Vector< SingleLinkedList<Component> >& dcomp_a, FtrBuffer& buf_a, FrontEndBase& fend_a, SingleLinkedList<Component>& temp_list_a) { // loop over the input list // long lag = 0; while (!temp_list_a.isEmpty()) { // set the length // if (lag >= dcomp_a.length()) { dcomp_a.setLength(lag + 1); } // loop over all recipes in the list: // the incremement is at the bottom of the code // for (boolean more_nodes = temp_list_a.gotoFirst(); more_nodes; ) { // declare some temporary variables // Component* algo = temp_list_a.getCurr(); boolean found_algo = true; boolean found_input; Long needed_lag = 0; // get the inputs for this algorithm // long num_inputs = algo->getNumInputs(); // loop over all inputs for this Component // for (long i = 0; found_algo && (i < num_inputs); i++) { found_input = false; long algo_lead_pad = (long)Integral::max(0, algo->getLeadingPad()); // if the coefficient is an input, it has no lag itself // if (fend_a.isNameInput(algo->getInputName(i)) && ((algo->getInputOffset(i) + algo_lead_pad) <= lag)) { if (debug_level_d >= Integral::DETAILED) { String str; str.assign(algo->getOutputName()); str.concat(L":"); str.concat(L"this is an input"); algo->getInputName(i).debug((unichar*)str); } found_input = true; needed_lag.max(algo->getInputOffset(i) + algo_lead_pad); continue; } // if the coefficient is not an input, determine what lag it // has. we are interested in finding the input coefficient // with the largest lag. to find the lag of the coefficient we // will loop through the vector and determine at what point // the coefficient is output (ie, a postName for a Component). // for (long j = 0; (!found_input) && (j <= lag); j++) { // sanity check // if (j >= dcomp_a.length()) { return Error::handle(name(), L"delayComponent", ERR, __FILE__, __LINE__); } // loop through all Components at this delay point to find if // our target coefficient is the output // for (boolean m2 = dcomp_a(j).gotoFirst(); m2; m2 = dcomp_a(j).gotoNext()) { // create a pointer to a Component // Component* j_algo = dcomp_a(j).getCurr(); // get the output name // if (algo->getInputName(i).eq(j_algo->getOutputName()) && ((algo->getInputOffset(i) + algo_lead_pad) <= (lag - j))) { found_input = true; needed_lag.max(lag); } } } if (!found_input) { found_algo = false; } } // move algorithm from temp_list to proper position // if (found_algo) { // see if there are more nodes // if ((algo = temp_list_a.getNext()) != (Component*)NULL) { more_nodes = true; } else { more_nodes = false; } // remove the component // temp_list_a.remove(algo); if (debug_level_d >= Integral::DETAILED) { String num; num.assign(needed_lag); num.concat(L": about to add an algorithm"); num.insert(L"delayComponent", 0); algo->debug((unichar*)num); } // insert the component // dcomp_a(needed_lag).gotoLast(); algo->init(); dcomp_a(needed_lag).insert(algo); if (debug_level_d >= Integral::DETAILED) { String num; num.assign(needed_lag); num.concat(L": added algorithm"); dcomp_a(needed_lag).debug((unichar*)num); } } else { more_nodes = temp_list_a.gotoNext(); } } lag++; } // loop over all remaining components // long needed_size = dcomp_a.length(); for (long i = dcomp_a.length() - 1; i >= 0; i--) { if (dcomp_a(i).length() == 0) { needed_size--; } else { break; } } dcomp_a.setLength(needed_size); // set the output to use the full file-size // Long len = fend_a.getNumFrames(); buf_a.addOrInitLength(buf_a.getCoefName(), len + needed_size); if (debug_level_d >= Integral::ALL) { buf_a.getLength().debug(L"coef_length, step A"); } // loop over all components // for (long i = 0; i < needed_size; i++) { for (boolean more = dcomp_a(i).gotoFirst(); more; more = dcomp_a(i).gotoNext()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -