|
| 1 | + |
1 | 2 | #include "static_move_generator.h" |
2 | | -#include "globals.h" |
3 | | -#include <algorithm> |
| 3 | + |
| 4 | +#include "median_move_generator.h" |
| 5 | +#include "weighted_median_move_generator.h" |
| 6 | +#include "weighted_centroid_move_generator.h" |
| 7 | +#include "feasible_region_move_generator.h" |
| 8 | +#include "uniform_move_generator.h" |
| 9 | +#include "critical_uniform_move_generator.h" |
| 10 | +#include "centroid_move_generator.h" |
4 | 11 |
|
5 | 12 | #include "vtr_random.h" |
6 | 13 | #include "vtr_assert.h" |
7 | 14 |
|
8 | | -StaticMoveGenerator::StaticMoveGenerator(const std::vector<float>& prob) { |
9 | | - avail_moves.emplace_back(std::make_unique<UniformMoveGenerator>()); |
10 | | - avail_moves.emplace_back(std::make_unique<MedianMoveGenerator>()); |
11 | | - avail_moves.emplace_back(std::make_unique<CentroidMoveGenerator>()); |
12 | | - avail_moves.emplace_back(std::make_unique<WeightedCentroidMoveGenerator>()); |
13 | | - avail_moves.emplace_back(std::make_unique<WeightedMedianMoveGenerator>()); |
14 | | - avail_moves.emplace_back(std::make_unique<CriticalUniformMoveGenerator>()); |
15 | | - avail_moves.emplace_back(std::make_unique<FeasibleRegionMoveGenerator>()); |
| 15 | +StaticMoveGenerator::StaticMoveGenerator(const vtr::vector<e_move_type, float>& move_probs) { |
| 16 | + all_moves.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES); |
16 | 17 |
|
17 | | - initialize_move_prob(prob); |
| 18 | + all_moves[e_move_type::UNIFORM] = std::make_unique<UniformMoveGenerator>(); |
| 19 | + all_moves[e_move_type::MEDIAN] = std::make_unique<MedianMoveGenerator>(); |
| 20 | + all_moves[e_move_type::CENTROID] = std::make_unique<CentroidMoveGenerator>(); |
| 21 | + all_moves[e_move_type::W_CENTROID] = std::make_unique<WeightedCentroidMoveGenerator>(); |
| 22 | + all_moves[e_move_type::W_MEDIAN] = std::make_unique<WeightedMedianMoveGenerator>(); |
| 23 | + all_moves[e_move_type::CRIT_UNIFORM] = std::make_unique<CriticalUniformMoveGenerator>(); |
| 24 | + all_moves[e_move_type::FEASIBLE_REGION] = std::make_unique<FeasibleRegionMoveGenerator>(); |
| 25 | + |
| 26 | + initialize_move_prob(move_probs); |
18 | 27 | } |
19 | 28 |
|
20 | | -void StaticMoveGenerator::initialize_move_prob(const std::vector<float>& prob) { |
21 | | - cumm_move_probs.push_back(prob[0]); |
22 | | - for (size_t i = 1; i < prob.size(); i++) { |
23 | | - cumm_move_probs.push_back(prob[i] + cumm_move_probs[i - 1]); |
| 29 | +void StaticMoveGenerator::initialize_move_prob(const vtr::vector<e_move_type, float>& move_probs) { |
| 30 | + cumm_move_probs.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES); |
| 31 | + std::fill(cumm_move_probs.begin(), cumm_move_probs.end(), 0.0f); |
| 32 | + |
| 33 | + for(auto move_type : move_probs.keys()) { |
| 34 | + cumm_move_probs[move_type] = move_probs[move_type]; |
24 | 35 | } |
25 | 36 |
|
26 | | - total_prob = cumm_move_probs[cumm_move_probs.size() - 1]; |
| 37 | + std::partial_sum(cumm_move_probs.begin(), cumm_move_probs.end(), cumm_move_probs.begin()); |
| 38 | + |
| 39 | + total_prob = cumm_move_probs.back(); |
27 | 40 | } |
28 | 41 |
|
29 | | -e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) { |
| 42 | +e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, |
| 43 | + t_propose_action& proposed_action, |
| 44 | + float rlim, |
| 45 | + const t_placer_opts& placer_opts, |
| 46 | + const PlacerCriticalities* criticalities) { |
30 | 47 | float rand_num = vtr::frand() * total_prob; |
31 | | - for (size_t i = 0; i < cumm_move_probs.size(); i++) { |
32 | | - if (rand_num <= cumm_move_probs[i]) { |
33 | | - proposed_action.move_type = (e_move_type)i; |
34 | | - return avail_moves[i]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities); |
| 48 | + |
| 49 | + for (auto move_type : cumm_move_probs.keys()) { |
| 50 | + if (rand_num <= cumm_move_probs[move_type]) { |
| 51 | + proposed_action.move_type = move_type; |
| 52 | + return all_moves[move_type]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities); |
35 | 53 | } |
36 | 54 | } |
37 | | - VTR_ASSERT_MSG(false, vtr::string_fmt("During static probability move selection, random number (%g) exceeded total expected probabaility (%g)", rand_num, total_prob).c_str()); |
| 55 | + |
| 56 | + VTR_ASSERT_MSG(false, vtr::string_fmt("During static probability move selection, random number (%g) exceeded total expected probability (%g)", rand_num, total_prob).c_str()); |
38 | 57 |
|
39 | 58 | //Unreachable |
40 | | - proposed_action.move_type = (e_move_type)(avail_moves.size() - 1); |
41 | | - return avail_moves[avail_moves.size() - 1]->propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities); |
| 59 | + proposed_action.move_type = e_move_type::INVALID_MOVE; |
| 60 | + return e_create_move::ABORT; |
42 | 61 | } |
0 commit comments