📄 ssrch_11.cc
字号:
// loop over all current traces and create the next level's traces // while (!trace_lists_d(level_num_a).isEmpty()) { // get the current vertex in the search graph // trace_lists_d(level_num_a).removeFirst(curr_trace); // delete this trace if it is now inactive // if (!curr_trace->isActive()) { // bump the current trace off of the trace list and delete it // and its backpath if necessary // Trace::deleteTrace(curr_trace, true); } // if it is active then propagate it // else { // get the current history and its central vertex // Context curr_context(*curr_trace->getHistory()->peek()); curr_vert = curr_context.getCentralVertex(); // if this vertex has a subgraph then descend and create the traces // at the next level // if (!curr_vert->isStart() && !curr_vert->isTerm()) { // we are propagating paths so set status to true // status = true; // get the subgraph's start vertex // SearchLevel& sl_curr = getSearchLevel(level_num_a); SearchLevel& sl_lower = getSearchLevel(level_num_a + 1); // convert context vertices to search symbol indices // we need to do it before hashing in getSubGraphIndex // curr_context.convert(); Ulong* subgr_ind = sl_curr.getSubGraphIndex(curr_context); if (subgr_ind == (Ulong*)NULL) { // throw an error message and exit // String out(L"propagateTracesDown - no subgraph for context: "); curr_context.debug(L"undefined context"); curr_trace->getHistory()->peek()->print(); Console::put(out); return Error::handle(name(), L"propagateTracesDown", Error::ARG, __FILE__, __LINE__); } // get the subgraph start vertex // tmp_vert = (sl_lower.getSubGraph((long)*subgr_ind)).getStart(); // loop over all paths in the subgraph and create new traces in the // next level // for (boolean more_paths = tmp_vert->gotoFirst(); more_paths; more_paths = tmp_vert->gotoNext()) { long central_pos = getSearchLevel(level_num_a + 1).getRightContext() + 1; long left_context_length = getSearchLevel(level_num_a + 1).getLeftContext(); long total_context_length = left_context_length + central_pos; // initialize left vertices of the context // Context left_context(total_context_length, central_pos); for (long i = 0; i < left_context_length; i++) { left_context.assignAndAdvance((ulong)tmp_vert); } // initialize central vertex of the context // GraphArc<SearchNode>* tmp_arc = tmp_vert->getCurr(); GraphVertex<SearchNode>* target_vertex = tmp_arc->getVertex(); left_context.assignAndAdvance((ulong)target_vertex); // output the debugging information // if (debug_level_d >= Integral::ALL) { String out; left_context.print(); Console::put(out); } // generate list of all possible right contexts // DoubleLinkedList<Context> right_context_list; right_context_list.setAllocationMode(DstrBase::USER); long depth = getSearchLevel(level_num_a + 1).getRightContext(); generateRightContexts(right_context_list, left_context, depth); // output the debugging information // if (debug_level_d >= Integral::ALL) { String output(L"Generated contexts for depth"); output.concat(depth); Console::put(output); long num = 0; for (boolean more_items = right_context_list.gotoFirst(); more_items; more_items = right_context_list.gotoNext()) { num++; String out(L" "); out.concat(num); out.concat(L":"); String cont; right_context_list.getCurr()->print(); out.concat(cont); Console::put(out); } } // generate a new trace for each right context // for (boolean more_items = right_context_list.gotoFirst(); more_items; more_items = right_context_list.gotoNext()) { // create a new trace // next_trace = new Trace(*curr_trace); next_trace->setFrame((ulong)current_frame_d); // update the score with the arc score // next_trace->setScore(next_trace->getScore() + tmp_arc->getWeight()); // add to the history // next_trace->getHistory()->push(right_context_list.getCurr()); // add the trace to the search node's trace list. // Trace* existing_trace = (Trace*)NULL; SearchNode* next_node = next_trace->getHistory()->peek()->getCentralVertex()->getItem(); if (next_node->addTrace(next_trace, current_frame_d, existing_trace)) { // set the backpointer // next_trace->setBackPointer(curr_trace); // add the trace to the next level's trace list // trace_lists_d(level_num_a + 1).insertLast(next_trace); if (debug_level_d >= Integral::ALL) { printNewPath(next_trace, curr_trace); } } else { // delete the trace since there is existing trace - same history // if (debug_level_d >= Integral::ALL) { printDeletedPath(next_trace, curr_trace); } delete next_trace; } } // clean the right contexts list // right_context_list.setAllocationMode(DstrBase::SYSTEM); right_context_list.clear(); } // bump the current trace off of the trace list // if (curr_trace->getRefCount() < 1) { Trace::deleteTrace(curr_trace, true); } trace_lists_d(level_num_a).gotoFirst(); } // else if there is no subgraph for this node, we extend the search // along this level. for now, we don't allow a level to completely // skip sub-levels so if we get to the end of the graph at this level // we simply stop // else { boolean more_paths = curr_vert->gotoFirst(); if (more_paths) { status = true; } for ( ; more_paths; more_paths = curr_vert->gotoNext()) { // create a new trace // next_trace = new Trace(*curr_trace); next_trace->setFrame((ulong)current_frame_d); // update the score with the arc score // GraphArc<SearchNode>* tmp_arc = curr_vert->getCurr(); score = next_trace->getScore() + tmp_arc->getWeight(); next_trace->setScore(score); // update the history with the next node at this level // GraphVertex<SearchNode>* target_vertex = tmp_arc->getVertex(); next_trace->getHistory()->peek() ->assignAndAdvance((ulong)target_vertex); // add the trace to the search node's trace list to make sure we // propagate it before exiting // Trace* existing_trace = (Trace*)NULL; SearchNode* next_node = next_trace->getHistory()->peek()->getCentralVertex()->getItem(); if (next_node->addTrace(next_trace, current_frame_d, existing_trace)) { // set the backpointer // next_trace->setBackPointer(curr_trace); // add the trace to this level's trace list // trace_lists_d(level_num_a).insertLast(next_trace); if (debug_level_d >= Integral::ALL) { printNewPath(next_trace, curr_trace); } } else { // delete the trace since there is existing trace - same history // if (debug_level_d >= Integral::ALL) { printDeletedPath(next_trace, curr_trace); } delete next_trace; } } // bump the current trace off of the trace list // if (curr_trace->getRefCount() < 1) { Trace::deleteTrace(curr_trace, true); } trace_lists_d(level_num_a).gotoFirst(); } } } } // exit gracefully // return status;}// method: beamPruneTrace//// arguments:// long level_num: (input) the level for which we will propagate traces//// return: logical error status.//boolean StackSearch::beamPruneTrace(long level_num_a) { // define local variables // Trace* curr_trace = (Trace*)NULL; float threshold = max_frame_scores_d(current_frame_d, level_num_a) - search_levels_d(level_num_a).getBeamThreshold(); float curr_score; long pruned_traces = 0; long orig_length = trace_lists_d(level_num_a).length(); // loop over all active traces at this level // boolean more_traces = trace_lists_d(level_num_a).gotoFirst(); while (more_traces) { curr_trace = trace_lists_d(level_num_a).getCurr(); curr_score = curr_trace->getScore(); if (curr_score > max_frame_scores_d(current_frame_d, level_num_a)) { return Error::handle(name(), L"beamPrune -- bad maximal score!", Error::ARG, __FILE__, __LINE__); } // prune the traces with too low score // if (curr_score < threshold) { if (debug_level_d >= Integral::DETAILED) { String output(L"score is SMALLER than threshold:"); output.concat(curr_score); output.concat(L" trace:" ); output.concat(curr_trace); Console::put(output); } if (trace_lists_d(level_num_a).isLast()) { more_traces = false; } // bump the current trace off of the trace list // trace_lists_d(level_num_a).remove(); if (curr_trace->getRefCount() < 1) { Trace::deleteTrace(curr_trace, true); } pruned_traces++; } else { if (debug_level_d >= Integral::DETAILED) { String output(L"score is NOT smaller than threshold:"); output.concat(curr_score); output.concat(L" trace:" ); output.concat(curr_trace); Console::put(output); } more_traces = trace_lists_d(level_num_a).gotoNext(); } } if (debug_level_d >= Integral::DETAILED) { // print the debugging information // String output(L"Pf:"); output.concat(current_frame_d); output.concat(L" lv:"); output.concat(level_num_a); output.concat(L" orig_tr:"); output.concat(orig_length); output.concat(L" PR_tr*"); output.concat(pruned_traces); output.concat(L" res_tr:"); output.concat(trace_lists_d(level_num_a).length()); output.concat(L" thr:"); output.concat(threshold); output.concat(L" max_sc:"); output.concat(max_frame_scores_d(current_frame_d, level_num_a)); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -