FastDMSamplingBase::value_t FastDMSamplingInvNorm::rand(rngeng_t& rngeng) { std::uniform_real_distribution<double> unif_dist; while (true) { const value_t t = randin(rngeng, invabsmu_, invmu2_); const value_t one2t = 0.5 / t; if (t < 2.5) { // short-time series if (acceptt(t, exp(-one2t) * unif_dist(rngeng), one2t)) return t; } else { // long-time series constexpr value_t Cl = -0.6773740579341821; // -log(pi/4)-log(2pi)/2; if (acceptt(t, exp(Cl - one2t - 3 / 2 * log(t)) * unif_dist(rngeng), PI * PI * t / 8)) return t; } } }
FastDMSamplingBase::value_t FastDMSamplingNormExp::rand(rngeng_t& rngeng) { std::uniform_real_distribution<double> unif_dist; while (true) { const value_t P = F1inf_ * unif_dist(rngeng); if (P <= CF1st_) { // short-time series const value_t erfcinvP = erfcinv(P / Cf1s_); const value_t t = 1 / (2 * a_ * erfcinvP * erfcinvP); if (acceptt(t, exp(- 0.5/(a_ * t) - sqrtamu_ + mu2_ * t / 2) * unif_dist(rngeng), 0.5 / t)) return t; } else { // long-time series const value_t t = -log1p(- (P - CF1st_) / Cf1l_ - F1lt_) / fourmu2pi_; const value_t pi2t8 = PI * PI * t / 8; if (acceptt(t, exp(-pi2t8) * unif_dist(rngeng), pi2t8)) return t; } } }
BOOL usite2( /* old_apos, new_apos, old_bpos, new_bpos */ ) /* MOVEBOXPTR *old_apos, *new_apos, *old_bpos, *new_bpos ; */ { PINBOXPTR anewtermptr , bnewtermptr ; MOVEBOXPTR pos ; /* temp pointer for easier access */ BINBOXPTR modptr ; INT cost , newpenalty, newbinpenal, newtimepenalty, newtimepenal ; INT oldBinX, oldBinY, limit, *oldCellList ; INT modBinX, modBinY, *modCellList ; INT i ; INT wire_chg ; DOUBLE delta_wire ; /* ----------------------------------------------------------------- global information is stored in element zero of position arrays new position records have been initialized in uloop(). */ acellS = new_apos0G->cell ; acellptrS = cellarrayG[acellS] ; anewtermptr = acellptrS->pinptr ; bcellS = new_bpos0G->cell ; bcellptrS = cellarrayG[bcellS] ; bnewtermptr = bcellptrS->pinptr ; clear_net_set() ; /* reset set to mark nets that have changed position */ /* remove overlap so that pairwise exchange has better chance at low T*/ mod_cellS = 0 ; /* mod_cell_positions() ; */ /* save state of penalty */ newbinpenal = binpenalG ; /* adjust overlap penalty */ newbinpenal += overlap2( /* old_apos, new_apos, old_bpos, new_bpos */ ) ; /* scale newpenalty for feedback circuit */ newpenalty = (INT) ( lapFactorG * sqrt( (DOUBLE) newbinpenal ) ) ; upin_test( anewtermptr, new_apos0G ) ; upin_test( bnewtermptr, new_bpos0G ) ; cost = funccostG ; cost += unet2( anewtermptr, bnewtermptr ) ; wire_chg = cost - funccostG ; newtimepenal = timingpenalG ; newtimepenal += calc_incr_time2( acellS, bcellS ) ; ASSERT( newtimepenal == dcalc_full_penalty(),"usite2","Timing woes\n" ) ; /* scale new timing penalty */ newtimepenalty = (INT) ( timeFactorG * (DOUBLE) newtimepenal ) ; if( acceptt( penaltyG - newpenalty - wire_chg + timingcostG - newtimepenalty )){ upin_accept( anewtermptr ) ; upin_accept( bnewtermptr ) ; update_overlap2( /* old_aposG, old_bposG */ ) ; update_time2( acellS, bcellS ) ; /* update new position and orientation of a cell */ acellptrS->xcenter = new_apos0G->xcenter ; acellptrS->ycenter = new_apos0G->ycenter ; acellptrS->orient = new_apos0G->orient ; bcellptrS->xcenter = new_bpos0G->xcenter ; bcellptrS->ycenter = new_bpos0G->ycenter ; bcellptrS->orient = new_bpos0G->orient ; /* ************ BEGIN UPDATE OF BIN CELL LIST ************** */ if( !(mod_cellS) ){ /* a and b are swapped - assert old_apos0 has b new position */ /* and newcellList has new a position calculated in uloop.c */ oldBinX = SETBINX(old_apos0G->xcenter) ; oldBinY = SETBINY(old_apos0G->ycenter) ; oldCellList = binptrG[oldBinX][oldBinY]->cells ; /* do nothing if cell a remains in same bin */ if( oldCellList != newCellListG ){ /* swap a for b in oldcellList */ /* find a 's position in array */ limit = oldCellList[0] ; for( i=1;i<=limit;i++ ){ if( oldCellList[i] == acellS ){ oldCellList[i] = bcellS ; break ; } } /* assert i now has correct value of b */ ASSERT( oldCellList[i] == bcellS,"usite2", "Problem in oldbin cell lists\n" ) ; /* swap b for a in newcellList */ /* find a 's position in array */ limit = newCellListG[0] ; for( i=1;i<=limit;i++ ){ if( newCellListG[i] == bcellS ){ newCellListG[i] = acellS ; break ; } } /* assert i now has correct value of a */ ASSERT( newCellListG[i] == acellS,"usite2", "Problem in newbin cell lists\n" ) ; } } else if( mod_cellS == acellS ){ /* a's bin is modified by the moving cells apart */ oldBinX = SETBINX(old_apos0G->xcenter) ; oldBinY = SETBINY(old_apos0G->ycenter) ; oldCellList = binptrG[oldBinX][oldBinY]->cells ; modBinX = SETBINX(new_apos0G->xcenter) ; modBinY = SETBINY(new_apos0G->ycenter) ; modptr = binptrG[modBinX][modBinY] ; modCellList = modptr->cells ; /* add b to oldCellList - find a 's position in array */ limit = oldCellList[0] ; for( i=1;i<=limit;i++ ){ if( oldCellList[i] == acellS ){ oldCellList[i] = bcellS ; break ; } } /* assert i now has correct value of b */ ASSERT( oldCellList[i] == bcellS, "usite2", "Problem in oldbin cell lists\n"); /* delete b in newCellList */ limit = newCellListG[0] ; for( i=1;i<=limit;i++ ){ if( newCellListG[i] == bcellS ){ break ; } } ASSERT( newCellListG[i] == bcellS, "usite2", "Problem in newbin cell lists\n" ) ; if( i != limit ){ newCellListG[i] = newCellListG[ limit ] ; } newCellListG[0]-- ; /* now add a to modified bin */ limit = ++modCellList[0] ; if( limit >= modptr->space ){ modptr->space += EXPCELLPERBIN ; modCellList = (INT *) Ysafe_realloc( modCellList, modptr->space * sizeof(INT) ) ; } modCellList[limit] = acellS ; } else if( mod_cellS == bcellS ){ /* b's bin is modified by the moving cells apart */ oldBinX = SETBINX(old_apos0G->xcenter) ; oldBinY = SETBINY(old_apos0G->ycenter) ; oldCellList = binptrG[oldBinX][oldBinY]->cells ; modBinX = SETBINX(new_bpos0G->xcenter) ; modBinY = SETBINY(new_bpos0G->ycenter) ; modptr = binptrG[modBinX][modBinY] ; modCellList = modptr->cells ; /* add a to newCellList - find b 's position in array */ /* this delete's b's old position */ limit = newCellListG[0] ; for( i=1;i<=limit;i++ ){ if( newCellListG[i] == bcellS ){ newCellListG[i] = acellS ; break ; } } /* assert i now has correct value of a */ ASSERT( newCellListG[i] == acellS, "usite2", "Problem in newbin cell lists\n" ) ; /* delete a in oldCellList */ limit = oldCellList[0] ; for( i=1;i<=limit;i++ ){ if( oldCellList[i] == acellS ){ break ; } } ASSERT( oldCellList[i] == acellS, "usite2", "Problem in oldbin cell lists\n" ) ; if( i != limit ){ oldCellList[i] = oldCellList[ limit ] ; } oldCellList[0]-- ; /* now add b to modified bin */ limit = ++modCellList[0] ; if( limit >= modptr->space ){ modptr->space += EXPCELLPERBIN ; modCellList = (INT *) Ysafe_realloc( modCellList, modptr->space * sizeof(INT) ) ; } modCellList[limit] = bcellS ; } /* ********** END UPDATE OF BIN CELL LIST ************** */ /* check that everything is ok */ ASSERT( checkbinList(), "usite2", "We have a problem at checkbinList()\n") ; funccostG = cost ; penaltyG = newpenalty ; binpenalG = newbinpenal ; timingcostG = newtimepenalty ; timingpenalG = newtimepenal ; return (ACCEPT) ; } else { return (REJECT) ; } }
ucxx2( ) { CBOXPTR acellptr , bcellptr ; TIBOXPTR atileptr , btileptr ; TEBOXPTR atermptr , btermptr ; int error_light_is_on ; int cost ; int aorient , borient ; int a1LoBin, a1HiBin, b1LoBin, b1HiBin ; int a2LoBin, a2HiBin, b2LoBin, b2HiBin ; int startxa1 , endxa1 , startxa2 , endxa2 ; int startxb1 , endxb1 , startxb2 , endxb2 ; int anbin , bnbin , i ; int truth ; double temp ; acellptr = carray[ a ] ; axcenter = acellptr->cxcenter ; aycenter = acellptr->cycenter ; aorient = acellptr->corient ; atileptr = acellptr->tileptr ; aleft = atileptr->left ; aright = atileptr->right ; atermptr = atileptr->termsptr ; bcellptr = carray[ b ] ; bxcenter = bcellptr->cxcenter ; bycenter = bcellptr->cycenter ; borient = bcellptr->corient ; btileptr = bcellptr->tileptr ; bleft = btileptr->left ; bright = btileptr->right ; btermptr = btileptr->termsptr ; newbinpenal = binpenal ; newrowpenal = rowpenal ; newpenal = penalty ; new_old( bright-bleft-aright+aleft ) ; find_new_pos() ; a1LoBin = SetBin( startxa1 = axcenter + aleft ) ; a1HiBin = SetBin( endxa1 = axcenter + aright ) ; b1LoBin = SetBin( startxb1 = bxcenter + bleft ) ; b1HiBin = SetBin( endxb1 = bxcenter + bright ) ; a2LoBin = SetBin( startxa2 = anxcenter + aleft ) ; a2HiBin = SetBin( endxa2 = anxcenter + aright ) ; b2LoBin = SetBin( startxb2 = bnxcenter + bleft ) ; b2HiBin = SetBin( endxb2 = bnxcenter + bright ) ; old_assgnto_new2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ; sub_penal( startxa1 , endxa1 , ablock , a1LoBin , a1HiBin ) ; sub_penal( startxb1 , endxb1 , bblock , b1LoBin , b1HiBin ) ; add_penal( startxa2 , endxa2 , bblock , a2LoBin , a2HiBin ) ; add_penal( startxb2 , endxb2 , ablock , b2LoBin , b2HiBin ) ; binpen_chg = newbinpenal - binpenal ; rowpen_chg = newrowpenal - rowpenal ; newpenal = (int)( roLenCon * (double) newrowpenal + binpenCon * (double) newbinpenal ) ; error_light_is_on = 0 ; if( newpenal - penalty > P_limit ) { if( potential_errors < 100 ) { ++potential_errors ; error_light_is_on = 1 ; } else { earlyRej++ ; return( -1 ) ; } } if( ablock != bblock ) { term_newpos_a( atermptr , anxcenter , bycenter , aorient ) ; term_newpos_b( btermptr , bnxcenter , aycenter , borient ) ; } else { term_newpos( atermptr , anxcenter , bycenter , aorient ) ; term_newpos( btermptr , bnxcenter , aycenter , borient ) ; } cost = funccost ; delta_vert_cost = 0 ; if( ablock != bblock ) { new_dbox_a( atermptr , &cost ) ; new_dbox_a( btermptr , &cost ) ; } else { new_dbox( atermptr , &cost ) ; new_dbox( btermptr , &cost ) ; } wire_chg = cost - funccost ; truth = acceptt(funccost + penalty - cost - newpenal - delta_vert_cost); if( truth == 1 ) { if( error_light_is_on ) { error_count++ ; } new_assgnto_old2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ; if( ablock != bblock ) { dbox_pos_2( atermptr ) ; dbox_pos_2( btermptr ) ; } else { dbox_pos( atermptr ) ; dbox_pos( btermptr ) ; } anbin = SetBin( anxcenter ) ; bnbin = SetBin( bnxcenter ) ; if( cellaptr != cellbptr ) { remv_cell( cellaptr , Apost ) ; remv_cell( cellbptr , Bpost ) ; add_cell( &binptr[bblock][anbin]->cell , a ) ; add_cell( &binptr[ablock][bnbin]->cell , b ) ; } else { remv_cell( cellaptr , Apost ) ; for( i = 1 ; i <= *cellaptr ; i++ ) { if( cellaptr[i] == b ) { break ; } } remv_cell( cellaptr , i ) ; add_cell( &binptr[ablock][anbin]->cell , a ) ; add_cell( &binptr[ablock][bnbin]->cell , b ) ; } if( wire_chg < 0 ) { temp = (double) - wire_chg ; total_wire_chg += temp ; sigma_wire_chg += (temp - mean_wire_chg) * (temp - mean_wire_chg) ; wire_chgs++ ; } acellptr->cblock = bblock ; acellptr->cxcenter = anxcenter ; acellptr->cycenter = bycenter ; bcellptr->cblock = ablock ; bcellptr->cxcenter = bnxcenter ; bcellptr->cycenter = aycenter ; funccost = cost ; binpenal = newbinpenal ; rowpenal = newrowpenal ; penalty = newpenal ; if( ablock != bblock ) { barray[ablock]->oldsize = barray[ablock]->newsize ; barray[bblock]->oldsize = barray[bblock]->newsize ; } return( 1 ) ; } else { return( 0 ) ; } }