#include <graph.hpp>
Definition at line 116 of file graph.hpp.
Graph | ( | ) | [inline] |
GraphDfsIter< T > * createIterator | ( | ) | const [inline] |
Definition at line 307 of file graph.hpp.
00308 { 00309 return new GraphDfsIter<T>(this); 00310 }
void delete_edge | ( | T | v_val, | |
T | e_val | |||
) | [inline] |
Deletes an edge.
Definition at line 468 of file graph.hpp.
Referenced by Graph< T >::delete_vertex().
00469 { 00470 if(head==NULL) 00471 return; 00472 00473 gNode<T> *s, *t=head; 00474 00475 while(t!=NULL) 00476 { 00477 if(t->data==v_val) 00478 { 00479 s=t; 00480 t=t->next; 00481 while(t!=NULL) 00482 { 00483 if(t->data==e_val) 00484 { 00485 s->next=t->next; 00486 t->vlist=NULL; 00487 delete t; 00488 nedges--; 00489 return; 00490 } 00491 s=t; 00492 t=t->next; 00493 } 00494 return; 00495 } 00496 t=t->vlist; 00497 } 00498 00499 }
void delete_vertex | ( | T | val | ) | [inline] |
Deletes a vertex and all incident edges.
Definition at line 503 of file graph.hpp.
References Graph< T >::delete_edge().
Referenced by voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), semialgebraic2d< C, V >::run(), and arrangement2d< C, V >::run().
00504 { 00505 if(head==NULL) 00506 return; 00507 nvertices--; 00508 00509 gNode<T>* e=head; 00510 00511 // Delete edges from other vertices lists 00512 while(e!=NULL) 00513 { 00514 delete_edge(e->data,v_val); 00515 e=e->vlist; 00516 } 00517 00518 // Delete incident edges 00519 e=head; 00520 while(e!=NULL) 00521 { 00522 delete_edge(v_val,e->data); 00523 e=e->vlist; 00524 } 00525 00526 //Delete Vertex 00527 if(head->data==v_val) 00528 { 00529 gNode<T>* temp=head; 00530 head=head->vlist; 00531 delete temp; 00532 return; 00533 } 00534 00535 gNode<T>* p1=head->vlist; 00536 gNode<T>* p2=head; 00537 00538 while(p1!=NULL) 00539 { 00540 if(p1->data==v_val) 00541 { 00542 p2->vlist=p1->vlist; 00543 p1=NULL; 00544 delete p1; 00545 return; 00546 } 00547 p2=p1; 00548 p1=p1->vlist; 00549 } 00550 }
void dfs | ( | Seq< T > & | out | ) | [inline] |
DFS traversal (output node data in DFS order).
Definition at line 655 of file graph.hpp.
References Graph< T >::dfs_walk(), and gNode< T >::status().
gNode< T > * dfs | ( | test_node | fp | ) | [inline] |
DFS search (find a node that satisfies test fp).
Definition at line 707 of file graph.hpp.
References NODESTACK, and gNode< T >::status().
00708 { 00709 gNode<T>* t=head; 00710 00711 while(t!=NULL) 00712 { 00713 t->status(-1); 00714 t=t->vlist; 00715 } 00716 00717 t=head; 00718 while(t!=NULL) 00719 { 00720 if (t->status()==-1) 00721 { 00722 NODESTACK q; 00723 gNode<T> * s; 00724 00725 q.push(t); 00726 t->status(0); // mark as visited 00727 00728 while ( !q.empty() ) 00729 { 00730 s=q.top(); 00731 q.pop(); 00732 00733 00734 if (fp!=NULL) 00735 if ( (*fp)(s) ) // check node 00736 return s; 00737 00738 while(t->next!=NULL) 00739 { 00740 if (t->next->status()==-1) 00741 { 00742 t->status(0); // mark as visited 00743 q.push(t->next->start); 00744 } 00745 00746 t=t->next; 00747 } 00748 } 00749 } 00750 t=t->vlist; 00751 } 00752 00753 return NULL; 00754 }
void dfs | ( | func | fp | ) | [inline] |
DFS traversal (run operation fp on nodes).
Definition at line 604 of file graph.hpp.
References Graph< T >::dfs_walk(), and gNode< T >::status().
Referenced by mmx::shape::print_boxes(), voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), semialgebraic2d< C, V >::run(), mesher2d< C, V >::run(), and arrangement2d< C, V >::run().
Definition at line 675 of file graph.hpp.
References NODESTACK, and gNode< T >::status().
00676 { 00677 NODESTACK q; 00678 gNode<T> * t; 00679 00680 q.push(s); 00681 00682 while ( !q.empty() ) 00683 { 00684 t=q.top(); 00685 q.pop(); 00686 if ( t->status()==-1) 00687 { 00688 out<< t->data; // output node data 00689 t->status(0); // mark as visited 00690 } 00691 while(t->next!=NULL) 00692 { 00693 if ( t->next->status() == -1 ) 00694 { 00695 q.push(t->next->start); 00696 } 00697 t=t->next; 00698 } 00699 00700 } 00701 }
void dfs_walk | ( | gNode< T > * | s, | |
func | fp | |||
) | [inline] |
Definition at line 623 of file graph.hpp.
References NODESTACK, and gNode< T >::status().
Referenced by Graph< T >::dfs().
00624 { 00625 NODESTACK q; 00626 gNode<T> * t; 00627 00628 q.push(s); 00629 s->status(0); // mark as visited 00630 00631 while ( !q.empty() ) 00632 { 00633 t=q.top(); 00634 q.pop(); 00635 00636 if (fp!=NULL) (*fp)(t); // run operation on node 00637 //std::cout<< t->data<<std::endl; 00638 00639 while(t->next!=NULL) 00640 { 00641 if (t->next->status()==-1) 00642 { 00643 t->status(0); // mark as visited 00644 q.push(t->next->start); 00645 } 00646 t=t->next; 00647 } 00648 } 00649 }
void edge_list | ( | Seq< T > & | e | ) | const [inline] |
gNode< T > * get_start_node | ( | ) | [inline] |
bool member | ( | T | val | ) | const [inline] |
Definition at line 447 of file graph.hpp.
Referenced by voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), semialgebraic2d< C, V >::run(), and arrangement2d< C, V >::run().
00447 { 00448 gNode<T> *t=head; 00449 while( t!=NULL) 00450 if(t->data==val) 00451 return true; 00452 else 00453 t=t->vlist; 00454 return false; 00455 }
unsigned nbe | ( | void | ) | const [inline] |
unsigned nbv | ( | ) | const [inline] |
Seq< T > neighbors | ( | T | e | ) | [inline] |
Definition at line 408 of file graph.hpp.
00409 { 00410 Seq<T> e; 00411 gNode<T>*s, *t=head; 00412 while( t!=NULL) 00413 { 00414 if(t->data==v_val) 00415 { 00416 s=t; 00417 while ( s->next!=NULL) 00418 { 00419 //e<< t->data << s->next->data ; 00420 e<< s->next->data ; 00421 s=s->next; 00422 } 00423 } 00424 t=t->vlist; 00425 } 00426 return e; 00427 }
T next | ( | T | val | ) | const [inline] |
Definition at line 431 of file graph.hpp.
Referenced by voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), semialgebraic2d< C, V >::run(), and arrangement2d< C, V >::run().
00431 { 00432 gNode<T> *t=head; 00433 while( t!=NULL){ 00434 if(t->data==val) 00435 { if (t->next==NULL) 00436 std::cout<<"no neighbor!"<<std::endl; 00437 return t->next->data; 00438 } 00439 t=t->vlist; 00440 } 00441 std::cout<< "Node not in graph."<<std::endl; 00442 return NULL; 00443 }
void print | ( | ) | [inline] |
Print rep of graph - for testing.
Definition at line 175 of file graph.hpp.
00176 { 00177 std::cout<< "Graph: "<< std::endl; 00178 gNode<T> *s, *t=head; 00179 while(t!=NULL) 00180 { 00181 std::cout<< t->data<<" ===> "; 00182 s=t->next; 00183 while(s!=NULL) 00184 { std::cout<< s->data<<", "; s=s->next;} 00185 std::cout<< std::endl; 00186 t=t->vlist; 00187 } 00188 std::cout<< std::endl; 00189 }
void push_edge | ( | T | v_val, | |
T | e_val | |||
) | [inline] |
Insert edge.
Definition at line 339 of file graph.hpp.
Referenced by Graph< Point * >::push_uedge(), voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), semialgebraic2d< C, V >::run(), mesher2d< C, V >::run(), and arrangement2d< C, V >::run().
00340 { 00341 if(head==NULL) 00342 return; 00343 nedges++; 00344 00345 gNode<T>* t=head; 00346 00347 while(t!=NULL) //find vertex v 00348 { 00349 if(t->data==v_val) 00350 { 00351 gNode<T>* temp=new gNode<T>(e_val); 00352 00353 while(t->next!=NULL) 00354 t=t->next; 00355 t->next=temp;// add e to v's neighbors 00356 00357 t=head;//update node info 00358 while(t!=NULL) 00359 { 00360 if(t->data==e_val) 00361 { 00362 temp->me=t->me; 00363 t->me=temp; 00364 //temp->vlist=t->vlist; 00365 temp->start=t; 00366 } 00367 t=t->vlist; 00368 } 00369 00370 return; 00371 } 00372 t=t->vlist; 00373 } 00374 }
void push_uedge | ( | T | v_val, | |
T | e_val | |||
) | [inline] |
Definition at line 142 of file graph.hpp.
Referenced by voronoi2dimpl< C, V >::insert_regular(), and voronoi2d< C, V >::insert_regular().
gNode< T > * push_vertex | ( | T | val, | |
int | i = 0 | |||
) | [inline] |
Insert vertex.
Definition at line 314 of file graph.hpp.
References gNode< T >::aux().
Referenced by voronoi2dimpl< C, V >::insert_regular(), voronoi2d< C, V >::insert_regular(), voronoi2dimpl< C, V >::run(), voronoi2d< C, V >::run(), and mesher2d< C, V >::run().
00314 : sets aux parameter 00315 { 00316 gNode<T>* temp=new gNode<T>(val); 00317 temp->aux(i); 00318 00319 nvertices++; 00320 if(head==NULL) 00321 { 00322 head=temp; 00323 head->me=temp; 00324 return temp; 00325 } 00326 00327 gNode<T>* t=head; 00328 while(t->vlist!=NULL) 00329 t=t->vlist; 00330 00331 t->vlist=temp; 00332 temp->start=temp; 00333 temp->me=temp; 00334 return temp; 00335 }
bool set_start_node | ( | T & | v_val, | |
T & | e_val | |||
) | [inline] |
Definition at line 579 of file graph.hpp.
References Graph< T >::set_start_node().
00580 { 00581 gNode<T>* k=this->head->next; 00582 00583 if (!set_start_node(v_val)) return false; 00584 00585 while(k->next!=NULL) 00586 { 00587 if(k->next->data==e_val) 00588 break; 00589 k=k->next; 00590 } 00591 if (k->next==NULL) return false; 00592 00593 gNode<T> *u= k->next; 00594 k->next = u->next; 00595 u->next = this->head->next; 00596 this->head->next= u; 00597 }
bool set_start_node | ( | T & | val | ) | [inline] |
Definition at line 560 of file graph.hpp.
Referenced by Graph< T >::set_start_node().
00561 { 00562 gNode<T>* k=head; 00563 00564 while(k->vlist!=NULL) //check that vertex exists 00565 { 00566 if(k->vlist->data==val) 00567 break; 00568 k=k->vlist; 00569 } 00570 if (k->vlist==NULL) return false; 00571 00572 gNode<T> *u= k->vlist; 00573 k->vlist = u->vlist; 00574 u->vlist = this->head; 00575 this->head= u; 00576 }
void vertex_list | ( | Seq< T > & | v | ) | const [inline] |
friend class GraphDfsIter< T > [friend] |