def tile_search_exhaustive(Jobs, X, Y, xspacing, yspacing, searchTimeout): """Wrapper around ExhaustiveSearch to handle keyboard interrupt, etc.""" search = tilesearch.ExhaustiveSearch(Jobs, X, Y, xspacing, yspacing, searchTimeout) possiblePermutations = (2 ** len(Jobs)) * factorial(len(Jobs)) print('=' * 70) print("Starting placement using exhaustive search.") print("There are {:d} possible permutations...".format(possiblePermutations)) if possiblePermutations < 1e4: print("this'll take no time at all.") elif possiblePermutations < 1e5: print("surf the web for a few minutes.") elif possiblePermutations < 1e6: print("take a long lunch.") elif possiblePermutations < 1e7: print("come back tomorrow.") else: print("don't hold your breath.") print("Press Ctrl-C to stop and use the best placement so far.") print("Estimated maximum possible utilization is {:.1f}%.".format(tiling.maxUtilization(Jobs, xspacing, yspacing) * 100)) try: search.run() except KeyboardInterrupt: print(search) print() print("Interrupted.") #TODO: Remove this obsolete code #computeTime = time.time() - x.startTime #print("Computed {:d} permutations in {:d} seconds / {:.1f} permutations/second".format(x.permutations, computeTime, x.permutations / computeTime)) print('=' * 70) return search.bestTiling
def tile_search2(Jobs, X, Y): """Wrapper around _tile_search2 to handle keyboard interrupt, etc.""" global _StartTime, _CkpointTime, _Placements, _TBestTiling, _TBestScore _StartTime = time.time() _CkpointTime = _StartTime + 3 _Placements = 0L _TBestTiling = None _TBestScore = float(sys.maxint) print '='*70 print "Starting random placement trials. You must press Ctrl-C to" print "stop the process and use the best placement so far." print "Estimated maximum possible utilization is %.1f%%." % (tiling.maxUtilization(Jobs)*100) try: _tile_search2(Jobs, X, Y) printTilingStats() print except KeyboardInterrupt: printTilingStats() print print "Interrupted." computeTime = time.time() - _StartTime print "Computed %ld placements in %d seconds / %.1f placements/second" % (_Placements, computeTime, _Placements/computeTime) print '='*70 return _TBestTiling
def tile_search2(Jobs, X, Y): """Wrapper around _tile_search2 to handle keyboard interrupt, etc.""" global _StartTime, _CkpointTime, _Placements, _TBestTiling, _TBestScore _StartTime = time.time() _CkpointTime = _StartTime + 3 _Placements = 0L _TBestTiling = None _TBestScore = float(sys.maxint) print '='*70 if (config.Config['searchtimeout'] > 0): print "Starting random placement trials. You can press Ctrl-C to" print "stop the process and use the best placement so far, or wait" print "for the automatic timeout in %i seconds." % config.Config['searchtimeout'] else: print "Starting random placement trials. You must press Ctrl-C to" print "stop the process and use the best placement so far." print "You can specify a timeout by setting 'SearchTimeout' in Layout.cfg" print "Estimated maximum possible utilization is %.1f%%." % (tiling.maxUtilization(Jobs)*100) try: _tile_search2(Jobs, X, Y) printTilingStats() print except KeyboardInterrupt: printTilingStats() print print "Interrupted." computeTime = time.time() - _StartTime print "Computed %ld placements in %d seconds / %.1f placements/second" % (_Placements, computeTime, _Placements/computeTime) print '='*70 return _TBestTiling
def tile_search2(Jobs, X, Y): """Wrapper around _tile_search2 to handle keyboard interrupt, etc.""" global _StartTime, _CkpointTime, _Placements, _TBestTiling, _TBestScore _StartTime = time.time() _CkpointTime = _StartTime + 3 _Placements = 0L _TBestTiling = None _TBestScore = float(sys.maxint) print '=' * 70 print "Starting random placement trials. You must press Ctrl-C to" print "stop the process and use the best placement so far." print "Estimated maximum possible utilization is %.1f%%." % ( tiling.maxUtilization(Jobs) * 100) try: _tile_search2(Jobs, X, Y) printTilingStats() print except KeyboardInterrupt: printTilingStats() print print "Interrupted." computeTime = time.time() - _StartTime print "Computed %ld placements in %d seconds / %.1f placements/second" % ( _Placements, computeTime, _Placements / computeTime) print '=' * 70 return _TBestTiling
def tile_search_random(Jobs, X, Y, xspacing, yspacing, searchTimeout, exhaustiveSearchJobs): """Wrapper around RandomSearch to handle keyboard interrupt, etc.""" print("=" * 70) print("Starting random placement trials. You must press Ctrl-C to") print("stop the process and use the best placement so far.") print("Estimated maximum possible utilization is {:.1f}.".format(tiling.maxUtilization(Jobs, xspacing, yspacing) * 100)) bestScore = float("inf") bestTiling = None placementsTried = 0 startTime = time.time() q = multiprocessing.Queue() p = [] for i in range(multiprocessing.cpu_count()): p.append(multiprocessing.Process(target=_tile_search_random, args=(q, Jobs, X, Y, xspacing, yspacing, searchTimeout, exhaustiveSearchJobs))) try: for i in p: i.start() while 1: time.sleep(3) foundBetter = False try: newResult = q.get(block=False) while newResult is not None: placementsTried += newResult[0] if newResult[1] and newResult[1].area() < bestScore: bestTiling = newResult[1] foundBetter = True bestScore = newResult[1].area() newResult = q.get(block=False) except queue.Empty: if foundBetter: if bestTiling: utilization = bestTiling.usedArea() / bestTiling.area() * 100.0 else: utilization = 0.0 print("\nTested {:d} placements over {:d} seconds. Best tiling at {:.2f}% usage.".format(placementsTried, time.time() - startTime, utilization)) else: print(".", end='') sys.stdout.flush() except KeyboardInterrupt: for i in p: i.terminate() print("\nSearch ended by user.") computeTime = time.time() - startTime print("Computed {:d} placements in {:d} seconds ({:.1f} placements/second).".format(placementsTried, computeTime, placementsTried / computeTime)) print("=" * 70) return bestTiling
def tile_search1(Jobs, X, Y): """Wrapper around _tile_search1 to handle keyboard interrupt, etc.""" global _StartTime, _CkpointTime, _Placements, _TBestTiling, _TBestScore, _Permutations, _PossiblePermutations initialize() _StartTime = time.time() _CkpointTime = _StartTime + 3 # There are (2**N)*(N!) possible permutations where N is the number of jobs. # This is assuming all jobs are unique and each job has a rotation (i.e., is not # square). Practically, these assumptions make no difference because the software # currently doesn't optimize for cases of repeated jobs. _PossiblePermutations = (2L**len(Jobs)) * factorial(len(Jobs)) #print "Possible permutations:", _PossiblePermutations print '=' * 70 print "Starting placement using exhaustive search." print "There are %ld possible permutations..." % _PossiblePermutations, if _PossiblePermutations < 1e4: print "this'll take no time at all." elif _PossiblePermutations < 1e5: print "surf the web for a few minutes." elif _PossiblePermutations < 1e6: print "take a long lunch." elif _PossiblePermutations < 1e7: print "come back tomorrow." else: print "don't hold your breath." print "Press Ctrl-C to stop and use the best placement so far." print "Estimated maximum possible utilization is %.1f%%." % ( tiling.maxUtilization(Jobs) * 100) try: _tile_search1(Jobs, tiling.Tiling(X, Y), 1) printTilingStats() print except KeyboardInterrupt: printTilingStats() print print "Interrupted." computeTime = time.time() - _StartTime print "Computed %ld placements in %d seconds / %.1f placements/second" % ( _Placements, computeTime, _Placements / computeTime) print '=' * 70 return _TBestTiling
def tile_search1(Jobs, X, Y): """Wrapper around _tile_search1 to handle keyboard interrupt, etc.""" global _StartTime, _CkpointTime, _Placements, _TBestTiling, _TBestScore, _Permutations, _PossiblePermutations initialize() _StartTime = time.time() _CkpointTime = _StartTime + 3 # There are (2**N)*(N!) possible permutations where N is the number of jobs. # This is assuming all jobs are unique and each job has a rotation (i.e., is not # square). Practically, these assumptions make no difference because the software # currently doesn't optimize for cases of repeated jobs. _PossiblePermutations = (2L**len(Jobs))*factorial(len(Jobs)) #print "Possible permutations:", _PossiblePermutations print '='*70 print "Starting placement using exhaustive search." print "There are %ld possible permutations..." % _PossiblePermutations, if _PossiblePermutations < 1e4: print "this'll take no time at all." elif _PossiblePermutations < 1e5: print "surf the web for a few minutes." elif _PossiblePermutations < 1e6: print "take a long lunch." elif _PossiblePermutations < 1e7: print "come back tomorrow." else: print "don't hold your breath." print "Press Ctrl-C to stop and use the best placement so far." print "Estimated maximum possible utilization is %.1f%%." % (tiling.maxUtilization(Jobs)*100) try: _tile_search1(Jobs, tiling.Tiling(X,Y), 1) printTilingStats() print except KeyboardInterrupt: printTilingStats() print print "Interrupted." computeTime = time.time() - _StartTime print "Computed %ld placements in %d seconds / %.1f placements/second" % (_Placements, computeTime, _Placements/computeTime) print '='*70 return _TBestTiling