void Graph<Node, Edge>::NodeContainer::merge(NodeContainer destroy) { while(!destroy.edges.empty()) { EdgeContainer ec = destroy.edges.back(); destroy.edges.pop_back(); if(ec.isValid() && ec.getDestination() != *nodePtr && !hasEdge(ec.getDestination(), ec.getWeight())) { edges.push_back(ec); } } }
bool SGMScanInfo::operator ==(const SGMScanInfo &other) const{ if(hasEdge() == other.hasEdge() && edge() == other.edge() && fabs(energy() - other.energy()) < 0.01 && start() == other.start() && middle() == other.middle() && end() == other.end()) return true; return false; }
int chunk::getNbrRefOnEdge(int n1, int n2, int *conn, int nGhost, int *gid, int idx, elemRef *er) { int i, e; er->init(); for (i=idx+1; i<nGhost; i++) if ((e = hasEdge(n1, n2, conn, i)) != -1) { er->init(gid[i*2], gid[i*2+1]); return e; } return -1; }
static unsigned int findWedgeEdge(const EdgeAdjacency& adjacency, const unsigned int* wedge, unsigned int a, unsigned int b) { unsigned int v = a; do { if (hasEdge(adjacency, v, b)) return v; v = wedge[v]; } while (v != a); return ~0u; }
bool DirectedGraph::addEdge(int fromNodeId, int toNodeId) { if (hasEdge(fromNodeId, toNodeId)) return false; if (!hasNode(fromNodeId)) addNode(fromNodeId); if (!hasNode(toNodeId)) addNode(toNodeId); ListType* fromNeighbors = inNeighborsTable[toNodeId]; fromNeighbors->push_back(fromNodeId); ListType* toNeighbors = outNeighborsTable[fromNodeId]; toNeighbors->push_back(toNodeId); edgeCount++; return true; }
//-------------------------------------------- // Function: getNeighbors() * // Purpose: Returns list of neighbors * // Returns: int array * //-------------------------------------------- void Prog3Graph::getNeighbors(int nodeA_ID, int *neighbors) { int i = 0; for each (GraphNode node in Nodes) { if(hasEdge(nodeA_ID, node.getNodeID())) { neighbors[i] = node.getNodeID(); i++; } } }
EssentialGraph inducedSubgraph(InputIterator first, InputIterator last) const { EssentialGraph result(std::distance(first, last)); InputIterator vi, vj; uint i, j; i = 0; for (vi = first; vi != last; ++vi, ++i) { j = 0; for (vj = first; vj != last; ++vj, ++j) if (hasEdge(*vi, *vj)) result.addEdge(i, j); } return result; }
static size_t countOpenEdges(const EdgeAdjacency& adjacency, unsigned int vertex, unsigned int* last = 0) { size_t result = 0; unsigned int count = adjacency.counts[vertex]; const unsigned int* data = adjacency.data + adjacency.offsets[vertex]; for (size_t i = 0; i < count; ++i) if (!hasEdge(adjacency, data[i], vertex)) { result++; if (last) *last = data[i]; } return result; }
edge_descriptor addEdge( const vertex_descriptor& v1, const vertex_descriptor& v2, const Edge& prop ) { if( hasEdge( v1, v2, prop.getInAttrName() ) ) { BOOST_THROW_EXCEPTION( exception::Logic() << exception::dev() + "Can't add Edge. There is already a connection from \"" + instance(v1) + "\" to \"" + instance(v2) + "/" + prop.getInAttrName() + "\"" ); } //TUTTLE_LOG_VAR2( TUTTLE_TRACE, v1, instance(v1) ); //TUTTLE_LOG_VAR2( TUTTLE_TRACE, v2, instance(v2) ); const edge_descriptor addedEdge = boost::add_edge( v1, v2, prop, _graph ).first; if( hasCycle() ) { removeEdge( addedEdge ); BOOST_THROW_EXCEPTION( exception::Logic() << exception::user() + "Connection error: the graph becomes cyclic while connecting \"" + instance(v1) + "\" to \"" + instance(v2) + "\"" ); } return addedEdge; }
bool isParent(const uint a, const uint b) const { return hasEdge(a, b) && !hasEdge(b, a); }
bool hasEdge( const VertexKey& out, const VertexKey& in, const std::string& inAttr ) const { return hasEdge( getVertexDescriptor(out), getVertexDescriptor(in), inAttr ); }
bool GraphIF::hasEdge(VertexIF * const sourceVertex, VertexIF * const targetVertex) { return hasEdge(sourceVertex->getVertexIdx(), targetVertex->getVertexIdx()); }
bool isAdjacent(const uint a, const uint b) const { return hasEdge(a, b) || hasEdge(b, a); }
bool isNeighbor(const uint a, const uint b) const { return hasEdge(a, b) && hasEdge(b, a); }
// Check for the presence of an edge bool Vertex::hasEdge(Edge* pEdge) const { return hasEdge(pEdge->getDesc()); }
/** * Yields a LexBFS-ordering of a subset of vertices, and possibly orients * the edges of the induced subgraph accordingly. Assumes * that all vertices belong to the same chain component. * * @param first first vertex of the start order * @param last --last: last vertex of the start order * @param orient indicates whether edges have to be oriented according * to the LexBFS order * @param directed (OUT) pointer to a list of edges that become directed * @return List (set) of oriented edges */ template <typename InputIterator> std::vector<uint> lexBFS(InputIterator first, InputIterator last, const bool orient = false, std::set<Edge, EdgeCmp>* directed = NULL) { if (directed != NULL) directed->clear(); std::vector<uint> ordering; int length = std::distance(first, last); ordering.reserve(length); // Trivial cases: if not more than one start vertex is provided, // return an empty set of edges if (length == 1) ordering.push_back(*first); if (length <= 1) return ordering; // Create sequence of sets ("\Sigma") containing the single set // of all vertices in the given start order std::list<std::list<uint> > sets(1, std::list<uint>(first, last)); std::list<std::list<uint> >::iterator si, newSet; std::list<uint>::iterator vi; uint a; while (!sets.empty()) { // Remove the first vertex from the first set, and remove this set // if it becomes empty a = sets.front().front(); sets.front().pop_front(); if (sets.front().empty()) sets.pop_front(); // Append a to the ordering ordering.push_back(a); // Move all neighbors of a into own sets, and orient visited edges // away from a for (si = sets.begin(); si != sets.end(); ) { newSet = sets.insert(si, std::list<uint>()); for (vi = si->begin(); vi != si->end(); ) { if (hasEdge(a, *vi)) { // Orient edge to neighboring vertex, if requested, and // store oriented edge in return set if (orient) removeEdge(*vi, a); if (directed != NULL) directed->insert(Edge(a, *vi)); // Move neighoring vertex newSet->push_back(*vi); vi = si->erase(vi); } else ++vi; } // If visited or newly inserted sets are empty, remove them // from the sequence if (newSet->empty()) sets.erase(newSet); if (si->empty()) si = sets.erase(si); else ++si; } } return ordering; }
inline bool hasEdge (String<bool> adjacency_matrix, unsigned id_from, unsigned id_to) { return hasEdge(adjacency_matrix, id_from, id_to, std::sqrt(length(adjacency_matrix)) ); }