|
4 | 4 | #include "SimulatedAnnealingCore.h" |
5 | 5 |
|
6 | 6 | #include <algorithm> |
| 7 | +#include <boost/random/uniform_int_distribution.hpp> |
7 | 8 | #include <cmath> |
8 | 9 | #include <fstream> |
9 | 10 | #include <iostream> |
@@ -601,27 +602,14 @@ void SimulatedAnnealingCore<T>::exchangeMacros() |
601 | 602 | template <class T> |
602 | 603 | void SimulatedAnnealingCore<T>::generateRandomIndices(int& index1, int& index2) |
603 | 604 | { |
604 | | - // TODO: See for explanation. |
605 | | - // https://github.com/The-OpenROAD-Project/OpenROAD/pull/6649 |
606 | | - // This code is ugly on purpose to incentivize merging the proper |
607 | | - // fix. |
608 | | - float random_variable_0_1_index1; |
609 | | - float random_variable_0_1_index2; |
610 | | - do { |
611 | | - random_variable_0_1_index1 = distribution_(generator_); |
612 | | - random_variable_0_1_index2 = distribution_(generator_); |
613 | | - } while (random_variable_0_1_index1 >= 1.0 |
614 | | - || random_variable_0_1_index2 >= 1.0); |
615 | | - |
616 | | - index1 = (int) (std::floor(random_variable_0_1_index1 * pos_seq_.size())); |
617 | | - index2 = (int) (std::floor(random_variable_0_1_index2 * pos_seq_.size())); |
| 605 | + boost::random::uniform_int_distribution<> index_distribution( |
| 606 | + 0, pos_seq_.size() - 1); |
618 | 607 |
|
619 | | - while (index1 == index2) { |
620 | | - do { |
621 | | - random_variable_0_1_index2 = distribution_(generator_); |
622 | | - } while (random_variable_0_1_index2 >= 1.0); |
| 608 | + index1 = index_distribution(generator_); |
| 609 | + index2 = index_distribution(generator_); |
623 | 610 |
|
624 | | - index2 = (int) (std::floor(random_variable_0_1_index2 * pos_seq_.size())); |
| 611 | + while (index1 == index2) { |
| 612 | + index2 = index_distribution(generator_); |
625 | 613 | } |
626 | 614 | } |
627 | 615 |
|
|
0 commit comments