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
00025 for( int i=0;i<N+KK;i++ )
00026 add_vertex(G);
00027
00028
00029
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
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
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
00053 IP.optimize();
00054
00055 return 0;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 }