bool Callback::isValid( Graph const & g , Graph::Node const & i , NodeSet const & dS , NodeSet const & S) const { if ( S.find( i ) == S.end() ) { // i must be in S return false; } if ( dS.find( i ) != dS.end() ) { // i must not be in dS return false; } // determine dS again NodeSet ddS; for ( Graph::Node i : S ) { for ( Graph::Edge e : g.incEdges( i) ) { Graph::Node j = g.oppositeNode( i, e ); if ( S.find( j ) == S.end() ) { ddS.insert( j ); } } } return dS == ddS; }
/** * Prepares constraints in order to apply VPSC vertically to remove ALL overlap. */ int generateYConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs) { events=new Event*[2*n]; int ctr=0,i,m; for(i=0;i<n;i++) { vars[i]->desiredPosition=rs[i]->getCentreY(); Node *v = new Node(vars[i],rs[i],rs[i]->getCentreY()); events[ctr++]=new Event(Open,v,rs[i]->getMinX()); events[ctr++]=new Event(Close,v,rs[i]->getMaxX()); } qsort((Event*)events, (size_t)2*n, sizeof(Event*), compare_events ); NodeSet scanline; vector<Constraint*> constraints; for(i=0;i<2*n;i++) { Event *e=events[i]; Node *v=e->v; if(e->type==Open) { scanline.insert(v); NodeSet::iterator i=scanline.find(v); if(i--!=scanline.begin()) { Node *u=*i; v->firstAbove=u; u->firstBelow=v; } i=scanline.find(v); if(++i!=scanline.end()) { Node *u=*i; v->firstBelow=u; u->firstAbove=v; } } else { // Close event Node *l=v->firstAbove, *r=v->firstBelow; if(l!=NULL) { double sep = (v->r->height()+l->r->height())/2.0; constraints.push_back(new Constraint(l->v,v->v,sep)); l->firstBelow=v->firstBelow; } if(r!=NULL) { double sep = (v->r->height()+r->r->height())/2.0; constraints.push_back(new Constraint(v->v,r->v,sep)); r->firstAbove=v->firstAbove; } scanline.erase(v); delete v; } delete e; } delete [] events; cs=new Constraint*[m=constraints.size()]; for(i=0;i<m;i++) cs[i]=constraints[i]; return m; }
Item::Ptr UTransform::TransformResult::next(DynamicContext *context) { context->testInterrupt(); AutoVariableStoreReset reset(context, &scope_); if(toDo_) { toDo_ = false; NodeSet copiedNodes = NodeSet(nodecompare(context)); VectorOfCopyBinding::const_iterator end = transform_->getBindings()->end(); for(VectorOfCopyBinding::const_iterator it = transform_->getBindings()->begin(); it != end; ++it) { if((*it)->qname_ == 0) continue; Sequence values = (*it)->expr_->createResult(context)->toSequence(context); // Keep a record of the nodes that have been copied Result valIt = values; Item::Ptr val; while((val = valIt->next(context)).notNull()) { copiedNodes.insert((Node*)val.get()); } scope_.setVar((*it)->uri_, (*it)->name_, values); } // Get the pending update list PendingUpdateList pul = transform_->getModifyExpr()->createUpdateList(context); // Check that the targets of the pending updates are copied nodes for(PendingUpdateList::const_iterator i = pul.begin(); i != pul.end(); ++i) { Node::Ptr target = i->getTarget(); while(copiedNodes.find(target) == copiedNodes.end()) { target = target->dmParent(context); if(target.isNull()) { XQThrow3(StaticErrorException,X("UTransform::staticTyping"), X("The target node of an update expression in the transform expression is not a node from the copy clauses [err:XUDY0014]"), &(*i)); } } } // Apply the updates AutoDelete<UpdateFactory> ufactory(context->createUpdateFactory()); ufactory->applyUpdates(pul, context, transform_->getRevalidationMode()); // Execute the return expression result_ = transform_->getReturnExpr()->createResult(context); } Item::Ptr result = result_->next(context); if(result.isNull()) { result_ = 0; return 0; } return result; }
uint64_t CVC4::theory::bv::utils::numNodes(TNode node, NodeSet& seen) { if (seen.find(node) != seen.end()) return 0; uint64_t size = 1; for (unsigned i = 0; i < node.getNumChildren(); ++i) { size += numNodes(node[i], seen); } seen.insert(node); return size; }
void CVC4::theory::bv::utils::collectVariables(TNode node, NodeSet& vars) { if (vars.find(node) != vars.end()) return; if (Theory::isLeafOf(node, THEORY_BV) && node.getKind() != kind::CONST_BITVECTOR) { vars.insert(node); return; } for (unsigned i = 0; i < node.getNumChildren(); ++i) { collectVariables(node[i], vars); } }
void TheoryEngineModelBuilder::checkTerms(TNode n, TheoryModel* tm, NodeSet& cache) { if (cache.find(n) != cache.end()) { return; } if (isAssignable(n)) { tm->d_equalityEngine.addTerm(n); } for(TNode::iterator child_it = n.begin(); child_it != n.end(); ++child_it) { checkTerms(*child_it, tm, cache); } cache.insert(n); }
void GraphicsContext::removeCamera(osg::Camera* camera) { Cameras::iterator itr = std::find(_cameras.begin(), _cameras.end(), camera); if (itr != _cameras.end()) { // find a set of nodes attached the camera that we are removing that isn't // shared by any other cameras on this GraphicsContext typedef std::set<Node*> NodeSet; NodeSet nodes; for(unsigned int i=0; i<camera->getNumChildren(); ++i) { nodes.insert(camera->getChild(i)); } for(Cameras::iterator citr = _cameras.begin(); citr != _cameras.end(); ++citr) { if (citr != itr) { osg::Camera* otherCamera = *citr; for(unsigned int i=0; i<otherCamera->getNumChildren(); ++i) { NodeSet::iterator nitr = nodes.find(otherCamera->getChild(i)); if (nitr != nodes.end()) nodes.erase(nitr); } } } // now release the GLobjects associated with these non shared nodes for(NodeSet::iterator nitr = nodes.begin(); nitr != nodes.end(); ++nitr) { const_cast<osg::Node*>(*nitr)->releaseGLObjects(_state.get()); } // release the context of the any RenderingCache that the Camera has. if (camera->getRenderingCache()) { camera->getRenderingCache()->releaseGLObjects(_state.get()); } _cameras.erase(itr); } }
/** * Prepares constraints in order to apply VPSC horizontally. Assumes variables have already been created. * useNeighbourLists determines whether or not a heuristic is used to deciding whether to resolve * all overlap in the x pass, or leave some overlaps for the y pass. */ int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs, const bool useNeighbourLists) { events=new Event*[2*n]; int i,m,ctr=0; for(i=0;i<n;i++) { vars[i]->desiredPosition=rs[i]->getCentreX(); Node *v = new Node(vars[i],rs[i],rs[i]->getCentreX()); events[ctr++]=new Event(Open,v,rs[i]->getMinY()); events[ctr++]=new Event(Close,v,rs[i]->getMaxY()); } qsort((Event*)events, (size_t)2*n, sizeof(Event*), compare_events ); NodeSet scanline; vector<Constraint*> constraints; for(i=0;i<2*n;i++) { Event *e=events[i]; Node *v=e->v; if(e->type==Open) { scanline.insert(v); if(useNeighbourLists) { v->setNeighbours( getLeftNeighbours(scanline,v), getRightNeighbours(scanline,v) ); } else { NodeSet::iterator it=scanline.find(v); if(it--!=scanline.begin()) { Node *u=*it; v->firstAbove=u; u->firstBelow=v; } it=scanline.find(v); if(++it!=scanline.end()) { Node *u=*it; v->firstBelow=u; u->firstAbove=v; } } } else { // Close event int r; if(useNeighbourLists) { for(NodeSet::iterator i=v->leftNeighbours->begin(); i!=v->leftNeighbours->end();i++ ) { Node *u=*i; double sep = (v->r->width()+u->r->width())/2.0; constraints.push_back(new Constraint(u->v,v->v,sep)); r=u->rightNeighbours->erase(v); } for(NodeSet::iterator i=v->rightNeighbours->begin(); i!=v->rightNeighbours->end();i++ ) { Node *u=*i; double sep = (v->r->width()+u->r->width())/2.0; constraints.push_back(new Constraint(v->v,u->v,sep)); r=u->leftNeighbours->erase(v); } } else { Node *l=v->firstAbove, *r=v->firstBelow; if(l!=NULL) { double sep = (v->r->width()+l->r->width())/2.0; constraints.push_back(new Constraint(l->v,v->v,sep)); l->firstBelow=v->firstBelow; } if(r!=NULL) { double sep = (v->r->width()+r->r->width())/2.0; constraints.push_back(new Constraint(v->v,r->v,sep)); r->firstAbove=v->firstAbove; } } r=scanline.erase(v); delete v; } delete e; } delete [] events; cs=new Constraint*[m=constraints.size()]; for(i=0;i<m;i++) cs[i]=constraints[i]; return m; }
bool Graph::printDOT(const std::string& fileName) { FILE *file = fopen(fileName.c_str(), "w"); if (file == NULL) { return false; } fprintf(file, "digraph G {\n"); NodeSet visited; std::queue<Node::Ptr> worklist; NodeIterator entryBegin, entryEnd; entryNodes(entryBegin, entryEnd); // Initialize visitor worklist for (NodeIterator iter = entryBegin; iter != entryEnd; ++iter) { worklist.push(*iter); } // Put the entry nodes on their own (minimum) rank fprintf(file, " { rank = min;"); for (NodeIterator iter = entryBegin; iter != entryEnd; ++iter) { fprintf(file, "\"%p\"; ", (*iter).get()); } fprintf(file, "}\n"); NodeIterator exitBegin, exitEnd; exitNodes(exitBegin, exitEnd); // Put the entry nodes on their own (minimum) rank fprintf(file, " { rank = max;"); for (NodeIterator iter = exitBegin; iter != exitEnd; ++iter) { fprintf(file, "\"%p\"; ", (*iter).get()); } fprintf(file, "}\n"); while (!worklist.empty()) { Node::Ptr source = worklist.front(); worklist.pop(); //fprintf(stderr, "Considering node %s\n", source->format().c_str()); // We may have already treated this node... if (visited.find(source) != visited.end()) { //fprintf(stderr, "\t skipping previously visited node\n"); continue; } //fprintf(stderr, "\t inserting %s into visited set, %d elements pre-insert\n", source->format().c_str(), visited.size()); visited.insert(source); fprintf(file, "\t%s\n", source->DOTshape().c_str()); fprintf(file, "\t%s\n", source->DOTrank().c_str()); fprintf(file, "\t\"%p\" [label=\"%s\"];\n", source.get(), source->DOTname().c_str()); NodeIterator outBegin, outEnd; source->outs(outBegin, outEnd); for (; outBegin != outEnd; ++outBegin) { Node::Ptr target = *outBegin; if (!target->DOTinclude()) continue; //fprintf(file, "\t %s -> %s;\n", source->DOTname().c_str(), target->DOTname().c_str()); fprintf(file, "\t \"%p\" -> \"%p\";\n", source.get(), target.get()); if (visited.find(target) == visited.end()) { //fprintf(stderr, "\t\t adding child %s\n", target->format().c_str()); worklist.push(target); } else { //fprintf(stderr, "\t\t skipping previously visited child %s\n", //target->format().c_str()); } } } fprintf(file, "}\n\n\n"); fclose(file); return true; }