@@ -94,8 +94,11 @@ void SACoreSoftMacro::run()
9494
9595 fastSA ();
9696
97- if (centralization_on_ ) {
97+ if (enhancements_on_ ) {
9898 attemptCentralization (calNormCost ());
99+ if (centralization_was_reverted_) {
100+ attemptMacroClusterAlignment ();
101+ }
99102 }
100103
101104 if (graphics_) {
@@ -554,11 +557,16 @@ void SACoreSoftMacro::calFixedMacrosPenalty()
554557}
555558
556559// Align macro clusters to reduce notch
557- void SACoreSoftMacro::alignMacroClusters ()
560+ void SACoreSoftMacro::attemptMacroClusterAlignment ()
558561{
559- if (width_ > outline_. getWidth () || height_ > outline_. getHeight ()) {
562+ if (! isValid ()) {
560563 return ;
561564 }
565+
566+ float pre_cost = calNormCost ();
567+ // Cache current solution to allow reversal
568+ auto clusters_locations = getClustersLocations ();
569+
562570 // update threshold value
563571 adjust_h_th_ = notch_h_th_;
564572 adjust_v_th_ = notch_v_th_;
@@ -597,6 +605,19 @@ void SACoreSoftMacro::alignMacroClusters()
597605 }
598606 }
599607 }
608+
609+ calPenalty ();
610+
611+ // Revert macro alignemnt
612+ if (calNormCost () > pre_cost) {
613+ setClustersLocations (clusters_locations);
614+
615+ if (graphics_) {
616+ graphics_->saStep (macros_);
617+ }
618+
619+ calPenalty ();
620+ }
600621}
601622
602623float SACoreSoftMacro::calSingleNotchPenalty (float width, float height)
@@ -984,6 +1005,33 @@ void SACoreSoftMacro::addBlockages(const std::vector<Rect>& blockages)
9841005 blockages_.insert (blockages_.end (), blockages.begin (), blockages.end ());
9851006}
9861007
1008+ std::vector<std::pair<float , float >> SACoreSoftMacro::getClustersLocations ()
1009+ const
1010+ {
1011+ std::vector<std::pair<float , float >> clusters_locations (pos_seq_.size ());
1012+ for (int id : pos_seq_) {
1013+ clusters_locations[id] = {macros_[id].getX (), macros_[id].getY ()};
1014+ }
1015+
1016+ return clusters_locations;
1017+ }
1018+
1019+ void SACoreSoftMacro::setClustersLocations (
1020+ const std::vector<std::pair<float , float >>& clusters_locations)
1021+ {
1022+ if (clusters_locations.size () != pos_seq_.size ()) {
1023+ logger_->error (MPL,
1024+ 52 ,
1025+ " setClustersLocation called with a different numbers of "
1026+ " clusters of that in the sequence pair" );
1027+ }
1028+
1029+ for (int & id : pos_seq_) {
1030+ macros_[id].setX (clusters_locations[id].first );
1031+ macros_[id].setY (clusters_locations[id].second );
1032+ }
1033+ }
1034+
9871035void SACoreSoftMacro::attemptCentralization (const float pre_cost)
9881036{
9891037 if (outline_penalty_ > 0 ) {
@@ -993,24 +1041,18 @@ void SACoreSoftMacro::attemptCentralization(const float pre_cost)
9931041 // In order to revert the centralization, we cache the current location
9941042 // of the clusters to avoid floating-point evilness when creating the
9951043 // x,y grid to fill the dead space by expanding mixed clusters.
996- std::map<int , std::pair<float , float >> clusters_locations;
997-
998- for (int & id : pos_seq_) {
999- clusters_locations[id] = {macros_[id].getX (), macros_[id].getY ()};
1000- }
1044+ auto clusters_locations = getClustersLocations ();
10011045
10021046 std::pair<float , float > offset ((outline_.getWidth () - width_) / 2 ,
10031047 (outline_.getHeight () - height_) / 2 );
10041048 moveFloorplan (offset);
1049+ calPenalty ();
10051050
10061051 // revert centralization
10071052 if (calNormCost () > pre_cost) {
10081053 centralization_was_reverted_ = true ;
10091054
1010- for (int & id : pos_seq_) {
1011- macros_[id].setX (clusters_locations[id].first );
1012- macros_[id].setY (clusters_locations[id].second );
1013- }
1055+ setClustersLocations (clusters_locations);
10141056
10151057 if (graphics_) {
10161058 graphics_->saStep (macros_);
@@ -1030,8 +1072,6 @@ void SACoreSoftMacro::moveFloorplan(const std::pair<float, float>& offset)
10301072 if (graphics_) {
10311073 graphics_->saStep (macros_);
10321074 }
1033-
1034- calPenalty ();
10351075}
10361076
10371077Tiling SACoreSoftMacro::computeOverlapShape (const Rect& rect_a,
0 commit comments