@@ -819,13 +819,22 @@ void B2BSolver::store_solution_into_placement(Eigen::VectorXd& x_soln,
819
819
for (size_t row_id_idx = 0 ; row_id_idx < num_moveable_blocks_; row_id_idx++) {
820
820
// Since we are capping the number of iterations, the solver may not
821
821
// have enough time to converge on a solution that is on the device.
822
- // We just clamp the solution to zero for now.
822
+ // Set the solution to be within the device grid. To prevent round-off
823
+ // errors causing the position to move outside of the device, we add a
824
+ // small buffer (epsilon) to the position.
825
+ // TODO: Create a helper method to clamp a position to just within the
826
+ // device grid.
823
827
// TODO: Should handle this better. If the solution is very negative
824
828
// it may indicate a bug.
825
- if (x_soln[row_id_idx] < 0.0 )
826
- x_soln[row_id_idx] = 0.0 ;
827
- if (y_soln[row_id_idx] < 0.0 )
828
- y_soln[row_id_idx] = 0.0 ;
829
+ double epsilon = 0.0001 ;
830
+ if (x_soln[row_id_idx] < epsilon)
831
+ x_soln[row_id_idx] = epsilon;
832
+ if (x_soln[row_id_idx] >= device_grid_width_)
833
+ x_soln[row_id_idx] = device_grid_width_ - epsilon;
834
+ if (y_soln[row_id_idx] < epsilon)
835
+ y_soln[row_id_idx] = epsilon;
836
+ if (y_soln[row_id_idx] >= device_grid_height_)
837
+ y_soln[row_id_idx] = device_grid_height_ - epsilon;
829
838
830
839
APRowId row_id = APRowId (row_id_idx);
831
840
APBlockId blk_id = row_id_to_blk_id_[row_id];
0 commit comments