本文整理汇总了C++中NumericVector::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::erase方法的具体用法?C++ NumericVector::erase怎么用?C++ NumericVector::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericVector
的用法示例。
在下文中一共展示了NumericVector::erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bsearch_boundary
/* Function to run breadth-first search, returning only sets of connected
components that reside on the boundary of the districts */
List bsearch_boundary(List aList,
arma::vec boundary)
{
/* Inputs to function:
aList: adjacency list
boundary: vector of boundary element indicators (as arma)
*/
// Get indices of boundary units
arma::uvec boundary_indices = find(boundary == 1);
// Container - outputted of breadth search, a list
List bsearch;
// Container - partition vector, gets added to bsearch when queue is empty
NumericVector partition;
// Set mark vector - ledger of which indices have been reached
NumericVector mark(aList.size());
// Set queue vector
NumericVector q;
// Initialize breadth search with first element in boundary_indices
mark(boundary_indices(0)) = boundary_indices(0);
partition.push_back(boundary_indices(0));
q = aList(boundary_indices(0));
// Initialize objects inside loop
int u; bool in_part; NumericVector adj_u; int i; int v;
// Begin do{} loop - run until number of elements in boundary_indices is 0
do{
// Begin while{} loop - run until q is empty
while(q.size() > 0){
// Dequeue first element in queue
u = q(0);
// Mark that element in ledger
mark(u) = u;
// Check if element is in the partition - add to partition if false
in_part = is_true(any(partition == u));
if(in_part == false){
partition.push_back(u);
}
// Get adjacency vector for unit u
adj_u = aList(u);
// Loop through elements of adj_u, add to queue and mark if not reached
if(adj_u.size() > 0){
// Start loop
for(i = 0; i < adj_u.size(); i++){
// Reach element v
v = adj_u(i);
/* Check if already reached - if false, mark, add to partition, and
add to queue */
if(is_true(any(mark == v)) == FALSE){
mark(v) = v;
partition.push_back(v);
q.push_back(v);
}
}
}
// Erase dequeued element from queue when done searching
q.erase(q.begin());
}
// Handling an empty queue
if(q.size() == 0){
/* First, find boundary units that are in the reached partition and
remove them from boundary_units vector */
for(i = boundary_indices.n_elem - 1; i >= 0; i--){
if(is_true(any(partition == boundary_indices(i))) == TRUE){
boundary_indices.shed_row(i);
}
}
// Store the partition, clear partition vector
bsearch.push_back(partition);
partition.erase(partition.begin(), partition.end());
// Re-initialize breadth search from new starting value if nonempty
if(boundary_indices.n_elem > 0){
q = aList(boundary_indices(0));
//.........这里部分代码省略.........