本文整理汇总了C++中Nodes::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Nodes::push_back方法的具体用法?C++ Nodes::push_back怎么用?C++ Nodes::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nodes
的用法示例。
在下文中一共展示了Nodes::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildnodes
Nodes Region::buildnodes()
{
Nodes Result;
srand(unsigned(time(0)));
if(typ==1)
{
double steph=double(PIXELSH)/numofrows,stepw=double(PIXELSW)/numofcols;
if(numofrows<=numofcols)
{
for(int i=0;i<=numofcols;i++)
for(int j=0;j<=numofrows;j++)
//Result.push_back(Point(stepw*i,steph*j),sqrt(stepw*i*stepw*i+steph*j*steph*j)/PIXELSH*50-50);
//Result.push_back(Point(stepw*i,steph*j),double(rand())/RAND_MAX*200-100);
Result.push_back(Point(stepw*i,steph*j),0);
}
else
{
for(int j=0;j<=numofrows;j++)
for(int i=0;i<=numofcols;i++)
//Result.push_back(Point(stepw*i,steph*j),sqrt(stepw*i*stepw*i+steph*j*steph*j)/PIXELSH*50-50);
//Result.push_back(Point(stepw*i,steph*j),double(rand())/RAND_MAX*200-100);
Result.push_back(Point(stepw*i,steph*j),0);
}
}
return Result;
}
示例2: loadAll
QObjectList loadAll(NodeObjectMap &map) {
Nodes nodes;
Triples candidates = m_s->match(Triple(Node(), Uri("a"), Node()));
foreach (Triple t, candidates) {
if (t.c.type != Node::URI) continue;
nodes.push_back(t.a);
}
LoadState state;
state.requested = nodes;
state.map = map;
state.loadFlags = LoadState::IgnoreUnknownTypes;
collect(state);
load(state);
map = state.map;
QObjectList objects;
foreach (Node n, nodes) {
QObject *o = map.value(n);
if (o) objects.push_back(o);
}
示例3: _stopNodes
void Config::_stopNodes()
{
// wait for the nodes to stop, destroy entities, disconnect
Nodes stoppingNodes;
const Nodes& nodes = getNodes();
for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
{
Node* node = *i;
const State state = node->getState();
if( state != STATE_STOPPED && state != STATE_FAILED )
continue;
LBASSERT( !node->isActive() || state == STATE_FAILED );
if( node->isApplicationNode( ))
continue;
co::NodePtr netNode = node->getNode();
if( !netNode ) // already disconnected
continue;
LBLOG( LOG_INIT ) << "Exiting node" << std::endl;
if( state == STATE_FAILED )
node->setState( STATE_STOPPED );
stoppingNodes.push_back( node );
LBASSERT( netNode.isValid( ));
netNode->send( fabric::CMD_SERVER_DESTROY_CONFIG )
<< getID() << LB_UNDEFINED_UINT32;
netNode->send( fabric::CMD_CLIENT_EXIT );
}
// now wait that the render clients disconnect
uint32_t nSleeps = 50; // max 5 seconds for all clients
for( Nodes::const_iterator i = stoppingNodes.begin();
i != stoppingNodes.end(); ++i )
{
Node* node = *i;
co::NodePtr netNode = node->getNode();
node->setNode( 0 );
if( nSleeps )
while( netNode->isConnected() && --nSleeps )
lunchbox::sleep( 100 ); // ms
if( netNode->isConnected( ))
{
co::LocalNodePtr localNode = getLocalNode();
LBASSERT( localNode.isValid( ));
LBWARN << "Forcefully disconnecting exited render client node"
<< std::endl;
localNode->disconnect( netNode );
}
LBLOG( LOG_INIT ) << "Disconnected node" << std::endl;
}
}
示例4: getNodes
void LocalNode::getNodes( Nodes& nodes, const bool addSelf ) const
{
base::ScopedMutex< base::SpinLock > mutex( _nodes );
for( NodeHash::const_iterator i = _nodes->begin();
i != _nodes->end(); ++i )
{
EQASSERT( i->second->isConnected( ));
if( addSelf || i->second != this )
nodes.push_back( i->second );
}
}
示例5: Nodes
Nodes *av_to_nodes(pTHX_ SV *from_)
{
Nodes *ret = new Nodes();
AV *from = (AV *)((SvROK(from_)) ? SvRV(from_) : from_);
int size = av_len(from);
for (int i = 0; i <= size; i++) {
SV *arg = (SV *)*av_fetch(from, i, FALSE);
ret->push_back(hv_to_node(aTHX_ arg));
}
return ret;
}
示例6: neighbors
static void neighbors(Node *n, Nodes &r, NodePool &p, const Grid &g) {
Tile v[16];
size_t s = g.adjacent(n->tile, v, COUNTOF(v));
r.clear();
for (Tile *t = v; t < v + s; ++t) {
float c = g.get(*t);
if (c > 0.1f) {
Node *a = new (p) Node(*t, c);
r.push_back(a);
}
}
}
示例7: parse_nodes
Nodes Test::parse_nodes(const char *nodes_str) const
{
Nodes nodes;
std::vector<int> array = parse_int_array(nodes_str);
assert(array.size() % 2 == 0);
for (int i = 0; i < array.size(); i += 2) {
int qid(array[i]);
int kid(array[i+1]);
nodes.push_back(Node(qid, kid));
}
return nodes;
}
示例8: build_from_proto
void GraphProtoInterface::build_from_proto(graph::Graph *graph) {
vector <Graphnode *> nodes;
vector <Graphedge *> edges;
int edge_count = 0;
for (int i = 0; i < graph->node_size(); i++) {
const graph::Graph_Node & node = graph->node(i);
for (int j=0; j < node.edge_size(); j++) {
const graph::Graph_Edge& edge = node.edge(j);
edge_count++;
}
}
set_up(*graph, graph->node_size(), edge_count);
for (int i = 0; i < graph->node_size(); i++) {
const graph::Graph_Node & node = graph->node(i);
Graphnode * my_node = new Graphnode(node.id());
my_node->set_label(node.label());
process_node(node, my_node);
nodes.push_back(my_node);
}
uint edge_id = 0;
for (int i = 0; i < graph->node_size(); i++) {
const graph::Graph_Node& node = graph->node(i);
for (int j=0; j < node.edge_size(); j++) {
const graph::Graph_Edge& edge = node.edge(j);
int to_node = edge.to_node();
Graphedge * my_edge = new Graphedge(edge_id, *nodes[node.id()], *nodes[to_node]);
process_edge(edge, my_edge);
//((HypernodeImpl*)_nodes[to_node])->add_edge(forest_edge);
nodes[node.id()]->add_edge(my_edge);
nodes[my_edge->to_node()->id()]->add_in_edge(my_edge);
edge_id++;
edges.push_back(my_edge);
}
}
Nodes * ns = new Nodes ();
Edges * es = new Edges ();
foreach (Graphnode * n, nodes) {
ns->push_back((Node) n);
}
示例9: children
Node::Nodes Node::children() const
{
Nodes childs;
for (Children::const_iterator it = children_.begin(), end = children_.end();
it != end; ++it) {
if (it->is_node()) {
assert(it->node());
childs.push_back(it->node());
}
else {
assert(false);
}
}
return childs;
}
示例10: readNodeFromArchive
osgDB::ReaderWriter::ReadResult readNodeFromArchive(osgDB::Archive& archive, const osgDB::ReaderWriter::Options* options) const
{
osgDB::ReaderWriter::ReadResult result(osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND);
if (!archive.getMasterFileName().empty())
{
result = archive.readNode(archive.getMasterFileName(), options);
}
else
{
osgDB::Archive::FileNameList fileNameList;
if (archive.getFileNames(fileNameList))
{
typedef std::list< osg::ref_ptr<osg::Node> > Nodes;
Nodes nodes;
for(osgDB::Archive::FileNameList::iterator itr = fileNameList.begin();
itr != fileNameList.end();
++itr)
{
result = archive.readNode(*itr, options);
if (result.validNode()) nodes.push_back(result.getNode());
}
if (!nodes.empty())
{
if (nodes.size()==1)
{
result = osgDB::ReaderWriter::ReadResult(nodes.front().get());
}
else
{
osg::ref_ptr<osg::Group> group = new osg::Group;
for(Nodes::iterator itr = nodes.begin();
itr != nodes.end();
++itr)
{
group->addChild(itr->get());
}
result = osgDB::ReaderWriter::ReadResult(group.get());
}
}
}
}
return result;
}
示例11: filter
Nodes Node::filter(const std::string& selector,const std::string& type) const {
std::string xpat;
if(type=="css") xpat = xpath(selector);
else if(type=="xpath") xpat = selector;
else STENCILA_THROW(Exception,"Unknown selector type <"+type+">");
try {
// Select nodes
pugi::xpath_node_set selected = pimpl_->select_nodes(xpat.c_str());
// Construct Nodes from pugi::xpath_node_set
Nodes nodes;
for(pugi::xpath_node_set::const_iterator it = selected.begin(); it != selected.end(); ++it){
nodes.push_back(it->node());
}
return nodes;
} catch (const pugi::xpath_exception& e){
STENCILA_THROW(Exception,e.what());
}
}
示例12: threes
void threes(const Vec2 &point)
{
point.toString();
int l,f,u,d;
l = f = point.x;
u = d = point.y;
PVector tmpX;
PVector tmpY;
WTF node;
node.centre = point;
int countX = 0;
while(--l > 0)
{
if (Map[l][point.y] == Map[point.x][point.y])
{
cout<<l<<" l "<<point.y<<endl;
tmpX.push_back(Vec2(l,point.y));
++countX;
}
else
break;
};
while(++f < xCount)
{
if (Map[f][point.y] == Map[point.x][point.y])
{
cout<<f<<" f "<<point.y<<endl;
tmpX.push_back(Vec2(f,point.y));
++countX;
}
else
break;
};
if (countX>=2)
{
cout<<"X is THREE"<<endl;
node.vecX = tmpX;
}
int countY = 0;
while(--u > 0)
{
if (Map[point.x][u] == Map[point.x][point.y])
{
cout<<point.x<<" u "<<u<<endl;
tmpY.push_back(Vec2(point.x,u));
++countY;
}
else
break;
};
while(++d < yCount)
{
if (Map[point.x][d] == Map[point.x][point.y])
{
cout<<point.x<<" d "<<d<<endl;
tmpY.push_back(Vec2(point.x,d));
++countY;
}
else
break;
};
if (countY>=2)
{
cout<<"Y is THREE"<<endl;
node.vecY = tmpY;
}
bool cross = countX>=2&&countY>=2;
bool five = countX>=4||countY>=4;
bool four = countX>=3||countY>=3;
bool three = countX>=2||countY>=2;
node.p = 0;
if (countX>=2&&countY>=2)
{
node.p |= CROSS;
}
if (countX>=4||countY>=4)
{
node.p |= FIVE;
}
else if (countX>=3||countY>=3)
{
node.p |= FOUR;
}
else if (countX>=2||countY>=2)
{
node.p |= THREE;
}
if (node.p!=0)
{
cout<<"Yes"<<endl;
nodes.push_back(node);
}
}
示例13: distribution
/**
* Takes a subgraph of the given graph (all nodes in the graph with the given label),
* partitions this subgraph into even smaller subgraphs (using something similar to k-means),
* and gives all small subgraphs a unique label (using the given min_label).
*
* @param graph
* @param label_of_connected_component
* @param size_of_largest_partition
* @param min_label_for_partition_labeling
* @return the number of generated partitions
*/
std::size_t
partition_connected_component(UniGraph * graph, std::size_t label_of_connected_component, std::size_t partition_size, std::size_t min_label_for_partition_labeling)
{
typedef std::size_t Node;
typedef std::size_t Label;
typedef std::vector<Node> Nodes;
Nodes nodes;
for (Node node = 0; node < graph->num_nodes(); ++node)
if (graph->get_label(node) == label_of_connected_component)
nodes.push_back(node);
const std::size_t num_partitions = (nodes.size() + partition_size - 1) / partition_size; // division and rounding up
/********* k-means clustering *******/
const std::size_t num_kmeans_iterations = 100;
Nodes centroids;
/* Draw centroids randomly. */
std::default_random_engine generator;
std::uniform_int_distribution<std::size_t> distribution(0, nodes.size() - 1);
for(std::size_t partition = 0; partition < num_partitions; ++partition) {
Node centroid = std::numeric_limits<Node>::max();
while (std::find(centroids.begin(), centroids.end(), centroid) != centroids.end())
centroid = nodes.at(distribution(generator));
centroids.push_back(centroid);
}
for (std::size_t kmeans_iteration = 0; kmeans_iteration < num_kmeans_iterations; ++kmeans_iteration) {
const Label unvisited = std::numeric_limits<Label>::max();
for (Node const & node : nodes)
graph->set_label(node, unvisited);
/* Put centroids into queues. */
std::vector<Nodes> queues(num_partitions);
for (std::size_t i = 0; i < num_partitions; ++i)
queues.at(i).push_back(centroids.at(i));
/* Grow regions starting from centroids */
while (std::any_of(queues.begin(), queues.end(), [](Nodes const & queue){return !queue.empty();})) {
#pragma omp parallel for
for (std::size_t queue_id = 0; queue_id < queues.size(); ++queue_id) {
Nodes & old_queue = queues.at(queue_id);
std::unordered_set<Node> new_queue;
for (Node node : old_queue)
graph->set_label(node, min_label_for_partition_labeling + queue_id); // there is a race condition for partition boundary nodes but we don't care
for (Node node : old_queue) {
/* Copy all unvisited (and not yet inserted) neighbors into new queue. */
for (Node neighbor : graph->get_adj_nodes(node))
if (graph->get_label(neighbor) == unvisited)
new_queue.insert(neighbor);
}
old_queue.clear();
old_queue.insert(old_queue.begin(), new_queue.begin(), new_queue.end());
}
}
/* If we are in the final iteration we stop here to keep the graph labels
* (they would be removed in the following region shrinking step). */
if (kmeans_iteration == num_kmeans_iterations - 1)
break;
/* Put partition boundary nodes into queues. */
for (Node const node : nodes) {
Label const cur_label = graph->get_label(node);
std::size_t const cur_queue = cur_label - min_label_for_partition_labeling;
Nodes const & neighbors = graph->get_adj_nodes(node);
/* Each node, where any of its neighbors has a different label, is a boundary node. */
if (std::any_of(neighbors.begin(), neighbors.end(), [graph, cur_label]
(Node const neighbor) { return graph->get_label(neighbor) != cur_label; } ))
queues.at(cur_queue).push_back(node);
}
/* Shrink regions starting from boundaries to obtain new centroids. */
#pragma omp parallel for
for (std::size_t queue_id = 0; queue_id < queues.size(); ++queue_id) {
Nodes & old_queue = queues.at(queue_id);
while (!old_queue.empty()){
std::unordered_set<Node> new_queue;
for (Node node : old_queue)
graph->set_label(node, unvisited);
for (Node node : old_queue) {
/* Copy all neighbors that have not yet been marked (and have not yet been inserted) into new queue. */
for (Node neighbor : graph->get_adj_nodes(node))
if (graph->get_label(neighbor) == min_label_for_partition_labeling + queue_id)
new_queue.insert(neighbor);
//.........这里部分代码省略.........
示例14: route
void LeaflessOrthoRouter::route(Logger *logger) {
// Set up for logging.
unsigned ln = logger != nullptr ? logger->nextLoggingIndex : 0;
std::function<void(unsigned)> log = [ln, this, logger](unsigned n)->void{
if (logger!=nullptr) {
std::string fn = string_format("%02d_%02d_routing_attempt", ln, n);
std::string path = logger->writeFullPathForFilename(fn);
this->m_ra.router.outputInstanceToSVG(path);
}
};
/*
* We may need to route multiple times to ensure that at least two sides of each node are being used,
* but in theory we should never have to route more than 4n+1 times.
*
* Proof: We always begin with an initial routing. We want to show it could be necessary to re-route
* at most 4n times.
*
* In order to see this, we first argue that the worst-case-scenario for any single node is that it
* require four routings. Consider then some node u all of whose edges have been routed to one side, s0. We
* then pick some edge e0 incident to u, say that it may not connect to side s0, and we re-route for the first time.
*
* While unlikely, it could be that, for whatever reason, now all edges incident to node u are routed to some other side,
* s1. We then pick some edge e1 (could be the same or different from e0), forbid it from connecting to
* side s1, and re-route for a second time.
*
* Again, for whatever reason, all edges could now connect to one
* of the two remaining sides, s2. Continuing in this way, we could be led to re-route a third and a fourth time. But
* prior to the fourth re-routing it would be the case that for each side si of node u, there was
* some edge ei incident to u that had been forbidden from connecting on side si. Therefore on the fourth
* re-routing it would be impossible for all edges to connect on any single side of u.
*
* So much for the case of a single node. However, in again a highly unlikely worst-case-scenario, it could be
* that during the first five routings no other node besides u was a pseudoleaf (had all edges routed to one side),
* but after the fifth some other node became a pseudoleaf. In this way we could be led to do four re-routings
* for each node in the graph. QED
*
* In practice, it would probably be very rare for more that two routings to ever be necessary. For this
* requires the odd circumstance, considered in the proof, that forbidding one edge from connecting on a
* given side somehow results in /all/ edges incident at that node migrating to some other, single side.
*
* In order that our theory be tested, we use an infinite loop with counter and assertion, instead
* of a mere for-loop which would fail silently.
*/
size_t numRoutings = 0;
size_t maxRoutings = 4*m_n + 1;
while (true) {
m_ra.router.processTransaction();
log(++numRoutings);
// As explained in the comments above, at most five routings should ever be needed.
COLA_ASSERT(numRoutings <= maxRoutings);
// For testing purposes, we may want to record the results of
// each routing attempt.
if (recordEachAttempt) {
m_ra.recordRoutes(true);
routingAttemptTglf.push_back(m_graph->writeTglf());
}
// Are there any nodes having all of their edges routed
// out of just one side? This is what we want to prevent.
// Such nodes would become leaves in a planarisation, so we
// call them "pseudoleaves".
Nodes pseudoLeaves;
// For each such Node (if any), there is a sole direction in which
// all connectors depart. We keep track of those directions as we work.
vector<CardinalDir> soleDepartureDirecs;
// Check each Node in the Graph:
for (auto p : m_graph->getNodeLookup()) {
Node_SP &u = p.second;
const EdgesById edgeLookup = u->getEdgeLookup();
// Sanity check, that Node u is not an actual leaf:
COLA_ASSERT(edgeLookup.size() > 1);
// Determine the departure direction from Node u for its first Edge.
auto edge_it = edgeLookup.cbegin();
CardinalDir d0 = departureDir((*edge_it).second, u);
// If two or more directions have been used, some edge must depart
// in a different direction than this one. (For if all the rest equal
// this first one, then all are the same.)
bool isPseudoLeaf = true;
for (auto jt = ++edge_it; jt != edgeLookup.cend(); ++jt) {
CardinalDir d1 = departureDir((*jt).second, u);
if (d1 != d0) {
isPseudoLeaf = false;
break;
}
}
if (isPseudoLeaf) {
pseudoLeaves.push_back(u);
soleDepartureDirecs.push_back(d0);
}
}
// Are there any pseudoleaves?
if (pseudoLeaves.empty()) {
// If there are none, then we're done routing, and can break out of the outer while loop.
break;
} else {
// But if there are still pseudoleaves, then we need to work on them.
for (size_t i = 0; i < pseudoLeaves.size(); ++i) {
// Get the Node and the direction in which all connectors currently depart from it.
Node_SP u = pseudoLeaves[i];
//.........这里部分代码省略.........
示例15: _stopNodes
void Config::_stopNodes()
{
// wait for the nodes to stop, destroy entities, disconnect
Nodes stoppingNodes;
const Nodes& nodes = getNodes();
for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
{
Node* node = *i;
const State state = node->getState();
if( state != STATE_STOPPED && state != STATE_FAILED )
continue;
EQASSERT( !node->isActive() || state == STATE_FAILED );
if( node->isApplicationNode( ))
continue;
co::NodePtr netNode = node->getNode();
if( !netNode ) // already disconnected
continue;
EQLOG( LOG_INIT ) << "Exiting node" << std::endl;
if( state == STATE_FAILED )
node->setState( STATE_STOPPED );
stoppingNodes.push_back( node );
EQASSERT( netNode.isValid( ));
fabric::ServerDestroyConfigPacket destroyConfigPacket;
destroyConfigPacket.configID = getID();
netNode->send( destroyConfigPacket );
ClientExitPacket clientExitPacket;
netNode->send( clientExitPacket );
}
// now wait that the render clients disconnect
uint32_t nSleeps = 50; // max 5 seconds for all clients
for( Nodes::const_iterator i = stoppingNodes.begin();
i != stoppingNodes.end(); ++i )
{
Node* node = *i;
co::NodePtr netNode = node->getNode();
node->setNode( 0 );
if( nSleeps )
while( netNode->isConnected() && --nSleeps )
co::base::sleep( 100 ); // ms
if( netNode->isConnected( ))
{
co::LocalNodePtr localNode = getLocalNode();
EQASSERT( localNode.isValid( ));
EQWARN << "Forcefully disconnecting exited render client node"
<< std::endl;
localNode->disconnect( netNode );
}
EQLOG( LOG_INIT ) << "Disconnected node" << std::endl;
}
}