Skip to content

Commit

Permalink
Debugging simulated annealing on frontier
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Sep 26, 2024
1 parent f030cf6 commit 4bc88dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/apex/simulated_annealing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ double SimulatedAnnealing::acceptance_probability(double new_cost) {

void SimulatedAnnealing::evaluate(double new_cost) {
/* T <- temperature( (k+1)/kmax ) */
temp = (double)(k)/(double)(kmax);
temp = std::min((double)(k)/(double)(kmax), 1.0);
/* If P(E(s), E(snew), T) ≥ random(0, 1): */
/* s <- snew */
if (new_cost < cost) {
Expand Down
26 changes: 19 additions & 7 deletions src/apex/simulated_annealing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,44 @@ class Variable {
if (delta < 0 && (current_index < (size_t)(abs(delta)))) {
// do nothing
//neighbor_index = 0;
} else if (delta > 0 && ((current_index + delta) > maxlen)) {
} else if (delta > 0 && ((current_index + delta) >= maxlen)) {
// do nothing
//neighbor_index = maxlen;
} else {
neighbor_index = current_index + delta;
}
/*
std::cout << "scope: " << scope
<< " quarter: " << quarter
<< " delta: " << delta
<< " current_index: " << delta
<< " neighbor_index: " << delta
<< std::endl;
*/
if (vtype == VariableType::doubletype) {
*((double*)(value)) = dvalues[neighbor_index];
//std::cout << "next value : " << *((double*)(value)) << std::endl;
}
else if (vtype == VariableType::longtype) {
*((long*)(value)) = lvalues[neighbor_index];
//std::cout << "next value : " << *((long*)(value)) << std::endl;
}
else {
*((const char**)(value)) = svalues[neighbor_index].c_str();
//std::cout << "next value : " << *((const char**)(value)) << std::endl;
}
/* std::cout << "scope: " << scope
<< " quarter: " << quarter
<< " delta: " << delta
<< " current_index: " << delta
<< " neighbor_index: " << delta
<< std::endl; */
}
void choose_neighbor() { current_index = neighbor_index; }
void save_best() { best_index = current_index; }
void restore_best() { current_index = best_index; }
/* For initializing in the center of the space */
void set_init(void) {
half = maxlen/2;
quarter = (double)half/2;
}
void set_init(double init_value) {
maxlen = dvalues.size();
set_init();
auto it = std::find(dvalues.begin(), dvalues.end(), init_value);
if (it == dvalues.end()) {
current_index = 0;
Expand All @@ -103,6 +113,7 @@ class Variable {
}
void set_init(long init_value) {
maxlen = lvalues.size();
set_init();
auto it = std::find(lvalues.begin(), lvalues.end(), init_value);
if (it == lvalues.end()) {
current_index = 0;
Expand All @@ -112,6 +123,7 @@ class Variable {
}
void set_init(std::string init_value) {
maxlen = svalues.size();
set_init();
auto it = std::find(svalues.begin(), svalues.end(), init_value);
if (it == svalues.end()) {
current_index = 0;
Expand Down

0 comments on commit 4bc88dc

Please sign in to comment.