Commit 12b109f8 authored by Robert Ricci's avatar Robert Ricci

Fix the names of some very badly-name variables

The 'best' variable didn't really store the best score seen so far,
so rename it to prev_score. Likewise for the bestviolated variable.
parent 26e0a6c6
...@@ -20,9 +20,6 @@ static const char rcsid[] = "$Id: anneal.cc,v 1.46 2009-05-20 18:06:07 tarunp Ex ...@@ -20,9 +20,6 @@ static const char rcsid[] = "$Id: anneal.cc,v 1.46 2009-05-20 18:06:07 tarunp Ex
* Internal variables * Internal variables
*/ */
// These variables store the best solution. // These variables store the best solution.
//node_map absassignment; // assignment field of vnode
//assigned_map absassigned; // assigned field of vnode
//type_map abstypes; // type field of vnode
solution best_solution; solution best_solution;
// Map of virtual node name to its vertex descriptor. // Map of virtual node name to its vertex descriptor.
...@@ -207,15 +204,24 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -207,15 +204,24 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
{ {
cout << "Annealing." << endl; cout << "Annealing." << endl;
double newscore = 0; /*
double bestscore = 0; * The score and number of violations at the start of the inner annealing
* loop
*/
double prev_score = 0;
int prev_violated = 0;
/*
*
*/
double new_score = 0;
double scorediff;
// The number of iterations that took place. // The number of iterations that took place.
iters = 0; iters = 0;
iters_to_best = 0; iters_to_best = 0;
int accepts = 0; int accepts = 0;
double scorediff;
int nnodes = num_vertices(VG); int nnodes = num_vertices(VG);
//int npnodes = num_vertices(PG); //int npnodes = num_vertices(PG);
...@@ -228,7 +234,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -228,7 +234,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
int naccepts = 20*(nnodes + PHYSICAL(npnodes)); int naccepts = 20*(nnodes + PHYSICAL(npnodes));
pvertex oldpos; pvertex oldpos;
bool oldassigned; bool oldassigned;
int bestviolated;
int num_fixed=0; int num_fixed=0;
double meltedtemp; double meltedtemp;
temp = init_temp; temp = init_temp;
...@@ -378,16 +383,16 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -378,16 +383,16 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
/* /*
* Find out the starting temperature * Find out the starting temperature
*/ */
bestscore = get_score(); prev_score = get_score();
bestviolated = violated; prev_violated = violated;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Problem started with score "<<bestscore<<" and "<< violated cout << "Problem started with score "<<prev_score<<" and "<< violated
<< " violations." << endl; << " violations." << endl;
#endif #endif
absbest = bestscore; best_score = prev_score;
absbestviolated = bestviolated; best_violated = prev_violated;
/* /*
* Make a list of all nodes that are still unassigned * Make a list of all nodes that are still unassigned
...@@ -397,9 +402,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -397,9 +402,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
for (;vit!=veit;++vit) { for (;vit!=veit;++vit) {
tb_vnode *vn = get(vvertex_pmap,*vit); tb_vnode *vn = get(vvertex_pmap,*vit);
if (vn->assigned) { if (vn->assigned) {
// XXX
// absassignment[*vit] = vn->assignment;
// abstypes[*vit] = vn->type;
best_solution.set_assignment(*vit,vn->assignment); best_solution.set_assignment(*vit,vn->assignment);
best_solution.set_vtype_assignment(*vit,vn->type); best_solution.set_vtype_assignment(*vit,vn->type);
} else { } else {
...@@ -530,10 +532,10 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -530,10 +532,10 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
#endif #endif
#ifdef VERBOSE #ifdef VERBOSE
cout << "Temperature: " << temp << " AbsBest: " << absbest << cout << "Temperature: " << temp << " Best: " << best_score <<
" (" << absbestviolated << ")" << endl; " (" << best_violated << ")" << endl;
#endif #endif
/* /*
* Initialize this temperature step * Initialize this temperature step
*/ */
...@@ -541,9 +543,9 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -541,9 +543,9 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
accepts = 0; accepts = 0;
nincreases = ndecreases = 0; nincreases = ndecreases = 0;
avgincrease = 0.0; avgincrease = 0.0;
avgscore = bestscore; avgscore = prev_score;
#ifdef CHILL #ifdef CHILL
scores[0] = bestscore; scores[0] = prev_score;
#endif #endif
// Adjust the number of transitions we're going to do based on the number // Adjust the number of transitions we're going to do based on the number
...@@ -569,6 +571,9 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -569,6 +571,9 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
|| (!melting && (trans < mintrans && accepts < naccepts))) { || (!melting && (trans < mintrans && accepts < naccepts))) {
#endif #endif
RDEBUG(cout << "ANNEALING: Loop starts with score " << get_score() <<
" violations " << violated << endl;)
#ifdef STATS #ifdef STATS
cout << "STATS temp:" << temp << " score:" << get_score() << cout << "STATS temp:" << temp << " score:" << get_score() <<
" violated:" << violated << " trans:" << trans << " violated:" << violated << " trans:" << trans <<
...@@ -701,7 +706,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -701,7 +706,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
toremove = (toremove +1) % nnodes; toremove = (toremove +1) % nnodes;
if (toremove == start) { if (toremove == start) {
toremove = -1; toremove = -1;
RDEBUG("Not removing a node" << endl;) RDEBUG(cout << "Not removing a node" << endl;)
break; break;
} }
} }
...@@ -731,7 +736,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -731,7 +736,7 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
* Okay, we've got pnode to map this vnode to - let's do it * Okay, we've got pnode to map this vnode to - let's do it
*/ */
if (newpnode != NULL) { if (newpnode != NULL) {
RDEBUG(cout << "MOVE: " << vn->name << " to " << newpnode->name << " ";) RDEBUG(cout << "MOVE: " << vn->name << " to " << newpnode->name << " " << endl;)
newpos = pnode2vertex[newpnode]; newpos = pnode2vertex[newpnode];
if (scoring_selftest) { if (scoring_selftest) {
// Run a little test here - see if the score we get by adding // Run a little test here - see if the score we get by adding
...@@ -780,11 +785,11 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -780,11 +785,11 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
/* /*
* Okay, now that we've mapped some new node, let's check the scoring * Okay, now that we've mapped some new node, let's check the scoring
*/ */
newscore = get_score(); new_score = get_score();
assert(newscore >= 0); assert(new_score >= 0);
// Negative means bad // Negative means bad
scorediff = bestscore - newscore; scorediff = prev_score - new_score;
// This looks funny, because < 0 means worse, which means an increase in // This looks funny, because < 0 means worse, which means an increase in
// score // score
if (scorediff < 0) { if (scorediff < 0) {
...@@ -808,14 +813,14 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -808,14 +813,14 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
#ifdef NO_VIOLATIONS #ifdef NO_VIOLATIONS
// Here, we don't consider violations at all, just whether the regular // Here, we don't consider violations at all, just whether the regular
// simulated annealing accept conditions // simulated annealing accept conditions
if (newscore < bestscore) { if (new_score < prev_score) {
accepttrans = true; accepttrans = true;
RDEBUG(cout << "accept: better (" << newscore << "," << bestscore RDEBUG(cout << "accept: better (" << new_score << "," << prev_score
<< ")" << endl;) << ")" << endl;)
} else if (accept(scorediff,temp)) { } else if (accept(scorediff,temp)) {
accepttrans = true; accepttrans = true;
RDEBUG(cout << "accept: metropolis (" << newscore << "," RDEBUG(cout << "accept: metropolis (" << new_score << ","
<< bestscore << "," << expf(scorediff/(temp*sensitivity)) << prev_score << "," << expf(scorediff/(temp*sensitivity))
<< ")" << endl;) << ")" << endl;)
} }
#else #else
...@@ -836,21 +841,24 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -836,21 +841,24 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
* progress. This prevents the cooling schedule from converging for * progress. This prevents the cooling schedule from converging for
* much, much longer than it should really take. * much, much longer than it should really take.
*/ */
if ((violated == bestviolated) && (newscore < bestscore)) { RDEBUG(cout << "CRITERIA: v=" << violated << " bv=" <<
prev_violated << " ns=" << new_score << " bs=" <<
prev_score << " sd=" << scorediff << " t=" << temp << endl;)
if ((violated == prev_violated) && (new_score < prev_score)) {
accepttrans = true; accepttrans = true;
RDEBUG(cout << "accept: better (" << newscore << "," << bestscore RDEBUG(cout << "accept: better (" << new_score << "," << prev_score
<< ")" << endl;) << ")" << endl;)
} else if (violated < bestviolated) { } else if (violated < prev_violated) {
accepttrans = true; accepttrans = true;
RDEBUG(cout << "accept: better (violations) (" << newscore << "," RDEBUG(cout << "accept: better (violations) (" << new_score << ","
<< bestscore << "," << violated << "," << bestviolated << prev_score << "," << violated << "," << prev_violated
<< ")" << endl; << ")" << endl;
cout << "Violations: (new) " << violated << endl; cout << "Violations: (new) " << violated << endl;
cout << vinfo;) cout << vinfo;)
} else if (accept(scorediff,temp)) { } else if (accept(scorediff,temp)) {
accepttrans = true; accepttrans = true;
RDEBUG(cout << "accept: metropolis (" << newscore << "," RDEBUG(cout << "accept: metropolis (" << new_score << ","
<< bestscore << "," << scorediff << "," << temp << prev_score << "," << scorediff << "," << temp
<< ")" << endl;) << ")" << endl;)
} }
#else // no SPECIAL_VIOLATION_TREATMENT #else // no SPECIAL_VIOLATION_TREATMENT
...@@ -865,8 +873,8 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -865,8 +873,8 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
* adding a violation results in a _lower_ score than a solution with * adding a violation results in a _lower_ score than a solution with
* fewer violations. * fewer violations.
*/ */
double adjusted_new_score = newscore + violated * VIOLATION_SCORE; double adjusted_new_score = new_score + violated * VIOLATION_SCORE;
double adjusted_old_score = bestscore + bestviolated * VIOLATION_SCORE; double adjusted_old_score = prev_score + prev_violated * VIOLATION_SCORE;
if (adjusted_new_score < adjusted_old_score) { if (adjusted_new_score < adjusted_old_score) {
accepttrans = true; accepttrans = true;
...@@ -883,21 +891,22 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -883,21 +891,22 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
* Okay, we've decided to accep this transition - do some bookkeeping * Okay, we've decided to accep this transition - do some bookkeeping
*/ */
if (accepttrans) { if (accepttrans) {
bestscore = newscore; // Accept change
bestviolated = violated; prev_score = new_score;
prev_violated = violated;
#ifdef GNUPLOT_OUTPUT #ifdef GNUPLOT_OUTPUT
fprintf(tempout,"%f\n",temp); fprintf(tempout,"%f\n",temp);
fprintf(scoresout,"%f\n",newscore); fprintf(scoresout,"%f\n",new_score);
fprintf(deltaout,"%f\n",-scorediff); fprintf(deltaout,"%f\n",-scorediff);
#endif // GNUPLOT_OUTPUT #endif // GNUPLOT_OUTPUT
avgscore += newscore; avgscore += new_score;
accepts++; accepts++;
#ifdef CHILL #ifdef CHILL
if (!melting) { if (!melting) {
scores[accepts] = newscore; scores[accepts] = new_score;
} }
#endif // CHILL #endif // CHILL
...@@ -906,11 +915,11 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -906,11 +915,11 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
* further bookkeeping - copy it into the structures for our best solution * further bookkeeping - copy it into the structures for our best solution
*/ */
#ifdef NO_VIOLATIONS #ifdef NO_VIOLATIONS
if (newscore < absbest) { if (new_score < best_score) {
#else // NO_VIOLATIONS #else // NO_VIOLATIONS
if ((violated < absbestviolated) || if ((violated < best_violated) ||
((violated == absbestviolated) && ((violated == best_violated) &&
(newscore < absbest))) { (new_score < best_score))) {
#endif // NO_VIOLATIONS #endif // NO_VIOLATIONS
#ifdef SCORE_DEBUG #ifdef SCORE_DEBUG
...@@ -925,9 +934,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -925,9 +934,6 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
} else { } else {
best_solution.clear_assignment(*vit); best_solution.clear_assignment(*vit);
} }
//absassignment[*vit] = get(vvertex_pmap,*vit)->assignment;
//absassigned[*vit] = get(vvertex_pmap,*vit)->assigned;
//abstypes[*vit] = get(vvertex_pmap,*vit)->type;
} }
vedge_iterator edge_it, edge_it_end; vedge_iterator edge_it, edge_it_end;
...@@ -941,14 +947,13 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes, ...@@ -941,14 +947,13 @@ void anneal(bool scoring_selftest, bool check_fixed_nodes,
} }
} }
absbest = newscore; best_score = new_score;
absbestviolated = violated; best_violated = violated;
iters_to_best = iters; iters_to_best = iters;
#ifdef SCORE_DEBUG #ifdef SCORE_DEBUG
cerr << "New best recorded" << endl; cerr << "New best recorded" << endl;
#endif #endif
} }
// Accept change
} else { // !acceptrans } else { // !acceptrans
// Reject change, go back to the state we were in before // Reject change, go back to the state we were in before
RDEBUG(cout << "removing: rejected change" << endl;) RDEBUG(cout << "removing: rejected change" << endl;)
...@@ -1147,7 +1152,7 @@ NOTQUITEDONE: ...@@ -1147,7 +1152,7 @@ NOTQUITEDONE:
(deltaavg > 0) && ((temp / initialavg) * (deltaavg/ deltatemp) < epsilon)) { (deltaavg > 0) && ((temp / initialavg) * (deltaavg/ deltatemp) < epsilon)) {
#endif #endif
#ifdef FINISH_HILLCLIMB #ifdef FINISH_HILLCLIMB
if (!finishedonce && ((absbestviolated <= violated) && (absbest < bestscore))) { if (!finishedonce && ((best_violated <= violated) && (best_score < prev_score))) {
// We don't actually stop, we just go do a hill-climb (basically) at the best // We don't actually stop, we just go do a hill-climb (basically) at the best
// one we previously found // one we previously found
finishedonce = true; finishedonce = true;
...@@ -1216,11 +1221,11 @@ NOTQUITEDONE: ...@@ -1216,11 +1221,11 @@ NOTQUITEDONE:
* it either in violations or in score. * it either in violations or in score.
*/ */
#ifndef NO_REVERT #ifndef NO_REVERT
if (REVERT_VIOLATIONS && (absbestviolated < violated)) { if (REVERT_VIOLATIONS && (best_violated < violated)) {
cout << "Reverting: REVERT_VIOLATIONS" << endl; cout << "Reverting: REVERT_VIOLATIONS" << endl;
revert = true; revert = true;
} }
if (absbest < bestscore) { if (best_score < prev_score) {
cout << "Reverting: best score" << endl; cout << "Reverting: best score" << endl;
revert = true; revert = true;
} }
......
...@@ -84,8 +84,8 @@ extern float temp_rate; ...@@ -84,8 +84,8 @@ extern float temp_rate;
extern pclass_types type_table; extern pclass_types type_table;
extern pclass_list pclasses; extern pclass_list pclasses;
extern pnode_pvertex_map pnode2vertex; extern pnode_pvertex_map pnode2vertex;
extern double absbest; extern double best_score;
extern int absbestviolated, iters, iters_to_best; extern int best_violated, iters, iters_to_best;
extern bool allow_overload; extern bool allow_overload;
#ifdef PER_VNODE_TT #ifdef PER_VNODE_TT
......
...@@ -145,9 +145,19 @@ bool ptop_rspec_input = false; ...@@ -145,9 +145,19 @@ bool ptop_rspec_input = false;
bool vtop_rspec_input = false; bool vtop_rspec_input = false;
#endif #endif
// XXX - shouldn't be in this file /*
double absbest; * Score and violations for the best score found so far
int absbestviolated, iters, iters_to_best; * XXX - shouldn't be in this file
*/
double best_score;
int best_violated;
/*
* Number of iterations executed so far, and how many it took us to find the
* best solution
* XXX - shouldn't be in this file
*/
int iters, iters_to_best;
// Map of all physical types in use in the system // Map of all physical types in use in the system
tb_ptype_map ptypes; tb_ptype_map ptypes;
...@@ -831,7 +841,7 @@ void exit_unretryable(int signal) { ...@@ -831,7 +841,7 @@ void exit_unretryable(int signal) {
extern double temp; extern double temp;
void status_report(int signal) { void status_report(int signal) {
cout << "I: " << iters << " T: " << temp << " S: " << get_score() << " V: " cout << "I: " << iters << " T: " << temp << " S: " << get_score() << " V: "
<< violated << " (Best S: " << absbest << " V:" << absbestviolated << ")" << violated << " (Best S: " << best_score << " V:" << best_violated << ")"
<< endl; << endl;
cout.flush(); cout.flush();
} }
...@@ -1218,11 +1228,11 @@ int main(int argc,char **argv) { ...@@ -1218,11 +1228,11 @@ int main(int argc,char **argv) {
fclose(deltaout); fclose(deltaout);
#endif #endif
if ((!compare_scores(get_score(),absbest)) || (violated > absbestviolated)) { if ((!compare_scores(get_score(),best_score)) || (violated > best_violated)) {
cout << "WARNING: Internal scoring inconsistency." << endl; cout << "WARNING: Internal scoring inconsistency." << endl;
cout << "score:" << get_score() << " absbest:" << absbest << cout << "score:" << get_score() << " best_score:" << best_score <<
" violated:" << violated << " absbestviolated:" << " violated:" << violated << " best_violated:" <<
absbestviolated << endl; best_violated << endl;
} }
cout << " BEST SCORE: " << get_score() << " in " << iters << cout << " BEST SCORE: " << get_score() << " in " << iters <<
......
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