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

broadcast.cc

00001 #include <boost/graph/adjacency_list.hpp>
00002 #include <boost/graph/iteration_macros.hpp>
00003 #include <scil/constraints/stronglyconnected.h>
00004 #include <scil/scil.h>
00005 
00006 using namespace SCIL;
00007 using namespace std;
00008 using boost::no_property;
00009 using boost::directedS;
00010 using boost::undirectedS;
00011 using boost::bidirectionalS;
00012 using boost::vecS;
00013 using boost::property;
00014 using boost::edge_weight_t;
00015 
00016 #define MAX_DOUBLE 10e+300
00017 #define MAX_INT 1000000
00018 
00019 
00020 typedef boost::adjacency_list<vecS,vecS,undirectedS, no_property, property<edge_weight_t, double> > Graph;
00021 typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
00022 typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
00023 
00024 
00025 #include"sym_connect.cc"
00026 
00028 struct point {
00029     double x;
00030     double y;
00031 
00032     point(double x_ = 0.0, double y_ = 0.0) : x(x_), y(y_) { }; 
00033 
00034     // Distance to another point. 
00035     double distance(point other) {
00036       double xd = x - other.x;
00037       double yd = y - other.y;
00038       return sqrt(xd * xd + yd * yd);
00039     }
00040 };
00041 
00042 void make_tests(char* s) {
00043 
00044       cout<<"Instance: "<<s<<endl;
00045       ifstream outp(s);
00046 
00047       double x,y;
00048       edge_descriptor e;
00049       std::list<edge_descriptor> T;
00050 
00051       int i;
00052       outp >> i;
00053 
00054       Graph G;
00055       std::vector<point> P(i);
00056       vertex_descriptor u;
00057 
00058       std::vector<int> N(i);
00059       for(int k=0; k<i; k++) {
00060         outp >> x;
00061         outp >> y;
00062         point p1(x,y);
00063         u=add_vertex(G);
00064         P[u]=p1;
00065         N[u]=k;
00066       }
00067 
00068       // COMPLETE GRAPH
00069       BGL_FORALL_VERTICES(u,G,Graph) {
00070          BGL_FORALL_VERTICES(v,G,Graph) {
00071             if(u>v) add_edge(u,v,G);
00072          }
00073       }
00074 
00075       property_map<Graph,edge_weight_t>::type 
00076         cost = get(edge_weight, G);
00077       BGL_FORALL_EDGES(e,G,Graph) {
00078         cost[e]=P[source(e,G)].distance(P[target(e,G)]); 
00079       }
00080 
00081       ComputeBroadcast(G, T);
00082 };
00083 
00084 
00085 int main(int argc, char** argv)
00086 {
00087   if (argc < 2) {
00088     std::cout<<"usage: broadcase name_of_file";
00089     return 0;
00090   }
00091 
00092   make_tests(argv[1]);
00093 
00094   return 0;
00095 }
00096 
Generated on Mon Mar 28 22:03:47 2011 for SCIL by  doxygen 1.6.3