@@ -263,62 +263,68 @@ void SimulatedAnnealingCore<T>::calOutlinePenalty()
263263template <class T >
264264void SimulatedAnnealingCore<T>::calWirelength()
265265{
266- // Initialization
267- wirelength_ = 0.0 ;
268266 if (core_weights_.wirelength <= 0.0 ) {
269267 return ;
270268 }
271269
272- // calculate the total net weight
273- float tot_net_weight = 0.0 ;
274- for (const auto & net : nets_) {
275- tot_net_weight += net.weight ;
276- }
270+ wirelength_ = computeNetsWireLength (nets_);
277271
278- if (tot_net_weight <= 0.0 ) {
279- return ;
272+ if (graphics_) {
273+ graphics_->setWirelengthPenalty ({.name = " Wire Length" ,
274+ .weight = core_weights_.wirelength ,
275+ .value = wirelength_,
276+ .normalization_factor = norm_wirelength_});
280277 }
278+ }
279+
280+ template <class T >
281+ float SimulatedAnnealingCore<T>::computeNetsWireLength(
282+ const std::vector<BundledNet>& nets) const
283+ {
284+ float nets_wire_length = 0.0 ;
285+ float nets_weight_sum = 0.0 ;
281286
282287 for (const auto & net : nets_) {
283- T& source = macros_[ net.terminals . first ] ;
284- T& target = macros_[net. terminals . second ];
288+ nets_weight_sum += net.weight ;
289+ }
285290
286- if (target. isClusterOfUnplacedIOPins () ) {
287- computeWLForClusterOfUnplacedIOPins (source, target, net. weight );
288- continue ;
289- }
291+ if (nets_weight_sum != 0.0 ) {
292+ for ( const auto & net : nets) {
293+ const T& source = macros_[net. terminals . first ] ;
294+ const T& target = macros_[net. terminals . second ];
290295
291- const float x1 = source.getPinX ();
292- const float y1 = source.getPinY ();
293- const float x2 = target.getPinX ();
294- const float y2 = target.getPinY ();
295- wirelength_ += net.weight * (std::abs (x2 - x1) + std::abs (y2 - y1));
296- }
296+ if (target.isClusterOfUnplacedIOPins ()) {
297+ nets_wire_length
298+ += computeWLForClusterOfUnplacedIOPins (source, target, net.weight );
299+ } else {
300+ const float x1 = source.getPinX ();
301+ const float y1 = source.getPinY ();
302+ const float x2 = target.getPinX ();
303+ const float y2 = target.getPinY ();
297304
298- // normalization
299- wirelength_ = wirelength_ / tot_net_weight
300- / (outline_.getHeight () + outline_.getWidth ());
305+ nets_wire_length
306+ += net.weight * (std::abs (x2 - x1) + std::abs (y2 - y1));
307+ }
308+ }
301309
302- if (graphics_) {
303- graphics_->setWirelengthPenalty ({" Wire Length" ,
304- core_weights_.wirelength ,
305- wirelength_,
306- norm_wirelength_});
310+ nets_wire_length = nets_wire_length / nets_weight_sum
311+ / (outline_.getHeight () + outline_.getWidth ());
307312 }
313+
314+ return nets_wire_length;
308315}
309316
310317template <class T >
311- void SimulatedAnnealingCore<T>::computeWLForClusterOfUnplacedIOPins(
318+ double SimulatedAnnealingCore<T>::computeWLForClusterOfUnplacedIOPins(
312319 const T& macro,
313320 const T& unplaced_ios,
314- const float net_weight)
321+ const float net_weight) const
315322{
316323 // To generate maximum cost.
317324 const float max_dist = die_area_.getPerimeter () / 2 ;
318325
319326 if (isOutsideTheOutline (macro)) {
320- wirelength_ += net_weight * max_dist;
321- return ;
327+ return net_weight * max_dist;
322328 }
323329
324330 const odb::Point macro_location (block_->micronsToDbu (macro.getPinX ()),
@@ -341,7 +347,7 @@ void SimulatedAnnealingCore<T>::computeWLForClusterOfUnplacedIOPins(
341347 = computeDistToNearestRegion (macro_location, {constraint}, nullptr );
342348 }
343349
344- wirelength_ += net_weight * block_->dbuToMicrons (smallest_distance);
350+ return net_weight * block_->dbuToMicrons (smallest_distance);
345351}
346352
347353// We consider the macro outside the outline based on the location of
0 commit comments