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

peter.cc

00001 #include<scil/scil.h>
00002 #include <boost/graph/adjacency_list.hpp>
00003 
00004 #define K 16
00005 #define N 20
00006 #define KK 256
00007 #define P 0.55
00008 
00009 using namespace SCIL;
00010 using namespace boost;
00011 
00012 int main() {
00013 
00014   typedef adjacency_list< vecS, vecS, directedS > Graph;
00015   typedef graph_traits<Graph>::edge_descriptor edge;    
00016   typedef graph_traits<Graph>::vertex_descriptor vertex;        
00017   typedef graph_traits<Graph>::edge_iterator edge_iterator;     
00018 
00019 
00020   Graph G;
00021   var V[N+KK];
00022   ILP_Problem IP(Optsense_Min);
00023 
00024   // create vertices
00025   for( int i=0;i<N+KK;i++ )
00026     add_vertex(G);
00027 
00028 
00029   // Generate edges with probability P
00030   srand ( time(NULL) );
00031   double d;
00032   for(int i=0; i<N; i++) 
00033     for(int j=0; j<KK; j++) {
00034       d = (double)rand()/RAND_MAX;
00035       if(d<=P) add_edge(i,N+j,G);
00036   };
00037 
00038 
00039   // add variable
00040   for(int i=0; i<N; i++) V[i]=IP.add_binary_variable(1);
00041   for(int i=N; i<N+KK; i++) V[i]=IP.add_binary_variable(0);
00042 
00043   // add constraints
00044   edge_iterator ei,ei_end;
00045   for( tie(ei,ei_end) =edges(G); ei!=ei_end; ++ei )
00046     IP.add_basic_constraint((row) V[source(*ei,G)]>=V[target(*ei,G)]);
00047 
00048   row r;
00049   for(int i=N; i<N+KK; i++) r+=V[i];
00050   IP.add_basic_constraint(r==K);
00051 
00052   // solve
00053   IP.optimize();
00054 
00055   return 0;
00056 
00057 
00058   /*Graph G;
00059   vertex L[N];
00060   vertex R[KK];
00061   var V[N+KK];
00062   map<vertex,int> VM;
00063   ILP_Problem IP(Optsense_Min);
00064   
00065   for( int i=0;i<N;i++ ){
00066     L[i] = add_vertex(G);
00067     VM[L[i]] = i;
00068   }
00069 
00070   for( int i=0;i<KK;i++ ){
00071     R[i]=add_vertex(G);
00072     VM[R[i]]=i+N;
00073   }
00074 
00075  // initialize random seed:
00076   srand ( time(NULL) );
00077 
00078   // Generate edges with probability P
00079   double d;
00080   for(int i=0; i<N; i++) for(int j=0; j<KK; j++) {
00081     d = (double)rand()/RAND_MAX;
00082     if(d<=P) add_edge(L[i],R[j],G);
00083   };
00084 
00085 
00086   for(int i=0; i<N; i++) V[i]=IP.add_binary_variable(1);
00087   for(int i=N; i<N+KK; i++) V[i]=IP.add_binary_variable(0);
00088 
00089   edge_iterator ei,ei_end;
00090   for( tie(ei,ei_end) =edges(G); ei!=ei_end; ++ei )
00091     IP.add_basic_constraint((row) V[VM[source(*ei,G)]]>=V[VM[target(*ei,G)]]);
00092 
00093   row r;
00094   for(int i=N; i<N+KK; i++) r+=V[i];
00095   IP.add_basic_constraint(r==K);
00096 
00097   IP.optimize();
00098 
00099   return 0; */
00100 }
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3