/* * Returns the number of edges from head on */ int numEdges(edgeSet * head) { if(head == NULL) return 0; else return 1 + numEdges(head->nextEdge); }
balazs::Permutation balazs::WeighedTree::getPairing() const { std::vector<std::size_t> pairing; pairing.reserve(2 * numEdges()); fillInPairing(pairing, m_root); return Permutation(pairing); }
std::vector<long double> balazs::WeighedTree::getLengths() const { std::vector<long double> lengths; lengths.reserve(2 * numEdges()); fillInLengths(lengths, m_root); return lengths; }
void Partitioner::query_list_of_connected_objects(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborProc, int wgt_dim, float *ewgts, int *ierr) { MeshPartitioner& p = *(MeshPartitioner *)data; *ierr = ZOLTAN_OK; p.list_of_connected_objects_in_part(PE::Comm::instance().rank(),nborGID); p.list_of_connected_procs_in_part(PE::Comm::instance().rank(),nborProc); // for debugging #if 0 const Uint nb_obj = p.nb_owned_objects(); std::vector<Uint> numEdges(nb_obj); Uint tot_nb_edges = p.nb_connected_objects(numEdges); std::vector<Uint> conn_glbID(tot_nb_edges); p.list_of_connected_objects(conn_glbID); std::vector<Uint> glbID(nb_obj); p.list_of_owned_objects(glbID); PEProcessSortedExecute(-1, CFdebug << RANK << "conn_glbID =\n"; Uint cnt = 0; index_foreach( e, const Uint nbEdge, numEdges) { if (p.is_node(glbID[e])) CFdebug << " N" << p.to_node_glb(glbID[e]) << ": "; else CFdebug << " E" << p.to_elem_glb(glbID[e]) << ": "; for (Uint c=cnt; c<cnt+nbEdge; ++c) { if (p.is_node(conn_glbID[c])) CFdebug << " N" << p.to_node_glb(conn_glbID[c]); else CFdebug << " E" << p.to_elem_glb(conn_glbID[c]); } CFdebug << "\n"; cnt += nbEdge; } CFdebug << CFendl; cf3_assert( cnt == tot_nb_edges ); CFdebug << RANK << "total nb_edges = " << cnt << CFendl; ) #endif }
/* * This function builds a partially connected graph from a given hypergraph. * It is similar to a fully connected graph because it is a naiive algorithm * however it is considered better because only each individual hyperedge is * connected */ hypergraph * buildPartialGraph(hypergraph * H) { hypergraph * G = newHyperGraph(); G->vertexSets = copyVertexSets(H->vertexSets); //erase the edges associated with each vertex vertexSet * currentVertex = G->vertexSets; while(currentVertex != NULL) { currentVertex->edges = NULL; currentVertex = currentVertex->nextVertex; } //traverse each edge in H, making sure to make each fully connected //when adding it to G edgeSet * currentEdge = H->edgeSets; int edges = numEdges(H->edgeSets) + 1; //Loop through each edge in H generating the eBar edges for each while(currentEdge!=NULL) { edgeSet * eBars = buildEdgesFromHyperEdge(currentEdge); //Loop through each of the generated eBar edges and add them to G while(eBars!=NULL) { edgeSet * currentG = G->edgeSets; bool found = false; while(currentG!=NULL) { if(equal_list(eBars->vertices, currentG->vertices)) found = true; currentG = currentG->nextEdge; } //only add the edge if it is unique if(!found) { edgeSet * newEdge = appendEdgeSet(&G->edgeSets, edges); newEdge->vertices = copyList(eBars->vertices); addEdgetoVertices(newEdge, G->vertexSets); edges++; } //advance to the next eBar eBars = eBars->nextEdge; } currentEdge = currentEdge->nextEdge; } return G; }
/* * displays the edges and vertices of a hyper graph */ void displayHyperGraph(hypergraph * h, char * name) { if(h!=NULL) { printf("EdgeSets of %s:\n", name); displayEdges(h->edgeSets); printf("-----------------------------------\n"); printf("VertexSets of %s:\n", name); displayVertices(h->vertexSets); printf("-----------------------------------\n"); printf("Number of edges of %s: %d Number of vertices of %s: %d\n", name, numEdges(h->edgeSets), name, numVertices(h->vertexSets)); printf("===================================\n"); } else printf("NULL GRAPH\n"); }
Edge<Scalar,2>* Polygon<Scalar>::edgePtr(unsigned int edge_idx) { bool index_valid = (edge_idx>=0)&&(edge_idx<numEdges()); if(!index_valid) { std::cerr<<"Polygon edge index out of range!\n"; std::exit(EXIT_FAILURE); } unsigned int current_edge_sum = 0; for(unsigned int group_idx = 0; group_idx < groups_.size(); ++group_idx) { EdgeGroup<Scalar,2>& current_group = groups_[group_idx]; unsigned int group_edge_num = current_group.numEdges(); if(current_edge_sum + group_edge_num > edge_idx)//find the group containing this edge { return current_group.edgePtr(edge_idx - current_edge_sum); } else current_edge_sum += group_edge_num; } std::cerr<<"Polygon edge index out of range!\n"; std::exit(EXIT_FAILURE); return groups_[0].edgePtr(0); }
void Graph::printGraph() { cout << "Number of nodes: " << numNodes() << ", number of edges: " << numEdges() << endl; vector<Edge>::iterator iter; for( iter = edges.begin(); iter != edges.end(); iter++ ) iter->printEdge(); }
bool isTree(const Graph & g) { return isConnected(g) && (numEdges(g) == order(g)-1); }
std::string toString() { std::stringstream ss; ss<<"|V|=" << numVertices() << ",|E|=" << numEdges(); return ss.str(); }