Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

dmst.c

00001 #include<LEDA/graph.h>
00002 #include<LEDA/graphwin.h>
00003 #include<LEDA/graph_misc.h>
00004 #include<LEDA/delaunay.h>
00005 
00006 #include<scil/scil.h>
00007 #include<scil/constraints/path.h>
00008 
00009 #include"compute_dmst.c"
00010 
00011 void make_complete(GraphWin& GW) {
00012   GW.set_flush(false);
00013   graph& G=GW.get_graph();
00014 
00015   G.del_all_edges();
00016 
00017   node u,v;
00018   forall_nodes(u,G) forall_nodes(v, G) if(u!=v) {
00019     G.new_edge(u,v);
00020   }
00021 
00022   GW.update_graph();
00023   GW.redraw();
00024   GW.set_flush(true);
00025   GW.redraw();
00026 }
00027 
00028 void triang_points(GraphWin& GW) 
00029 {
00030   graph& G=GW.get_graph();
00031   int n=G.number_of_nodes();
00032   if (n!=0) {
00033   
00034     GW.set_flush(false);
00035 
00036     point_set T;  
00037     node_array<node> tr(T,n,nil);
00038     node_array<int> num(T,n,0);
00039     node v,v1;
00040     int i=0;
00041 
00042     double x,y;
00043     forall_nodes(v1,G) 
00044     {
00045       x=GW.get_position(v1).xcoord();
00046       y=GW.get_position(v1).ycoord();
00047       point p(x,y);
00048       v=T.insert(p);
00049       tr[v]=v1;
00050       num[v]=i++;
00051      }
00052 
00053     G.del_all_edges();
00054     GW.update_graph();
00055     edge e;
00056     forall_edges(e,T) if (num[T.source(e)]<num[T.target(e)])
00057                         GW.new_edge(tr[T.source(e)],tr[T.target(e)]);
00058     GW.redraw();
00059     GW.set_flush(true);
00060     GW.redraw();
00061   }
00062 }
00063 
00064 void generate_del(GraphWin& GW) 
00065 {
00066   graph& G=GW.get_graph();
00067   if (!G.empty()) GW.clear_graph();
00068 
00069   int n=10;
00070 
00071   panel p;
00072   p.int_item("Number of nodes : ",n);
00073   p.open(GW.get_window());
00074  
00075   random_source ran;
00076 
00077   double x,y;
00078   for(int i=0;i<n;i++) 
00079   { ran >> x >> y;
00080     x=(x+0.08)*(GW.get_xmax()-GW.get_xmin())*0.9+GW.get_xmin();
00081     y=(y+0.08)*(GW.get_ymax()-GW.get_ymin())*0.9+GW.get_ymin();
00082     point p1(x,y);
00083     GW.new_node(p1);
00084    }
00085   triang_points(GW);
00086 }
00087 
00088 int main()
00089 {
00090   GraphWin GW;
00091 
00092 // Setup of the graph window
00093   GW.set_node_width(8);
00094   GW.set_node_height(8);
00095   GW.set_flush(true);
00096   GW.set_edge_direction(undirected_edge);
00097 
00098 // Additional functionality of the graph window; the implementation is hidden
00099   int gn=gw_add_menu(GW,"Generation");
00100   gw_add_simple_call(GW,triang_points,"Triangulate defined points",gn);
00101   gw_add_simple_call(GW,generate_del, "Generate random Delaunay-Graph",gn);
00102   gw_add_simple_call(GW,make_complete, "Make Complete Graph", gn);
00103 
00104   GW.display();
00105 
00106   while(GW.edit())
00107   {
00108     make_complete(GW);
00109 
00110     graph& G=GW.get_graph();
00111 
00112     edge e;
00113     edge_array<double> C(G);
00114     forall_edges(e, G) 
00115       C[e]=GW.get_position(source(e)).distance(GW.get_position(target(e)));
00116 
00117     list<edge> T;
00118     ComputeDMST(G, C, T);
00119 
00120     GW.set_flush(false);
00121     forall_edges(e,G) {
00122       GW.set_color(e, black);
00123     }
00124     forall(e,T) { 
00125       GW.set_color(e,red);
00126     }
00127     forall_edges(e,G) if(GW.get_color(e)==black) {
00128       GW.del_edge(e);
00129     }
00130     GW.redraw();
00131     GW.set_flush(true);
00132   }
00133   return 0;
00134 }
00135 

Generated on Tue Nov 16 15:18:16 2004 for SCIL by doxygen1.2.16