//---------------------------------------------------------------------- // Connecting a node //---------------------------------------------------------------------- NodePtr LocalNode::connect( const NodeID& nodeID ) { EQASSERT( nodeID != NodeID::ZERO ); EQASSERT( _state == STATE_LISTENING ); Nodes nodes; getNodes( nodes ); for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i ) { NodePtr peer = *i; if( peer->getNodeID() == nodeID && peer->isConnected( )) // early out return peer; } for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i ) { NodePtr peer = *i; NodePtr node = _connect( nodeID, peer ); if( node.isValid( )) return node; } EQWARN << "Node " << nodeID << " connection failed" << std::endl; return 0; }
bool TypeHierarchy::closure(Graph & gr,GI & gi,Nodes & vs,GI & gs,const TypeRef * t) { if(gi == gr.end()) { return false; }; if(*(gi->first) == *t) { for(Nodes::const_iterator i = vs.begin();i != vs.end();++i) { gs->second.insert(*i); //insert(vs.begin(),vs.end()); }; //gs->second.insert(vs.begin(),vs.end()); return true; }; for(Nodes::iterator n = gi->second.begin();n != gi->second.end();++n) { if(vs.find(*n) == vs.end()) { vs.insert(*n); GI tmp = gr.find(*n); if(closure(gr,tmp,vs,gs,t)) return true; }; }; return false; };
int main() { boost::archive::text_oarchive oa(std::cout); using namespace Input::EMMA; Nodes nodes; nodes.address = "Mr."; nodes.country = "Puerto Mazarique"; nodes.insert(nodes.end(), Node{"John", "Doe"}); nodes.insert(nodes.end(), Node{"Jane", "Greenwalt"}); nodes.insert(nodes.end(), Node{"Morgan", "Cheese"}); nodes.insert(nodes.end(), Node{"Walton", "Whiz"}); oa << nodes; }
static bool checkDesired(vpsc::Dim dim, const Nodes& nodes, const Rectangles& targets, const ResizeMap& resizeMap) { for (Nodes::const_iterator i=nodes.begin();i!=nodes.end();++i) { const Node* v=*i; const unsigned id=v->id; const Rectangle* t=targets[id]; ResizeMap::const_iterator j=resizeMap.find(id); if(j==resizeMap.end()) { COLA_ASSERT(approx_equals(v->var->desiredPosition, t->getCentreD(dim))); } } for(ResizeMap::const_iterator j=resizeMap.begin();j!=resizeMap.end();++j) { const unsigned id=j->first; const ResizeInfo& ri=j->second; COLA_ASSERT(ri.orig->id==id); const Node *ln=ri.lhsNode, *cn=nodes[id], *rn=ri.rhsNode; COLA_ASSERT(ln->id==id); COLA_ASSERT(cn->id==id); COLA_ASSERT(rn->id==id); const Rectangle* t=targets[id]; const double lp = t->getMinD(dim) + DW2, cp = t->getCentreD(dim), rp = t->getMaxD(dim) - DW2; COLA_ASSERT(approx_equals(lp,ln->var->desiredPosition)); COLA_ASSERT(approx_equals(cp,cn->var->desiredPosition)); COLA_ASSERT(approx_equals(rp,rn->var->desiredPosition)); } return true; }
Nodes NetworkManager::getNodeCandidates() { Nodes result; while ( !depthSearcher->isExhausted() ) { Elements elements = depthSearcher->getElementCandidates(); cerr << "[NM]\tDepth search returned " << elements.size() << endl; for ( Elements::iterator i = elements.begin(); i != elements.end(); i++ ) { Element * element = *i; if ( ! element->isNode() ) continue; Node * node = (Node *) element; if ( rejectedNodes.find(node) != rejectedNodes.end() ) continue; result.insert(node); } depthSearcher->increaseSearchSpace(); if ( !result.empty() ) break; } rejectedNodes.insert(result.begin(), result.end()); cerr << "[NM]\tPrepared " << result.size() << " candidates" << endl; return result; }
//--------------------------------------------------------------------------- // identifier master node mapping //--------------------------------------------------------------------------- NodeID ObjectStore::_findMasterNodeID( const base::UUID& identifier ) { EQ_TS_NOT_THREAD( _commandThread ); // OPT: look up locally first? Nodes nodes; _localNode->getNodes( nodes ); // OPT: send to multiple nodes at once? for( Nodes::iterator i = nodes.begin(); i != nodes.end(); i++ ) { NodePtr node = *i; EQLOG( LOG_OBJECTS ) << "Finding " << identifier << " on " << node << std::endl; NodeFindMasterNodeIDPacket packet; packet.requestID = _localNode->registerRequest(); packet.identifier = identifier; node->send( packet ); NodeID masterNodeID = base::UUID::ZERO; _localNode->waitRequest( packet.requestID, masterNodeID ); if( masterNodeID != base::UUID::ZERO ) { EQLOG( LOG_OBJECTS ) << "Found " << identifier << " on " << masterNodeID << std::endl; return masterNodeID; } } return base::UUID::ZERO; }
void Node::print(const string& connect) { for (CNodeIter iter = m_nodes.begin(); iter != m_nodes.end(); ++iter) { Node* pNode = *iter; CNodeIter next = iter; ++next; if (next != m_nodes.end()) { cout << connect << "+---" << pNode->name() << endl; pNode->print(connect + "| "); } else { cout << connect << "\\---" << pNode->name() << endl; pNode->print(connect + " "); } } }
bool OSR::isNoArrayInLoop(LoopNode* lnode, SsaOpnd* iv) { Nodes nodes = lnode->getNodesInLoop(); StlVector < Node* >::iterator iter = nodes.begin(), end = nodes.end(); for (; iter != end; iter++) { Node* node = *iter; Inst* last_inst = (Inst*) node->getLastInst(); for (Inst* iter1 = (Inst*) node->getFirstInst(); iter1 != last_inst; iter1 = iter1->getNextInst()) { Inst inst = *iter1; if (inst.getOpcode() == Op_AddScaledIndex) { Opnd* opnd = inst.getSrc(1); findLeadingOpnd(&inst, (SsaOpnd*) opnd); SsaOpnd* lop = getLeadingOperand((SsaOpnd*) opnd); if (lop != 0) { SsaOpnd* ivlop = getLeadingOperand(iv); if (lop == ivlop) { return false; } } } } } return true; }
void VirtualMachinesAssigner::getAvailableNodeAssignments(Element* element, std::map<Node*, std::vector<Node*> >& VMsOnNode, std::map<Node*, Assignment* >& vmAssignment, Assignment* assignment) { Nodes::iterator nodesIt = network->getNodes().begin(); Nodes::iterator nodesItEnd = network->getNodes().end(); for ( ; nodesIt != nodesItEnd; ++nodesIt ) { // inserting only vms with capacity less then the element's one VMsOnNode[*nodesIt] = std::vector<Node *>(); // going through all other assigned requests RequestAssignment::iterator it = requestAssignment.begin(); RequestAssignment::iterator itEnd = requestAssignment.end(); for ( ; it != itEnd; ++it ) { Nodes vms = it->second->GetAssigned(*nodesIt); Nodes::iterator vmIt = vms.begin(); Nodes::iterator vmItEnd = vms.end(); for ( ; vmIt != vmItEnd; ++vmIt ) { VMsOnNode[*nodesIt].push_back(*vmIt); vmAssignment[*vmIt] = it->second; } } } }
static void PrintNodes(std::ostream &str, const Nodes &nodes) { for (typename Nodes::const_iterator i = nodes.begin(); i != nodes.end(); i++) { PrintSimplex(str, (*i)->simplex); } }
static void Compute(Nodes &nodes, AccSubAlgorithm accSubAlgorithm, AccTest *accTest) { #ifdef ACCSUB_TRACE Timer::TimeStamp("ComputationsParallelOMP start"); Timer::Time start = Timer::Now(); if (accSubAlgorithm == AccSubAlgorithm::AccSubIG) { std::cout<<"using AccSubIG"<<std::endl; } else { std::cout<<"using AccSubST"<<std::endl; } #endif #pragma omp parallel for for (typename Nodes::iterator i = nodes.begin(); i != nodes.end(); i++) { ComputationsLocal<PartitionGraph>::CreateIncidenceGraph(*i, accSubAlgorithm, accTest); #ifdef ACCSUB_TRACE Timer::TimeStamp("incidence graph calculated"); #endif } #ifdef ACCSUB_TRACE Timer::TimeStamp("ComputationsParallelOMP end"); Timer::TimeFrom(start, "total distributed computations"); #endif }
const set<const TypeRef *> & TypeHierarchy::leaves(PTypeRef & t) { static Nodes empty; GI gi = leafNodes.find(&t); if(gi != leafNodes.end()) { return (gi->second); }; gi = downGraph.find(&t); if(gi == downGraph.end()) return empty; Nodes ns; PTypeRef pt(0); closure(downGraph,gi,ns,gi,&pt); Nodes ms; for(Nodes::const_iterator i = ns.begin();i != ns.end();++i) { Nodes xs; gi = downGraph.find(*i); closure(downGraph,gi,xs,gi,&pt); if(xs.empty()) ms.insert(*i); }; leafNodes[downGraph.find(&t)->first] = ms; return leafNodes[downGraph.find(&t)->first]; };
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; } }
int Test::count_per_qid(const Nodes& nodes, const Qid& qid) const { int count = 0; for (Nodes::const_iterator ni = nodes.begin(); ni != nodes.end(); ++ni) { if (ni->qid == qid) ++count; } return count; }
static void PrintAccSub(std::ostream &str, const Nodes &nodes) { for (typename Nodes::const_iterator i = nodes.begin(); i != nodes.end(); i++) { if ((*i)->IsInAccSub()) { PrintSimplex(str, *((*i)->simplex)); } } str<<std::endl; }
void split() { Nodes nodes; Edges es; printf("test: bend2()\n"); addNode(nodes,100,100,40,20); addNode(nodes,100,130,40,20); addNode(nodes,70,160,40,20); addNode(nodes,180,190,40,20); EdgePoints p1; addToPath(p1,nodes[0],EdgePoint::CENTRE); addToPath(p1,nodes[1],EdgePoint::BL); addToPath(p1,nodes[1],EdgePoint::TL); addToPath(p1,nodes[3],EdgePoint::CENTRE); es.push_back(new Edge(100,p1)); EdgePoints p2; addToPath(p2,nodes[2],EdgePoint::CENTRE); addToPath(p2,nodes[3],EdgePoint::CENTRE); es.push_back(new Edge(50,p2)); const size_t V = nodes.size(); vpsc::Constraints cs; vpsc::Variables vs; getVariables(nodes,vs); { // scope for t, so that t gets destroyed before es TopologyConstraints t(vpsc::HORIZONTAL,nodes,es,vs,cs); writeFile(nodes,es,"split-0.svg"); // test computeStress double stress=t.computeStress(); printf("Stress=%f\n",stress); //assert(fabs(expectedStress-stress)<1e-4); valarray<double> g(V); cola::SparseMap h(V); for(unsigned i=1;i<5;i++) { g=0; h.clear(); t.gradientProjection(g,h); stringstream ss; ss << "split-" << i << ".svg"; writeFile(nodes,es,ss.str().c_str()); } } for_each(nodes.begin(),nodes.end(),delete_node()); for_each(es.begin(),es.end(),delete_object()); for_each(cs.begin(),cs.end(),delete_object()); for_each(vs.begin(),vs.end(),delete_object()); }
//Directory string Directory::path() const { ostringstream oss; Nodes nodes = pathFromRoot(); for (auto node = nodes.begin(); node != nodes.end(); ++node) { if (node != nodes.begin()) oss << "/"; oss << (*node)->name; } return oss.str(); }
void NetworkManager::setSearchSpace(const Nodes & nodes) { rejectedNodes.clear(); rejectedStores.clear(); Elements elements; for (Nodes::iterator i = nodes.begin(); i != nodes.end(); i++) { elements.insert(*i); } depthSearcher = new DepthSearcher(network, elements); }
int Test::count_overlap_kid(const Nodes& nodes) const { std::map<Kid,int> counter; for (Nodes::const_iterator ni = nodes.begin(); ni != nodes.end(); ++ni) { counter[ni->kid]++; } int count = 0; for (std::map<Kid,int>::const_iterator ki = counter.begin(); ki != counter.end(); ++ki) { if (ki->second > 1) ++count; } return count; }
string filename() { ostringstream oss; Nodes nodes = pathFromRoot(); for (auto node = nodes.begin(); node != nodes.end(); ++node) { if (node != nodes.begin()) oss << "/"; oss << (*node)->name; } return oss.str(); }
void write_vertices(Nodes const& nodes, string vertex_filename) { ofstream of(vertex_filename.c_str()); give_wide_permissions(vertex_filename.c_str()); for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it != end; ++it) { of << (*it)->pos()[0] << " " << (*it)->pos()[1] << " " << (*it)->pos()[2] << endl; } }
/** * Applies the required resizes to nodes in the specified axis, rerouting edges * around the resized nodes. * @param dim axis * @param targets the target rectangles (in both axes) * @param nodes to be moved and/or resized * @param edges to be rerouted around nodes * @param resizes ResizeInfo for specific nodes * @param vs canonical list of variables passed into solver. Note that * the first nodes.size() variables are used for each corresponding node. * Note also that new variables for the dummy nodes will be appended to this * list and will need to be cleaned up later. * @param cs canonical list of constraints over variables. Note that new * non-overlap constraints may be appended to the end of this list. */ static void resizeAxis(vpsc::Dim dim, const Rectangles& targets, Nodes& nodes, Edges& edges, RootCluster *clusters, ResizeMap& resizes, Variables& vs, Constraints& cs) { COLA_ASSERT(vs.size()>=nodes.size()); // - create copy tn of topologyNodes with resize rects replaced with // three nodes: one for the lhs of rect, one for centre and one for rhs. // lhs node goes at position of replaced node, the others are appended // to end of tn. // - set desired positions of each lhs node to be the left side // of resized rect and symmetric for rhs node, centre node's desired // pos it at the centre Nodes tn(nodes.size()); COLA_ASSERT(assertConvexBends(edges)); COLA_ASSERT(assertNoSegmentRectIntersection(nodes,edges)); transform(nodes.begin(),nodes.end(),tn.begin(), TransformNode(dim, targets,resizes,vs)); feach(resizes, CreateLeftRightDummyNodes(dim,targets,tn,vs)); COLA_ASSERT(tn.size()==nodes.size()+2*resizes.size()); COLA_ASSERT(vs.size()>=tn.size()); // update topologyRoutes with references to resized nodes replaced with // correct references to lhs/rhs nodes feach(edges,SubstituteNodes(dim,resizes,tn)); COLA_ASSERT(assertConvexBends(edges)); COLA_ASSERT(assertNoSegmentRectIntersection(tn,edges)); // move nodes and reroute topology::TopologyConstraints t(dim, tn, edges, clusters, vs, cs); COLA_ASSERT(checkDesired(dim,tn,targets,resizes)); #ifndef NDEBUG unsigned loopCtr=0; #endif while(t.solve()) { COLA_ASSERT(++loopCtr<1000); } //COLA_ASSERT(checkFinal(tn,targets,resizes)); // reposition and resize original nodes feach(nodes,CopyPositions(dim,tn,resizes)); // revert topologyRoutes back to original nodes feach(edges,RevertNodes(nodes)); COLA_ASSERT(assertConvexBends(edges)); COLA_ASSERT(assertNoSegmentRectIntersection(nodes,edges)); // clean up feach(tn,DeleteTempNode()); }
/** * Find an overlap free arrangement of resized rectangles and reroute * edges around them without changing topology. * @param nodes topology node definitions to be resized * @param edges edges to be reroutes * @param resizes list of resizes to be applied to nodes * @param xvs horizontal vars list * @param xcs horizontal constraints * @param yvs vertical vars * @param ycs vertical constraints */ void applyResizes(Nodes& nodes, Edges& edges, RootCluster *clusters, ResizeMap& resizes, Variables& xvs, Constraints& xcs, Variables& yvs, Constraints& ycs) { // targets will hold an overlap free placement of the resized rectangles Rectangles targets(nodes.size()); // rectangles that are resized should be fixed when finding overlap free placement // the following is populated with their ids set<unsigned> fixed; transform(nodes.begin(),nodes.end(),targets.begin(),CreateTargetRect(resizes,fixed)); removeoverlaps(targets,fixed); resizeAxis(vpsc::XDIM, targets, nodes, edges, clusters, resizes, xvs, xcs); resizeAxis(vpsc::YDIM, targets, nodes, edges, clusters, resizes, yvs, ycs); feach(targets,delete_object()); }
void LocalNode::addListener( ConnectionPtr connection ) { EQASSERT( isListening( )); EQASSERT( connection->isListening( )); connection->ref( CO_REFERENCED_PARAM ); NodeAddListenerPacket packet( connection ); Nodes nodes; getNodes( nodes ); for( Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i ) { (*i)->send( packet, connection->getDescription()->toString( )); } }
TEST(TestScriptFetcher, HandleSimple) { TemporaryDir tmp_dir; TemporaryFile cmdFile(tmp_dir.createFile()); cmdFile.writeString( "#!/bin/sh\n" "echo foo\n" "echo bar\n" ); PCHECK(chmod(cmdFile.getFilename().c_str(), 0700) == 0); Config config(dynamic::object ("resources", dynamic::object) ("nodes", dynamic::object ("levels", {"level1"}) ("node_source", "script") ("node_source_prefs", dynamic::object ("parent_level", "instance") ("script", cmdFile.getFilename().native()) ) ) ); Nodes nodes; NodesLoader::_fetchNodesImpl(config, &nodes); auto it = nodes.begin(); ASSERT_EQ(nodes.getInstance(), (*it).get()); ++it; ASSERT_NE(it, nodes.end()); ASSERT_EQ("foo", (*it)->name()); ASSERT_EQ(nodes.getInstance(), (*it)->parent()); ++it; ASSERT_NE(it, nodes.end()); ASSERT_EQ("bar", (*it)->name()); ASSERT_EQ(nodes.getInstance(), (*it)->parent()); ++it; ASSERT_EQ(it, nodes.end()); }
vector<const pddl_type *> TypeHierarchy::accumulateAll(const pddl_type * t) { vector<const pddl_type *> nds(1,t); PTypeRef tt(t); GI gi = downGraph.find(&tt); if(gi == downGraph.end()) return nds; Nodes ns; PTypeRef pt(0); closure(downGraph,gi,ns,gi,&pt); for(Nodes::const_iterator i = ns.begin();i != ns.end();++i) { nds.push_back(***i); }; return nds; };
void Node::add(const string& str) { string::size_type pos = str.find(c_separator); string name = str.substr(0, pos); Node target(name); CNodeIter iter = m_nodes.find(&target); if (iter == m_nodes.end()) { iter = m_nodes.insert(new Node(name)).first; } if (pos != string::npos) { Node* pNode = *iter; pNode->add(str.substr(pos + 1)); } }
uint32_t LocalNode::removeListenerNB( ConnectionPtr connection ) { EQASSERT( isListening( )); EQASSERT( connection->isListening( )); connection->ref( CO_REFERENCED_PARAM ); NodeRemoveListenerPacket packet( connection, registerRequest( )); Nodes nodes; getNodes( nodes ); for( Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i ) { (*i)->send( packet, connection->getDescription()->toString( )); } return packet.requestID; }
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; }
void Object::notifyDetach() { if( !isMaster( )) return; // unmap slaves const Nodes slaves = impl_->cm->getSlaveNodes(); if( slaves.empty( )) return; LBWARN << slaves.size() << " slaves subscribed during deregisterObject of " << lunchbox::className( this ) << " id " << impl_->id << std::endl; for( NodesCIter i = slaves.begin(); i != slaves.end(); ++i ) { NodePtr node = *i; node->send( CMD_NODE_UNMAP_OBJECT ) << impl_->id; } }