From 063422d49f75f934bc7c379d6463dcb0cb23c4ce Mon Sep 17 00:00:00 2001 From: Robert Ricci <ricci@cs.utah.edu> Date: Tue, 8 Jun 2004 19:17:45 +0000 Subject: [PATCH] Sigh, more 'porting'. In gcc 2.95, we have to use std::random() to disambiguate from boost's random() function. But, for some reason, with 3.x, random() doesn't live in the std:: namespace. Macro-ize it. --- assign/anneal.cc | 34 +++++++++++++++++----------------- assign/common.h | 2 ++ assign/score.cc | 2 +- assign/vclass.cc | 4 ++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/assign/anneal.cc b/assign/anneal.cc index bd02b5d79e..6e4773a577 100644 --- a/assign/anneal.cc +++ b/assign/anneal.cc @@ -58,7 +58,7 @@ inline int accept(double change, double temperature) } else { p = expf(change/temperature) * 1000; } - r = random() % 1000; + r = RANDOM() % 1000; if (r < p) { return 1; } @@ -182,8 +182,8 @@ tb_pnode *find_pnode_connected(vvertex vv, tb_vnode *vn) { visit_order[i] = *vedge_it; } for (int i = 0; i < visit_order.size(); i++) { - int i1 = random() % visit_order.size(); - int i2 = random() % visit_order.size(); + int i1 = RANDOM() % visit_order.size(); + int i2 = RANDOM() % visit_order.size(); vedge tmp = visit_order[i1]; visit_order[i1] = visit_order[i2]; visit_order[i2] = tmp; @@ -241,8 +241,8 @@ tb_pnode *find_pnode(tb_vnode *vn) traversal_order[i] = i; } for (int i = 0; i < num_types; i++) { - int i1 = random() % num_types; - int i2 = random() % num_types; + int i1 = RANDOM() % num_types; + int i2 = RANDOM() % num_types; int tmp = traversal_order[i1]; traversal_order[i1] = traversal_order[i2]; traversal_order[i2] = tmp; @@ -451,7 +451,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, absassignment[*vit] = vn->assignment; abstypes[*vit] = vn->type; } else { - unassigned_nodes.push(vvertex_int_pair(*vit,random())); + unassigned_nodes.push(vvertex_int_pair(*vit,RANDOM())); } } @@ -585,7 +585,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, assert(!get(vvertex_pmap,vv)->assigned); unassigned_nodes.pop(); } else { - int start = random()%nnodes; + int start = RANDOM()%nnodes; int choice = start; while (get(vvertex_pmap,virtual_nodes[choice])->fixed) { choice = (choice +1) % nnodes; @@ -626,7 +626,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, // Actually find a pnode tb_pnode *newpnode = NULL; if ((use_connected_pnode_find != 0) - && ((random() % 1000) < (use_connected_pnode_find * 1000))) { + && ((RANDOM() % 1000) < (use_connected_pnode_find * 1000))) { newpnode = find_pnode_connected(vv,vn); } if (newpnode == NULL) { @@ -641,7 +641,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, if (newpnode == NULL) { // We're not going to be re-assigning this one #ifndef SMART_UNMAP - unassigned_nodes.push(vvertex_int_pair(vv,random())); + unassigned_nodes.push(vvertex_int_pair(vv,RANDOM())); #endif // need to free up nodes #ifdef SMART_UNMAP @@ -656,7 +656,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, pclass_vector *acceptable_types = tt.second; // Find a node to kick out bool foundnode = false; - int offi = random(); + int offi = RANDOM(); int index; for (int i = 0; i < size; i++) { index = (i + offi) % size; @@ -675,14 +675,14 @@ void anneal(bool scoring_selftest, double scale_neighborhood, assert((*acceptable_types)[index]->used_members[vn->type]->size()); tb_pclass::tb_pnodeset::iterator it = (*acceptable_types)[index]->used_members[vn->type]->begin(); - int j = random() % + int j = RANDOM() % (*acceptable_types)[index]->used_members[vn->type]->size(); while (j > 0) { it++; j--; } tb_vnode_set::iterator it2 = (*it)->assigned_nodes.begin(); - int k = random() % (*it)->assigned_nodes.size(); + int k = RANDOM() % (*it)->assigned_nodes.size(); while (k > 0) { it2++; k--; @@ -693,13 +693,13 @@ void anneal(bool scoring_selftest, double scale_neighborhood, newpnode = *it; remove_node(toremove); unassigned_nodes.push(vvertex_int_pair(toremove, - random())); + RANDOM())); } else { cerr << "Failed to find a replacement!" << endl; } #else - int start = random()%nnodes; + int start = RANDOM()%nnodes; int toremove = start; #ifdef SMART_UNMAP @@ -748,7 +748,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, RDEBUG(cout << "removing: freeing up nodes" << endl;) remove_node(virtual_nodes[toremove]); unassigned_nodes.push(vvertex_int_pair(virtual_nodes[toremove], - random())); + RANDOM())); } continue; #endif /* SMART_UNMAP */ @@ -786,12 +786,12 @@ void anneal(bool scoring_selftest, double scale_neighborhood, } } if (add_node(vv,newpos,false,false) != 0) { - unassigned_nodes.push(vvertex_int_pair(vv,random())); + unassigned_nodes.push(vvertex_int_pair(vv,RANDOM())); continue; } } else { #ifdef SMART_UNMAP - unassigned_nodes.push(vvertex_int_pair(vv,random())); + unassigned_nodes.push(vvertex_int_pair(vv,RANDOM())); #endif if (freednode) { continue; diff --git a/assign/common.h b/assign/common.h index 0ad485c4a0..58bc13cd0c 100644 --- a/assign/common.h +++ b/assign/common.h @@ -14,8 +14,10 @@ #if __GNUC__ == 3 && __GNUC_MINOR__ > 0 #include <ext/hash_map> using namespace __gnu_cxx; +#define RANDOM() random() #else #include <hash_map> +#define RANDOM() std::random() #endif #include "config.h" diff --git a/assign/score.cc b/assign/score.cc index 949975af77..39d30fc1ed 100644 --- a/assign/score.cc +++ b/assign/score.cc @@ -1067,7 +1067,7 @@ int add_node(vvertex vv,pvertex pv, bool deterministic, bool is_fixed) int index; if (!deterministic && !greedy_link_assignment) { float choice; - choice = random()%(int)total_weight; + choice = RANDOM()%(int)total_weight; for (index = 0;index < resolution_index;++index) { switch (resolutions[index].type_used) { case tb_link_info::LINK_DIRECT: diff --git a/assign/vclass.cc b/assign/vclass.cc index 5efca206c1..a8f974da57 100644 --- a/assign/vclass.cc +++ b/assign/vclass.cc @@ -77,10 +77,10 @@ crope tb_vclass::choose_type() { // This may take some tweaking - i.e. might want to make more // efficient, although members is usually a very small hash. - if (random()%2 == 0) { + if (RANDOM()%2 == 0) { return dominant; } - int r = random()%members.size(); + int r = RANDOM()%members.size(); members_map::iterator dit; for (dit=members.begin();dit != members.end();++dit) { if (r == 0) break; -- GitLab