/* * Removes an vertex from a graph and returns its data */ void *remove_vertex(graph_p graph, vertex_p v) { if (graph->vertices == v) { graph->vertices = v->next; } vertex_p w = graph->vertices; // remove all incoming edges while (w) { edge_p e = v->neighbors; while (e) { if (e->to == v) { // there's a vertex w -> v, remove it remove_edge(w, v); } e = e->next; } // if v is the following vertex in the list of all vertices, remove it from the list and skip it if (w->next == v) { w->next = v->next; } w = w->next; } // remove all outgoing edges while (v->neighbors) { remove_edge(v, v->neighbors->to); } void *data = v->data; free(v); return data; }
int main() { { typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, boost::no_property, edge_prop> graph; typedef boost::graph_traits<graph>::edge_descriptor edge; graph g(2); edge_prop p = { 42 }; edge e; bool b; tie(e, b) = add_edge(0, 1, p, g); assert( num_edges(g) == 1 ); assert( g[e].weight == 42 ); remove_edge(e, g); assert( num_edges(g) == 0 ); } { typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> graph; typedef boost::graph_traits<graph>::edge_descriptor edge; graph g(2); edge e; bool b; tie(e, b) = add_edge(0, 1, g); assert( num_edges(g) == 1 ); remove_edge(e, g); assert( num_edges(g) == 0 ); } return boost::exit_success; }
void constraints() { v = add_vertex(g); clear_vertex(v, g); remove_vertex(v, g); p = add_edge(u, v, g); remove_edge(u, v, g); remove_edge(e, g); }
void planarize_two_edges(graphD * theGraph, int u1, int v1, int u2, int v2, int newVertex) { remove_edge(u1, v1, *theGraph); remove_edge(u2, v2, *theGraph); add_edge(u1, newVertex, *theGraph); add_edge(v1, newVertex, *theGraph); add_edge(u2, newVertex, *theGraph); add_edge(v2, newVertex, *theGraph); }
void graph_remove_vertex_edges(struct graph *graph, int idx) { assert(idx >= 0 && idx < graph_get_vertex_count(graph)); while (graph->edges[idx]) { remove_edge(graph, graph->edges[idx]->rev); remove_edge(graph, graph->edges[idx]); } }
void cleanup_graph(FUNCTION *func) { GRAPH *graph = func->graph; int i; restart: for (i = 2; i < tree_num_children(graph); i++) { NODE *vertex = tree_get_child(graph, i); if (vertex == NULL) continue; if (!find_in_hash(graph->forward, vertex, sizeof(void *)) || !find_in_hash(graph->backward, vertex, sizeof(void *))) { //printf(" dead-end: "); //tree_print(vertex, 2); } if (tree_is_type(vertex, STMT_PASS)) { HASH *subhash = get_from_hash(graph->forward, vertex, sizeof(void *)); HASH_ITERATOR iter; hash_iterator(subhash, &iter); if (hash_iterator_valid(&iter)) { NODE *successor = iter.entry->key; EDGE_TYPE type = (EDGE_TYPE) iter.entry->data; replace_backward(graph, vertex, successor, type); remove_edge(graph, vertex, successor); remove_vertex(graph, vertex); goto restart; } } else if (tree_is_type(vertex, STMT_JOIN)) { HASH *subhash = get_from_hash(graph->forward, vertex, sizeof(void *)); if (subhash->num != 1) error("Join does not have exactly 1 successor"); HASH_ITERATOR iter; hash_iterator(subhash, &iter); if (hash_iterator_valid(&iter)) { NODE *successor = iter.entry->key; EDGE_TYPE type = (EDGE_TYPE) iter.entry->data; replace_backward(graph, vertex, successor, type); remove_edge(graph, vertex, successor); remove_vertex(graph, vertex); goto restart; } } } }
void rim::connect(const vertices_size_type &) { // Store frequently-used variables. const vertices_size_type t_size = get_number_of_vertices(); pagmo_assert(t_size != 0); switch (t_size) { case 1: { // If the topology was empty, do not do anything. break; } case 2: { add_edge(0,1); add_edge(1,0); break; } case 3: { // Add edge to the center. add_edge(0,2); add_edge(2,0); // Add 1-2 connection. add_edge(1,2); add_edge(2,1); break; } case 4: { // Add edge to the center. add_edge(0,3); add_edge(3,0); // Add 1-3 and 3-2 connections. add_edge(1,3); add_edge(3,1); add_edge(2,3); add_edge(3,2); break; } default: { // Add edge to the center. add_edge(0,t_size - 1); add_edge(t_size - 1,0); // Remove connection (previous last)-first. remove_edge(t_size - 2,1); remove_edge(1,t_size - 2); // Add connection (previous last)-(new last). add_edge(t_size - 2,t_size - 1); add_edge(t_size - 1,t_size - 2); // Add connection (new last)-(first). add_edge(t_size - 1,1); add_edge(1,t_size - 1); } } }
void solution::remove_edge( unsigned int page, const edge_t & e, int crossings ) { if( page >= pages.size() ) throw std::out_of_range("requested page out of range"); remove_edge(pages[page], e, crossings); }
void one_way_ring::connect(const vertices_size_type &n) { // Store frequently-used variables. const vertices_size_type t_size = get_number_of_vertices(); pagmo_assert(t_size != 0); switch (t_size) { case 1: { // If the topology was empty, just update the id of the first element. m_first = n; break; } case 2: { pagmo_assert(n != m_first); // Add connections to the only existing element. add_edge(m_first,n); add_edge(n,m_first); break; } default: { // The current last must be connected to the new one. remove_edge(m_last,m_first); add_edge(m_last,n); add_edge(n,m_first); } } // Update the id of the last island. m_last = n; }
static void insert_new_edges(SkEdge* newEdge, int curr_y) { if (newEdge->fFirstY != curr_y) { return; } SkEdge* prev = newEdge->fPrev; if (prev->fX <= newEdge->fX) { return; } // find first x pos to insert SkEdge* start = backward_insert_start(prev, newEdge->fX); // insert the lot, fixing up the links as we go do { SkEdge* next = newEdge->fNext; do { if (start->fNext == newEdge) { goto nextEdge; } SkEdge* after = start->fNext; if (after->fX >= newEdge->fX) { break; } start = after; } while (true); remove_edge(newEdge); insert_edge_after(newEdge, start); nextEdge: start = newEdge; newEdge = next; } while (newEdge->fFirstY == curr_y); }
void betweenness_centrality_clustering(MutableGraph& g, Done done, EdgeCentralityMap edge_centrality, VertexIndexMap vertex_index) { typedef typename property_traits<EdgeCentralityMap>::value_type centrality_type; typedef typename graph_traits<MutableGraph>::edge_iterator edge_iterator; typedef typename graph_traits<MutableGraph>::edge_descriptor edge_descriptor; typedef typename graph_traits<MutableGraph>::vertices_size_type vertices_size_type; if (has_no_edges(g)) return; // Function object that compares the centrality of edges indirect_cmp<EdgeCentralityMap, std::less<centrality_type> > cmp(edge_centrality); bool is_done; do { brandes_betweenness_centrality(g, edge_centrality_map(edge_centrality) .vertex_index_map(vertex_index)); std::pair<edge_iterator, edge_iterator> edges_iters = edges(g); edge_descriptor e = *max_element(edges_iters.first, edges_iters.second, cmp); is_done = done(get(edge_centrality, e), e, g); if (!is_done) remove_edge(e, g); } while (!is_done && !has_no_edges(g)); }
static void remove_ctrl_stmt_and_useless_edges (basic_block bb, basic_block dest_bb) { gimple_stmt_iterator gsi; edge e; edge_iterator ei; gsi = gsi_last_bb (bb); /* If the duplicate ends with a control statement, then remove it. Note that if we are duplicating the template block rather than the original basic block, then the duplicate might not have any real statements in it. */ if (!gsi_end_p (gsi) && gsi_stmt (gsi) && (gimple_code (gsi_stmt (gsi)) == GIMPLE_COND || gimple_code (gsi_stmt (gsi)) == GIMPLE_GOTO || gimple_code (gsi_stmt (gsi)) == GIMPLE_SWITCH)) gsi_remove (&gsi, true); for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) { if (e->dest != dest_bb) remove_edge (e); else ei_next (&ei); } }
void graph_edge_remove(struct graph *graph, int i, int j) { struct edge *edge; assert(i >= 0 && i < graph_get_vertex_count(graph)); assert(j >= 0 && j < graph_get_vertex_count(graph)); assert(i != j); edge = graph_edge_find(graph, i, j); if (edge) { remove_edge(graph, edge->rev); remove_edge(graph, edge); } }
void clear_vertex(typename EdgeList::value_type u, std::vector<EdgeList, Allocator>& g) { g[u].clear(); for (std::size_t i = 0; i < g.size(); ++i) remove_edge(i, u, g); }
void planarize_one_edge(graphD * theGraph, int u1, int v1, int u2, int newVertex) { remove_edge(u1, v1, *theGraph); add_edge(u1, newVertex, *theGraph); add_edge(v1, newVertex, *theGraph); add_edge(u2, newVertex, *theGraph); }
void NETWORK::rewire( int _laps ) { // weights std::vector<double> weights; get_weights( weights ); shuffle_vector( weights ); // structure int wirings_left = _laps; int s1, s2, deg1, deg2, p1, p2, t1, t2; while( wirings_left > 0 ) { // choose two edge randomly s1 = Ran.IRandom( 0, Order-1 ); deg1 = Nodes[s1]->outdegree(); s2 = Ran.IRandom( 0, Order-1 ); deg2 = Nodes[s2]->outdegree(); if( s1 != s2 && deg1 != 0 && deg2 != 0 ) { p1 = Ran.IRandom( 0, deg1-1 ); t1 = Nodes[s1]->outneighbor(p1)->id(); p2 = Ran.IRandom( 0, deg2-1 ); t2 = Nodes[s2]->outneighbor(p2)->id(); if( t1 != t2 && t1 != s2 && t2 != s1 ) { remove_edge( s1, t1 ); remove_edge( s2, t2 ); add_edge( s1, t2, 1.0 ); add_edge( s2, t1, 1.0 ); wirings_left--; } } } // set weights int deg; for(int i=0; i<Order; i++) { deg = Nodes[i]->outdegree(); for(int j=0; j<deg; j++) { Nodes[i]->setOutWeight( j, weights.back() ); weights.pop_back(); } } }
void remove(adjacency_list<T> const &g) { for(vertex_iterator i(g.begin_verts());i!=g.end_verts();++i) { for(edge_iterator j(g.begin_edges(*i));j!=g.end_edges(*i);++j) { if(*i >= j->first) { remove_edge(*i,j->first,j->second); } } } }
void delete_dead_graph_inputs (FuncGraph *fg, int id, IntList **deleted) { int i, j, g_in, nd, pt, cnt, ndd; IntList *it, *kept_inputs = NULL; /* printf ("entering 'delete_dead_graph_inputs', id = %d\n", id); fflush (stdout); */ for (i=0, j=0; i<fg->nodes[id].num_inputs; i++) { g_in = fg->nodes[id].My_inputs[i]; if (fg->nodes[g_in].outputs[0].targets == NULL) { is_stable = FALSE; /* if this is a dead nextified input, we have to track down its * associated ND_NEXT node and delete it as well */ if (fg->nodes[g_in].nodetype == ND_G_INPUT_NEXT) for (it=fg->nodes[id].My_nodes; it!=NULL; it=it->link) { ndd = it->val; if ((fg->nodes[ndd].nodetype == ND_NEXT) && (fg->nodes[ndd].In_next_id == g_in)) { remove_simple_node (fg, ndd); add_to_list (ndd, deleted); break; } } SacFree (fg->nodes[g_in].outputs) fg->nodes[g_in].nodetype = ND_VOIDED; add_to_list (g_in, deleted); if (fg->nodes[id].inputs[i].back_edges != NULL) { nd = fg->nodes[id].inputs[i].back_edges->node; pt = fg->nodes[id].inputs[i].back_edges->port; remove_edge (fg, nd, pt, id, i); } } else { append_intlist (&kept_inputs, g_in); move_graph_input (fg, id, i, j); j++; } } for (it=kept_inputs, cnt=0; it!=NULL; it=it->link, cnt++) fg->nodes[id].My_inputs[cnt] = it->val; free_intlist (&kept_inputs); fg->nodes[id].num_inputs = cnt; }
void MergeAllParents::mergeAll(std::pair<ParentsIterator,ParentsIterator> pair, VertexID child, set<VertexID> &A, set<VertexID> &B) { set<VertexID> parents2; set<VertexID> parents1; set<VertexID>::iterator pit,Aelt,Belt; ParentsIterator p,p_end,p2,p2_end; InEdgeIterator e,e_end; for (tie(p,p_end) = pair; p != p_end; p++) { if (*p != m_invartask) { parents1.insert(*p); } } for (pit=parents1.begin(); pit != parents1.end(); pit++) { addContainsTask(child,*pit); for (tie(p2,p2_end) = parents(*pit,*m_taskgraph); p2 != p2_end; p2++) { if (parents1.find(*pit) == parents1.end() && *p2 != m_invartask) parents2.insert(*p2); } // Add edge from parents^2 to child for(tie(e,e_end) = in_edges(*pit,*m_taskgraph); e != e_end; e++) { // Adding edge here invalidates pair iterators if (parents1.find(source(*e,*m_taskgraph)) == parents1.end()) { EdgeID newEdge = add_edge(source(*e,*m_taskgraph),child,m_taskgraph); ResultSet &set = getResultSet(newEdge,m_taskgraph); ResultSet &oldSet = getResultSet(*e,m_taskgraph); set.make_union(&oldSet); } } } // Add edge from new node to all in A for (Aelt=A.begin(); Aelt != A.end(); Aelt++) { add_edge(child,*Aelt,m_taskgraph); } // Can not iterate through pair since add_edge above invalidates that // iterator. for (pit=parents1.begin(); pit != parents1.end(); pit++) { if (B.find(*pit) == B.end() && *pit != m_invartask) { (*m_taskRemoved)[*pit] = true; clear_vertex(*pit,*m_taskgraph); remove_vertex(*pit,*m_taskgraph); } } // Remove edges from elts in B to child, the elts are already dupl. into child. for (Belt = B.begin(); Belt != B.end(); Belt++) { remove_edge(*Belt,child,*m_taskgraph); } }
void remove_edge_and_renumber_indices(edge_iterator i) { edge_iterator j = next(i), end = edges(m_graph).second; edge_index_type n = get(edge_index, m_graph, *i); // remove the offending edge and renumber everything after remove_edge(*i); m_max_edge_index = renumber_edge_indices(j, end, n); }
bool CSimpleUGraph< ObjT, Compare >::RemoveEdge( const ObjT & oV1, const ObjT & oV2 ) { typename DataVertexMapT::iterator pMapPos1 = oDataToVertexMap.find( oV1 ); typename DataVertexMapT::iterator pMapPos2 = oDataToVertexMap.find( oV2 ); if( pMapPos1 == oDataToVertexMap.end() || pMapPos2 == oDataToVertexMap.end() ) return false; remove_edge( pMapPos1->second, pMapPos2->second, oBoostGraph ); }
void BondGraph::_ClearBonds () { // Remove all the edges. Edge_it ei, e_end, next; tie(ei, e_end) = edges(_graph); for (next = ei; ei != e_end; ei = next) { ++next; remove_edge(*ei, _graph); } return; }
void solution::move_vertices( const std::list< std::pair<size_t,size_t> > & move_list ) { std::list<std::pair<page_iterator_t,edge_t> > all_touching_edges; for( auto i= move_list.begin(); i!= move_list.end(); ++i ) { size_t index1= i->first; size_t to_pos= i->second; if( index1 >= spine_order.size() || to_pos > spine_order.size() ) { throw std::out_of_range("move vertices outside of index range"); } std::list<std::pair<page_iterator_t,edge_t> > touching_edges; // collect touching edges for( auto p= pages.begin(); p != pages.end(); ++p ) for( auto e= p->edges.begin(); e != p->edges.end(); ++e ) if( e->first == spine_order[index1] || e->second == spine_order[index1] ) { touching_edges.push_back( make_pair(p,*e) ); all_touching_edges.push_back( make_pair(p,*e) ); } // remove touching edges for( auto i= touching_edges.begin(); i != touching_edges.end(); ++i ) remove_edge( * i->first, i->second ); // // moving spine order if( to_pos < spine_order.size() ) move_range( index1, 1, to_pos, spine_order ); else append_range( index1, 1, spine_order ); } // new order map int order_count= 0; for( auto v=spine_order.begin(); v!= spine_order.end(); ++v ) { spine_order_map[ *v ]= order_count++; } // re -add edges for( auto i= all_touching_edges.begin(); i != all_touching_edges.end(); ++i ) add_edge( * i->first, i->second ); }
/* * Removes a vertex, in the following sense: The bag corresponding to the * index is emptied and all adjacencies are removed, i.e., the bag will * contain 0 vertices and have no incident edges. Nevertheless, the number of * vertices is reduced (hence num_vertices--). */ void remove_vertex(unsigned u) { bags.at(u).clear(); std::vector<unsigned> remove; for (auto it = adj_list.at(u).begin(); it != adj_list.at(u).end(); it++) { remove.push_back(*it); } for (auto it = remove.begin(); it != remove.end(); it++) { remove_edge(u,*it); } num_vertices--; }
void add_edge( const edge_type& e) { node_type *src = e.dst->input_plugs()[e.port].input(); if( src) remove_edge( edge_type( src, e.dst, e.port)); e.dst->input_plugs()[e.port].set_input( e.src); e.src->output_plug().add_output( e.dst, e.port); edges_.push_back( e); }
/* Insert 'newv' between 'v1' and 'v2'. e.g: given edge v1->v2, the result is v1->newv->v2. Return edge v1->newv, newv->v2. */ void GRAPH::insert_vertex_between(IN VERTEX * v1, IN VERTEX * v2, IN VERTEX * newv, OUT EDGE ** e1, OUT EDGE ** e2) { EDGE * e = get_edge(v1, v2); remove_edge(e); EDGE * tmpe1 = add_edge(v1, newv); EDGE * tmpe2 = add_edge(newv, v2); if (e1 != NULL) *e1 = tmpe1; if (e2 != NULL) *e2 = tmpe2; }
//Reverse edge direction EDGE * GRAPH::rev_edge(EDGE * e) { IS_TRUE(m_pool != NULL, ("not yet initialized.")); IS_TRUE(m_is_direction, ("graph is indirection")); void * einfo = EDGE_info(e); VERTEX * from = EDGE_from(e); VERTEX * to = EDGE_to(e); remove_edge(e); e = add_edge(VERTEX_id(to), VERTEX_id(from)); EDGE_info(e) = einfo; return e; }
void SGraphBit::set_node_predecessors(SGraphNode node, const BitVector *t) { unsigned num_nodes = max_num_nodes(); for (unsigned i = 0; i < num_nodes; i++) { if (is_node_member(i)) { if (t->get_bit(i)) { add_edge(SGraphEdge(i, node)); } else { remove_edge(SGraphEdge(i, node)); } } } }
int test_main(int, char*[]) { { typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, boost::no_property, edge_prop, boost::no_property, boost::vecS> graph; typedef boost::graph_traits<graph>::edge_descriptor edge; graph g(2); edge_prop p1 = { 42 }; edge_prop p2 = { 17 }; add_edge(0, 1, p1, g); add_edge(1, 0, p2, g); edge e1 = boost::edge(0, 1, g).first; edge e2 = boost::edge(1, 0, g).first; BOOST_TEST( num_edges(g) == 2 ); BOOST_TEST( g[e1].weight == 42 ); BOOST_TEST( g[e2].weight == 17 ); remove_edge(e1, g); BOOST_TEST( num_edges(g) == 1 ); // e2 has been invalidated, so grab it again bool b2; tie(e2, b2) = boost::edge(1, 0, g); BOOST_TEST( b2 ); BOOST_TEST( g[e2].weight == 17 ); /* Now remove the other edge. Here, the fact that * stored_ra_edge_iterator keeps an index but does not update it * when edges are removed. So, this will be incorrect but the * error may not always show up (use an STL debug mode to see the * error for sure.) */ remove_edge(e2, g); } return boost::exit_success; }
void SGraph::remove_node_predecessor_edges(SGraphNode node) { // make a list and then delete the edges. SGraphNodeList list; for (SNodeIter iter(get_node_predecessor_iterator(node)); !iter.done(); iter.increment()) { list.push_back(iter.get()); } while (!list.empty()) { SGraphNode from_node = list.front(); remove_edge(SGraphEdge(from_node, node)); } }