示例#1
0
bool Line::
Collides( const Line &other, const Placement &thisPlacement,
              const Placement &otherPlacement ) const {
   Matrix2D thisTransform = thisPlacement.Get2DMatrix();
   Matrix2D otherTransform = otherPlacement.Get2DMatrix();
   
   Vec2D thisStart = thisTransform.Transform( start - thisPlacement.GetRotationPivot() );
   Vec2D thisEnd = thisTransform.Transform( end - thisPlacement.GetRotationPivot() );
   
   Vec2D otherStart = otherTransform.Transform( other.start - otherPlacement.GetRotationPivot() );
   Vec2D otherEnd = otherTransform.Transform( other.end - otherPlacement.GetRotationPivot() );
   
   return Collides( thisStart, thisEnd, other.origin, otherStart, otherEnd );
}
示例#2
0
 virtual void TransformBy( const Placement &placement ) {
    pos += placement.GetPosition();
    angle += placement.GetRotation();
    xRad *= placement.GetStretch();
    yRad *= placement.GetStretch();
 }
示例#3
0
void ol::Point::
TransformBy( const Placement &placement ) {
   pos += placement.GetPosition();
}
示例#4
0
int main(int argc, char *argv[])
{
    
	
	gArg.Init( argc, argv );
    if( !handleArgument( argc, argv, param ) )
        return -1;



    Placement placement;
    placement.readBookshelfFormat(param.auxFilename , param.plFilename);

    cout << "Benchmark: " << placement.name() << endl;

    cout << format("HPWL: %.f", placement.computeHpwl()) << endl;
    cout << format("Memory usage: %.1f MB", getCurrentMemoryUsage()) << endl;
    cout << format("Core region: (%.f,%.f)-(%.f,%.f)",
                   placement.boundryLeft(),
                   placement.boundryBottom(),
                   placement.boundryRight(),
                   placement.boundryTop()) << endl;
    double orig_wirelength;
    double gp_wirelength, lg_wirelength, dp_wirelength;
    bool bLegal=false;
    orig_wirelength=gp_wirelength=lg_wirelength=dp_wirelength=0;

    ////////////////////////////////////////////////////////////////
    // Global Placement
    ////////////////////////////////////////////////////////////////

    time_t total_time=0;
    time_t global_time_start = time(NULL);
    time_t total_global_time = 0;
    if(param.bRunGlobal)
    {

        cout<<endl<<"////// Global Placement ///////"<<endl;

		
        ////////////start to edit your code /////////////
		
		GlobalPlacer globalPlacer(placement);
		globalPlacer.place();

		/////////////////////////////////////////////////
		
		
        placement.outputBookshelfFormat(placement.name()+".gp.pl");

        gp_wirelength = placement.computeHpwl();
        printf( "\nHPWL: %.0f\n",gp_wirelength);
        total_global_time = time(NULL) - global_time_start;
        total_time+=total_global_time;
    }


    ////////////////////////////////////////////////////////////////
    // Legalization
    ////////////////////////////////////////////////////////////////


    time_t legal_time_start = time(NULL);
    time_t total_legal_time = 0;
    if(param.bRunLegal){

        cout<<endl<<"////// Legalization ///////"<<endl;
        orig_wirelength = placement.computeHpwl();

        CTetrisLegal legal(placement);

        bLegal = legal.Solve( 0.8 );
        if(bLegal)
            cout<<"legalization success!"<<endl;
        else
            cout<<"legalization fail!"<<endl;


        placement.outputBookshelfFormat(placement.name()+".lg.pl");

        lg_wirelength = placement.computeHpwl();
        printf( "\nHPWL: %.0f (%3.2f%%)\n",
                lg_wirelength, ((lg_wirelength - orig_wirelength)/orig_wirelength)*100.0);
        total_legal_time = time(NULL) - legal_time_start;
        total_time+=total_legal_time;
    }

    ////////////////////////////////////////////////////////////////
    // Detail Placement
    ////////////////////////////////////////////////////////////////

    time_t detail_time_start = time(NULL);
    time_t total_detail_time = 0;
    if(param.bRunDetail && bLegal){

        cout<<endl<<"////// Detail Placement ///////"<<endl;
        orig_wirelength = placement.computeHpwl();

        CDetailPlacer dplacer( placement);
        dplacer.DetailPlace();


        placement.outputBookshelfFormat(placement.name()+".dp.pl");

        dp_wirelength = placement.computeHpwl();
        printf( "\nHPWL: %.0f (%3.2f%%)\n",
                dp_wirelength, ((dp_wirelength - orig_wirelength)/orig_wirelength)*100.0);
        total_detail_time = time(NULL) - detail_time_start;
        total_time+=total_detail_time;
    }

    cout<<endl<<endl<<"////////////////////"<<endl;
    if(placement.plname()!="")
        cout << "Benchmark: " << placement.plname() << endl;
    else
        cout << "Benchmark: " << placement.name() << endl;
    if(param.bRunGlobal)
        printf( "\nGlobal HPWL: %.0f   Time: %6.1f sec (%.1f min)\n",gp_wirelength, (double)total_global_time, (double)total_global_time/ 60.0);
    if(param.bRunLegal)
        printf( " Legal HPWL: %.0f   Time: %6.1f sec (%.1f min)\n",lg_wirelength, (double)total_legal_time, (double)total_legal_time/ 60.0);
    if(param.bRunDetail && bLegal)
        printf( "Detail HPWL: %.0f   Time: %6.1f sec (%.1f min)\n",dp_wirelength, (double)total_detail_time, (double)total_detail_time/ 60.0);
    printf( " ===================================================================\n" );
    printf( "       HPWL: %.0f   Time: %6.1f sec (%.1f min)\n", placement.computeHpwl(), (double)total_time, (double)total_time / 60.0 );

    return 0;
}
示例#5
0
文件: Placer.hpp 项目: torc-isi/torc
		void generatePlacement(Placement& placement) {
			//double initialtemperature = 10000;
			placement.updateCostFull(false);
			int currentCost = placement.getCost();
			int newCost = 9999999;
			int goodMoves = 0;
			int movesUndone = 0;
			int acceptedBad = 0;
			int zeroCostMoves = 0;
			int illegalMoves = 0;
			int bestCost = 999999;
			bool done = false;
			double temperature = mHeuristic.getInitialTemperature();
			double acceptrate = 0;
			int doneCount = 0;
			
			boost::timer epochTimer;
			boost::timer totalTimer;
			
			mMovesPerTemperature = mHeuristic.getMovesPerTemperature(); //50000
			//mMovesPerTemperature = 10 * sqrt(pow(placement.getNumInstances(), 3));
			//mMovesPerTemperature = 100000;
			std::cout << "Moves per temperature: " << mMovesPerTemperature << std::endl;
			//placement.updateCostFull(false);
			while (!done) {
				epochTimer.restart();
				//placement.updateCostFull(false);
				goodMoves = 0;
				movesUndone = 0;
				acceptedBad = 0;
				zeroCostMoves = 0;
				illegalMoves = 0;
				std::cout << "currentCost for epoch: " << currentCost;
				
				for (uint32 movei = 0; movei < mMovesPerTemperature; movei++) {
					if (!placement.randomMove(false)) {
						//std::cout << "FAILED MOVED" << std::endl;
						illegalMoves++;
						continue;
					}
					newCost = placement.getCost();
					if (newCost < bestCost) {
						bestCost = newCost;
						//fp.savePlacement();
					}
					if (currentCost < newCost) {
						//if (mRandom.nextDouble() >= 
						//	Math.exp(((double)currentCost - (double)newCost / temperature))
						double irand = (double)rand() / (double)(std::numeric_limits<int>::max());
						if (irand >= exp(((double)currentCost - (double)newCost) / temperature)) {
							movesUndone++;
							placement.undoMove(false);
							//std::cout << " UNDO" << std::endl;
						} else {
							acceptedBad++;
							currentCost = newCost;
							//std::cout << " ACCEPT BAD" << std::endl;
						}
					} else if (currentCost == newCost) {
						zeroCostMoves++;
					} else {
						goodMoves++;
						currentCost = newCost;
					}
				}
				
				double epochTime = epochTimer.elapsed();
				//currentCost = newCost;
				acceptrate = (double)acceptedBad / ((double)acceptedBad + (double)movesUndone);
				
				// temperature adjustment
				double tempadjust = 0;
				if (acceptrate > 0.96) {
					temperature = 0.5 * temperature;
					tempadjust = (double)0.5;
				} else if (acceptrate <= 0.96 && acceptrate > 0.8) {
					temperature = 0.9 * temperature;
					tempadjust = (double)0.9;
				} else if (acceptrate <= 0.8 && acceptrate > 0.15) {
					temperature = 0.95 * temperature;
					tempadjust = (double)0.95;
				} else {
					temperature = 0.8 * temperature;
					tempadjust = (double)0.8;
				}
				
				// termination condition
				//if (acceptedBad == 0)
				if (goodMoves == 0) {
					doneCount++;
				} else {
					doneCount = 0;
				}
				if (doneCount == 10) {
					done = true;
				}
				
				//%.3f%n
				std::cout << " Good moves: " << goodMoves;
				std::cout << " Accepted bad: " << acceptedBad;
				std::cout << " Undone: " << movesUndone;
				std::cout << " ZeroCostMoves: " << zeroCostMoves;
				std::cout << " Best Cost: " << bestCost;
				std::cout << " Attemped Illegal Moves: " << illegalMoves;
				std::cout << " Acceptance rate: " << acceptrate;
				std::cout << " new temp: " << temperature;
				std::cout << " tempadjust: " << tempadjust;
				//std::cout << " time: " << epochTimer.elapsed();
				std::cout << " time: " << epochTime;
				//std::cout << " | ";
				std::cout << std::endl;
				//fp.getCost(temperature, initialtemperature, true);
			}
			std::cout << "Total time: " << totalTimer.elapsed();
			std::cout << std::endl;
			//fp.displayPlacementWithCost();
			//std::cout << "Here's where we ended:";
			//fp.displayPlacement();
			//((AmorphousFloorPlan)fp).getCostAllPairsDistance(true);
			//fp.restorePlacement();
			//fp.validatePlacement();
			//fp.displayPlacement();
			placement.updateCostFull(false);
			std::cout << "Actual end cost: " << placement.getCost() << std::endl;
		}
示例#6
0
bool Dow::Handle::SetPlacement (Placement const & placement) const
{
	Assert (!IsNull ());
	return ::SetWindowPlacement (H (), placement.Get ()) != FALSE;
}
ol::Collision ol::Shape::
LineStripCollision( const std_container1 &vertices, const std_container2 &otherVertices,
                    const Placement &thisPlacement, const Placement &otherPlacement,
                    bool getResults, bool thisConnectFirstAndLast, bool otherConnectFirstAndLast ) const {
   
   if( vertices.size() < 2 || otherVertices.size() < 2 ) {
      OlError( "An empty shape can't ever collide!" );
      return Collision( false );
   }
   
   Vec2D thisCo = thisPlacement.GetPosition();
   Vec2D otherCo = otherPlacement.GetPosition();
   
   Matrix2D thisTransform = thisPlacement.Get2DMatrix();
   Matrix2D otherTransform = otherPlacement.Get2DMatrix();
   
   typename std_container1::const_iterator thisIter = vertices.begin();
   
   const Vec2D rotationPivot = thisPlacement.GetRotationPivot();
   const Vec2D otherRotationPivot = otherPlacement.GetRotationPivot();
   
   Vec2D thisPrev = thisTransform.Transform( *thisIter - rotationPivot ) + thisCo + rotationPivot;
   
   thisIter++;
   
   std::vector< LinePair * > segmentLists;
   
   // Loop through each vertex //
   while( true ) {
      bool breakNow = false;
      
      // Test if we've reached the last line segment //
      if( thisIter == vertices.end() ) {
         if( !thisConnectFirstAndLast ) {
            break;
         }
         
         breakNow = true;
         thisIter = vertices.begin();
      }
      
      Vec2D thisVertex = thisTransform.Transform( *thisIter - rotationPivot ) + thisCo + rotationPivot;
      thisIter++;

      typename std_container2::const_iterator otherIter = otherVertices.begin();
      Vec2D otherPrev = otherTransform.Transform( *otherIter - otherRotationPivot ) + otherCo + otherRotationPivot;
      otherIter++;
      
      // Loop through each vertex of the other polygon //
      while( true ) {
         bool breakNow = false;
         
         // Test if we've reached the last line segment of the other polygon //
         if( otherIter == otherVertices.end() ) {
            if( !otherConnectFirstAndLast ) {
               break;
            }
            
            breakNow = true;
            otherIter = otherVertices.begin();
         }

         Vec2D otherVertex = otherTransform.Transform( *otherIter - otherRotationPivot )
                             + otherCo + otherRotationPivot;
         otherIter++;
         
         // Test for collision //
         if( IsCounterClockwise( thisPrev, thisVertex, otherPrev )
             != IsCounterClockwise( thisPrev, thisVertex, otherVertex )
             &&
             IsCounterClockwise( otherPrev, otherVertex, thisPrev )
             != IsCounterClockwise( otherPrev, otherVertex, thisVertex )) {
            
            if( !getResults ) {
               return Collision( true );
            }
            else {
               Line thisLine( thisVertex, thisPrev );
               Line otherLine( otherVertex, otherPrev );
               
               segmentLists.push_back( new LinePair( thisLine, otherLine ));
               
               /*
               return Collision( thisLine, otherLine );*/
            }
         }

         // Is last line segment of the other polygon processed? //
         if( breakNow ) {
            break;
         }

         // Advance to the next vertex of the other polygon //
         otherPrev = otherVertex;
      }

      // Is last line segment processed? //
      if( breakNow ) {
         break;
      }

      // Advance to the next vertex //
      thisPrev = thisVertex;
   }
   
   if( !segmentLists.empty() ) {
      return Collision( segmentLists );
   }
   
   return Collision( false );
}