Skip to content

Commit b811486

Browse files
committed
mpl: change best_valid_result to best_result to handle case of no valid result
If there is no valid result then we want to use the best invalid result in a similar fashion to when there is a best result. If a valid result is found then then only valid results are considered for being the best. Signed-off-by: Matt Liberty <[email protected]>
1 parent 8f716dc commit b811486

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/mpl/src/SimulatedAnnealingCore.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -717,19 +717,19 @@ void SimulatedAnnealingCore<T>::fastSA()
717717
// as it is too expensive
718718
notch_weight_ = 0.0;
719719

720-
if (isValid()) {
721-
updateBestValidResult(cost);
722-
}
720+
updateBestResult(cost);
723721

724722
while (step <= max_num_step_) {
725723
for (int i = 0; i < num_perturb_per_step_; i++) {
726724
saveState();
727725
perturb();
728726
cost = calNormCost();
729727

730-
const bool keep_result = cost < pre_cost || best_valid_result_.empty();
731-
if (isValid() && keep_result) {
732-
updateBestValidResult(cost);
728+
const bool is_valid = isValid();
729+
const bool improved = cost < pre_cost || best_result_.empty();
730+
if ((!is_best_result_valid_ || is_valid) && improved) {
731+
updateBestResult(cost);
732+
is_best_result_valid_ = is_valid;
733733
}
734734

735735
const float delta_cost = cost - pre_cost;
@@ -767,40 +767,42 @@ void SimulatedAnnealingCore<T>::fastSA()
767767
graphics_->doNotSkip();
768768
}
769769
calPenalty();
770+
cost = calNormCost();
770771

771-
if (!best_valid_result_.empty()
772-
&& (!isValid() || best_valid_result_.cost < calNormCost())) {
773-
useBestValidResult();
772+
const bool is_valid = isValid();
773+
const bool improved = cost < best_result_.cost || best_result_.empty();
774+
if ((is_best_result_valid_ && !is_valid) || !improved) {
775+
useBestResult();
774776
}
775777
}
776778

777779
template <class T>
778-
void SimulatedAnnealingCore<T>::updateBestValidResult(const float cost)
780+
void SimulatedAnnealingCore<T>::updateBestResult(const float cost)
779781
{
780-
best_valid_result_.sequence_pair.pos_sequence = pos_seq_;
781-
best_valid_result_.sequence_pair.neg_sequence = neg_seq_;
782+
best_result_.sequence_pair.pos_sequence = pos_seq_;
783+
best_result_.sequence_pair.neg_sequence = neg_seq_;
782784

783785
if constexpr (std::is_same_v<T, SoftMacro>) {
784786
for (const int macro_id : pos_seq_) {
785787
SoftMacro& macro = macros_[macro_id];
786-
best_valid_result_.macro_id_to_width[macro_id] = macro.getWidth();
788+
best_result_.macro_id_to_width[macro_id] = macro.getWidth();
787789
}
788790
}
789791

790-
best_valid_result_.cost = cost;
792+
best_result_.cost = cost;
791793
}
792794

793795
template <class T>
794-
void SimulatedAnnealingCore<T>::useBestValidResult()
796+
void SimulatedAnnealingCore<T>::useBestResult()
795797
{
796-
pos_seq_ = best_valid_result_.sequence_pair.pos_sequence;
797-
neg_seq_ = best_valid_result_.sequence_pair.neg_sequence;
798+
pos_seq_ = best_result_.sequence_pair.pos_sequence;
799+
neg_seq_ = best_result_.sequence_pair.neg_sequence;
798800

799801
if constexpr (std::is_same_v<T, SoftMacro>) {
800802
for (const int macro_id : pos_seq_) {
801803
SoftMacro& macro = macros_[macro_id];
802804
const float valid_result_width
803-
= best_valid_result_.macro_id_to_width.at(macro_id);
805+
= best_result_.macro_id_to_width.at(macro_id);
804806

805807
if (macro.isMacroCluster()) {
806808
const float valid_result_height = macro.getArea() / valid_result_width;

src/mpl/src/SimulatedAnnealingCore.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class SimulatedAnnealingCore
107107
const BoundaryRegionList& regions);
108108
void initSequencePair();
109109
void setDieArea(const Rect& die_area);
110-
void updateBestValidResult(float cost);
111-
void useBestValidResult();
110+
void updateBestResult(float cost);
111+
void useBestResult();
112112

113113
virtual float calNormCost() const = 0;
114114
virtual void calPenalty() = 0;
@@ -212,7 +212,8 @@ class SimulatedAnnealingCore
212212
MplObserver* graphics_ = nullptr;
213213
odb::dbBlock* block_;
214214

215-
Result best_valid_result_;
215+
Result best_result_;
216+
bool is_best_result_valid_ = false;
216217

217218
std::vector<float> cost_list_; // store the cost in the list
218219
std::vector<float> T_list_; // store the temperature

0 commit comments

Comments
 (0)