Commit 063422d4 authored by Robert Ricci's avatar Robert Ricci

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.
parent d7f45ef6
...@@ -58,7 +58,7 @@ inline int accept(double change, double temperature) ...@@ -58,7 +58,7 @@ inline int accept(double change, double temperature)
} else { } else {
p = expf(change/temperature) * 1000; p = expf(change/temperature) * 1000;
} }
r = random() % 1000; r = RANDOM() % 1000;
if (r < p) { if (r < p) {
return 1; return 1;
} }
...@@ -182,8 +182,8 @@ tb_pnode *find_pnode_connected(vvertex vv, tb_vnode *vn) { ...@@ -182,8 +182,8 @@ tb_pnode *find_pnode_connected(vvertex vv, tb_vnode *vn) {
visit_order[i] = *vedge_it; visit_order[i] = *vedge_it;
} }
for (int i = 0; i < visit_order.size(); i++) { for (int i = 0; i < visit_order.size(); i++) {
int i1 = random() % visit_order.size(); int i1 = RANDOM() % visit_order.size();
int i2 = random() % visit_order.size(); int i2 = RANDOM() % visit_order.size();
vedge tmp = visit_order[i1]; vedge tmp = visit_order[i1];
visit_order[i1] = visit_order[i2]; visit_order[i1] = visit_order[i2];
visit_order[i2] = tmp; visit_order[i2] = tmp;
...@@ -241,8 +241,8 @@ tb_pnode *find_pnode(tb_vnode *vn) ...@@ -241,8 +241,8 @@ tb_pnode *find_pnode(tb_vnode *vn)
traversal_order[i] = i; traversal_order[i] = i;
} }
for (int i = 0; i < num_types; i++) { for (int i = 0; i < num_types; i++) {
int i1 = random() % num_types; int i1 = RANDOM() % num_types;
int i2 = random() % num_types; int i2 = RANDOM() % num_types;
int tmp = traversal_order[i1]; int tmp = traversal_order[i1];
traversal_order[i1] = traversal_order[i2]; traversal_order[i1] = traversal_order[i2];
traversal_order[i2] = tmp; traversal_order[i2] = tmp;
...@@ -451,7 +451,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -451,7 +451,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
absassignment[*vit] = vn->assignment; absassignment[*vit] = vn->assignment;
abstypes[*vit] = vn->type; abstypes[*vit] = vn->type;
} else { } 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, ...@@ -585,7 +585,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
assert(!get(vvertex_pmap,vv)->assigned); assert(!get(vvertex_pmap,vv)->assigned);
unassigned_nodes.pop(); unassigned_nodes.pop();
} else { } else {
int start = random()%nnodes; int start = RANDOM()%nnodes;
int choice = start; int choice = start;
while (get(vvertex_pmap,virtual_nodes[choice])->fixed) { while (get(vvertex_pmap,virtual_nodes[choice])->fixed) {
choice = (choice +1) % nnodes; choice = (choice +1) % nnodes;
...@@ -626,7 +626,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -626,7 +626,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
// Actually find a pnode // Actually find a pnode
tb_pnode *newpnode = NULL; tb_pnode *newpnode = NULL;
if ((use_connected_pnode_find != 0) 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); newpnode = find_pnode_connected(vv,vn);
} }
if (newpnode == NULL) { if (newpnode == NULL) {
...@@ -641,7 +641,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -641,7 +641,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
if (newpnode == NULL) { if (newpnode == NULL) {
// We're not going to be re-assigning this one // We're not going to be re-assigning this one
#ifndef SMART_UNMAP #ifndef SMART_UNMAP
unassigned_nodes.push(vvertex_int_pair(vv,random())); unassigned_nodes.push(vvertex_int_pair(vv,RANDOM()));
#endif #endif
// need to free up nodes // need to free up nodes
#ifdef SMART_UNMAP #ifdef SMART_UNMAP
...@@ -656,7 +656,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -656,7 +656,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
pclass_vector *acceptable_types = tt.second; pclass_vector *acceptable_types = tt.second;
// Find a node to kick out // Find a node to kick out
bool foundnode = false; bool foundnode = false;
int offi = random(); int offi = RANDOM();
int index; int index;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
index = (i + offi) % size; index = (i + offi) % size;
...@@ -675,14 +675,14 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -675,14 +675,14 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
assert((*acceptable_types)[index]->used_members[vn->type]->size()); assert((*acceptable_types)[index]->used_members[vn->type]->size());
tb_pclass::tb_pnodeset::iterator it = tb_pclass::tb_pnodeset::iterator it =
(*acceptable_types)[index]->used_members[vn->type]->begin(); (*acceptable_types)[index]->used_members[vn->type]->begin();
int j = random() % int j = RANDOM() %
(*acceptable_types)[index]->used_members[vn->type]->size(); (*acceptable_types)[index]->used_members[vn->type]->size();
while (j > 0) { while (j > 0) {
it++; it++;
j--; j--;
} }
tb_vnode_set::iterator it2 = (*it)->assigned_nodes.begin(); 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) { while (k > 0) {
it2++; it2++;
k--; k--;
...@@ -693,13 +693,13 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -693,13 +693,13 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
newpnode = *it; newpnode = *it;
remove_node(toremove); remove_node(toremove);
unassigned_nodes.push(vvertex_int_pair(toremove, unassigned_nodes.push(vvertex_int_pair(toremove,
random())); RANDOM()));
} else { } else {
cerr << "Failed to find a replacement!" << endl; cerr << "Failed to find a replacement!" << endl;
} }
#else #else
int start = random()%nnodes; int start = RANDOM()%nnodes;
int toremove = start; int toremove = start;
#ifdef SMART_UNMAP #ifdef SMART_UNMAP
...@@ -748,7 +748,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -748,7 +748,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
RDEBUG(cout << "removing: freeing up nodes" << endl;) RDEBUG(cout << "removing: freeing up nodes" << endl;)
remove_node(virtual_nodes[toremove]); remove_node(virtual_nodes[toremove]);
unassigned_nodes.push(vvertex_int_pair(virtual_nodes[toremove], unassigned_nodes.push(vvertex_int_pair(virtual_nodes[toremove],
random())); RANDOM()));
} }
continue; continue;
#endif /* SMART_UNMAP */ #endif /* SMART_UNMAP */
...@@ -786,12 +786,12 @@ void anneal(bool scoring_selftest, double scale_neighborhood, ...@@ -786,12 +786,12 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
} }
} }
if (add_node(vv,newpos,false,false) != 0) { 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; continue;
} }
} else { } else {
#ifdef SMART_UNMAP #ifdef SMART_UNMAP
unassigned_nodes.push(vvertex_int_pair(vv,random())); unassigned_nodes.push(vvertex_int_pair(vv,RANDOM()));
#endif #endif
if (freednode) { if (freednode) {
continue; continue;
......
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0 #if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map> #include <ext/hash_map>
using namespace __gnu_cxx; using namespace __gnu_cxx;
#define RANDOM() random()
#else #else
#include <hash_map> #include <hash_map>
#define RANDOM() std::random()
#endif #endif
#include "config.h" #include "config.h"
......
...@@ -1067,7 +1067,7 @@ int add_node(vvertex vv,pvertex pv, bool deterministic, bool is_fixed) ...@@ -1067,7 +1067,7 @@ int add_node(vvertex vv,pvertex pv, bool deterministic, bool is_fixed)
int index; int index;
if (!deterministic && !greedy_link_assignment) { if (!deterministic && !greedy_link_assignment) {
float choice; float choice;
choice = random()%(int)total_weight; choice = RANDOM()%(int)total_weight;
for (index = 0;index < resolution_index;++index) { for (index = 0;index < resolution_index;++index) {
switch (resolutions[index].type_used) { switch (resolutions[index].type_used) {
case tb_link_info::LINK_DIRECT: case tb_link_info::LINK_DIRECT:
......
...@@ -77,10 +77,10 @@ crope tb_vclass::choose_type() ...@@ -77,10 +77,10 @@ crope tb_vclass::choose_type()
{ {
// This may take some tweaking - i.e. might want to make more // This may take some tweaking - i.e. might want to make more
// efficient, although members is usually a very small hash. // efficient, although members is usually a very small hash.
if (random()%2 == 0) { if (RANDOM()%2 == 0) {
return dominant; return dominant;
} }
int r = random()%members.size(); int r = RANDOM()%members.size();
members_map::iterator dit; members_map::iterator dit;
for (dit=members.begin();dit != members.end();++dit) { for (dit=members.begin();dit != members.end();++dit) {
if (r == 0) break; if (r == 0) break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment