Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Outputs the distribution of the nodes of a graph in two parts randomly so that each side
- * has the same ammount of nodes
- *
- * @param int size the size of the graph
- * @param vi& v the new distribution of the graph
- *
- * @returns void
- *
- */
- void randomize_Bipartition(int size, vi& v){
- int threshold = (size%2 == 0) ? size/2 : size/2 + 1;
- int r_size, l_size;
- r_size = l_size = 0;
- v = vi(size);
- srand (time(NULL));
- int i = 0;
- while(r_size < threshold and l_size < threshold){
- if(rand()%2 == 0){
- v[i] = 0;
- ++r_size;
- }
- else{
- v[i] = 1;
- ++l_size;
- }
- ++i;
- }
- if(r_size == threshold){
- while(r_size + l_size != size){
- v[i] == 1;
- ++i;
- ++l_size;
- }
- }
- else{
- while(r_size + l_size != size){
- v[i] == 0;
- ++i;
- ++r_size;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement