Timer unit: 3.1048e-07 s

Total time: 182.464 s
File: bignum_generation.py
Function: evaluate_patterns at line 53

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    53                                           @profile
    54                                           def evaluate_patterns(width, height, many_patterns = None):
    55         4          162     40.5      0.0      if not many_patterns:
    56         2           48     24.0      0.0          many_patterns = []
    57         4         2890    722.5      0.0      searcher= Searcher(width, height)
    58         4          119     29.8      0.0      config.maxy=height+4
    59         4           88     22.0      0.0      config.maxx=width+4
    60                                               
    61         4           91     22.8      0.0      uniq_good_bignums = set()
    62         4           85     21.2      0.0      uniq_bad_bignums = set()
    63         4           83     20.8      0.0      repeat_good_bignums = set()
    64         4           83     20.8      0.0      repeat_bad_bignums = set()
    65         4           96     24.0      0.0      st = time.clock()
    66         4           93     23.2      0.0      do_notch_searching = searcher.width * searcher.height != 6  #let those guys discover them.
    67                                               #actually those guys will discover tem anyway since they're on the edge.
    68         4           77     19.2      0.0      do_extra_checking = True
    69      4740        82353     17.4      0.0      for bignum in range(0, searcher.maxnum):  #this represents the open spaces...?
    70      4736       108728     23.0      0.0          poss=set()
    71     59264       984225     16.6      0.2          for n in range(width * height):
    72     54528       999589     18.3      0.2              if (bignum>>n)%2 == 0:
    73     27264       488218     17.9      0.1                  sq = searcher.num2sq[n]
    74     27264       681483     25.0      0.1                  poss.add(addpos(sq, offset))
    75      4736        75274     15.9      0.0          need_to_check = True
    76                                                   #checking for special skips.
    77      4736        79009     16.7      0.0          if not poss:
    78         4           78     19.5      0.0              res = True
    79         4           77     19.2      0.0              need_to_check = False
    80      4736        81086     17.1      0.0          res_is_unique_to_this_size = True  #we would store a bad pattern here.
    81                                                   #basically, we always store it, unless it was found due to a smaller bad pattern.
    82                                                   #if that is the case, we should have just used that pattern to find it and don't need to store it again here.
    83      4736        77415     16.3      0.0          if do_extra_checking:
    84     24054       406282     16.9      0.1              for pos in poss:
    85     21525       545562     25.3      0.1                  if not searcher.edgy(pos):  #cneter
    86      3971       185638     46.7      0.0                      neis = [oo for oo in orth(pos) if oo in poss]
    87      3971        69876     17.6      0.0                      if len(neis) == 0:  #single bubble
    88       235         3855     16.4      0.0                          need_to_check = False
    89       235         3816     16.2      0.0                          res = False
    90       235         3760     16.0      0.0                          res_is_unique_to_this_size = False
    91       235         3944     16.8      0.0                          break
    92      3736        65393     17.5      0.0                      if len(neis) == 1:  #internal alley
    93       963        15371     16.0      0.0                          need_to_check = False
    94       963        15263     15.8      0.0                          res = False
    95       963        17399     18.1      0.0                          res_is_unique_to_this_size = False
    96       963        16168     16.8      0.0                          break
    97     17554       280431     16.0      0.0                  elif do_notch_searching:
    98                                                               #   X.X
    99                                                               #   XXX
   100     17170       446120     26.0      0.1                      if not searcher.cornery(pos):  #single guy side of the street
   101     10437       508170     48.7      0.1                          neis = [oo for oo in orth(pos) if oo in poss]
   102     10437       191180     18.3      0.0                          if len(neis) == 0:
   103      1009        15547     15.4      0.0                              need_to_check = False
   104      1009        15081     14.9      0.0                              res = False
   105      1009        15085     15.0      0.0                              res_is_unique_to_this_size = False
   106      1009        17824     17.7      0.0                              break
   107      4736        80091     16.9      0.0          if need_to_check:
   108      2525        93548     37.0      0.0              config.levelnum='roomtest%dx%d'%(width,height)
   109      2525        52539     20.8      0.0              config.worktype='roomtest'
   110      2525    190909793  75607.8     32.5              board=Board(config, rows=[r[:] for r in searcher.rowcopy])
   111      2525       117370     46.5      0.0              board.levelnum='roomtest%dx%d'%(width,height)
   112      2525        47649     18.9      0.0              board.static = True
   113      2525        45421     18.0      0.0              board.dynamic_endset = None 
   114      2525      2916812   1155.2      0.5              board.curopen=board.count_open()
   115      2525        54671     21.7      0.0              config.shrink_images = False
   116     31061       568387     18.3      0.1              for pos in searcher.room_cover_area:
   117     28536       842409     29.5      0.1                  board.set(pos) #set them all full.
   118      2525        74941     29.7      0.0              gates=set()
   119     18503       328479     17.8      0.1              for pos in poss:
   120     15978       478827     30.0      0.1                  board.unset(pos)
   121     79890      1685880     21.1      0.3                  for oo in orth(pos):
   122     63912      1153519     18.0      0.2                      if oo in poss:continue
   123     36888       959286     26.0      0.2                      if not board.isopen(oo):continue
   124     18994       386521     20.3      0.1                      gates.add((oo, 2))
   125                                                       
   126      2525     22083278   8745.9      3.8              rm=Room(board=board, poss=poss.copy(), gates=gates, kind='roomtest')
   127                                                       
   128      2525       626624    248.2      0.1              rm.add_must('c')
   129      2525       159479     63.2      0.0              rm.set_timelimit(source='pregen')
   130      2525        57273     22.7      0.0              rm.timelimit = time.time() + 1000  #doesn't even matter
   131      2525      1047809    415.0      0.2              rm.setup_key()
   132      2525        66527     26.3      0.0              rm.start_progress = 1
   133      2525        45458     18.0      0.0              rm.start_cutoff = 0
   134                                                       
   135                                                       #now searching for previous patterns.
   136                                                       #clamp these in case the room shrinks.
   137      2525        49584     19.6      0.0              left = 2 - (rm.xoffset - 1)  #need these because rooms will autoshrink
   138      2525        46095     18.3      0.0              top = 2 - (rm.yoffset - 1)  #and we have to be really careful not to overlap into the gatesqs area.
   139                                                       
   140                                                       #a test.
   141                                                       
   142      2525        73732     29.2      0.0              right = min(rm.width - 1, left + searcher.width - 1)
   143      2525        56865     22.5      0.0              bottom = min(rm.height - 1, top + searcher.height - 1)
   144                                                       
   145                                                       if 0:
   146                                                           for xx in range(left, right + 1):
   147                                                               for yy in range(top, bottom + 1):
   148                                                                   if (xx, yy) in rm.gatesqs:
   149                                                                       import ipdb;ipdb.set_trace()
   150                                                       
   151      2525        49314     19.5      0.0              patternres = search_rows_for_many_patterns(rm.rows, many_patterns, rm.width,
   152      2525        44631     17.7      0.0                                                  search_left = left, search_right = right,
   153      2525      3926434   1555.0      0.7                                                  search_top = top, search_bottom = bottom)
   154                                                       
   155      2525        51772     20.5      0.0              if patternres:
   156        94         1301     13.8      0.0                  res_is_unique_to_this_size = False
   157        94         1289     13.7      0.0                  res = False
   158                                                           
   159                                                           #maybe show it too
   160                                                           
   161        94         1466     15.6      0.0                  patternx, patterny = patternres[3], patternres[4]
   162        94         1521     16.2      0.0                  if patternx * patterny > PATTERN_MIN_TO_SHOW:
   163                                                               patternnum = patternres[2]
   164                                                               coord = (patternres[0], patternres[1])
   165                                                               coords = set()
   166                                                               for xx in range(patternx):
   167                                                                   for yy in range(patterny):
   168                                                                       pos = addpos(coord, (xx, yy))
   169                                                                       if not rm.isopen(pos):
   170                                                                           coords.add(pos)
   171                                                               rm.show(coords)
   172                                                               print('bad at %s of size: %dx%d' % (str(coord), patternx, patterny))
   173                                                               print('')
   174      2525        46841     18.6      0.0              if not patternres:
   175      2431      2393190    984.4      0.4                  sections = multi_flow_in_set(rm.allsqs)
   176      6303       138167     21.9      0.0                  for section in sections:
   177      3872        85441     22.1      0.0                      if section.isdisjoint(rm.gatesqs):
   178                                                                   import ipdb;ipdb.set_trace()
   179                                                                   need_to_check = False
   180                                                                   res = False
   181      2431        44910     18.5      0.0                  if need_to_check:
   182      2431    348396336 143314.0     59.3                      sols=get_all_sols(rm, board, toplevel = False, getone = True)
   183                                                               if 0:
   184                                                                   nm=str(sorted(poss)).replace(' ','')
   185      2431        66736     27.5      0.0                      if sols==TIMELIMIT:
   186                                                                   import ipdb;ipdb.set_trace()
   187                                                                   continue
   188      2431        46031     18.9      0.0                      elif not sols:
   189                                                                   #nm=str(sorted(poss)).replace(' ','')
   190                                                                   #fname='BAD-%sroomtest-bad'%(nm)
   191                                                                   #board.smh(rm,text=fname)
   192        73         1409     19.3      0.0                          res = False
   193                                                               else:
   194                                                                   #fname='GOOD-%sroomtest-good'%(nm)
   195                                                                   #board.smh(rm,text=fname)
   196      2358        43407     18.4      0.0                          res = True
   197                                                               
   198      4736        84968     17.9      0.0          if res_is_unique_to_this_size:
   199      2435        44084     18.1      0.0              if res:
   200      2362        54488     23.1      0.0                  uniq_good_bignums.add(bignum) 
   201                                                       else:
   202        73         1681     23.0      0.0                  uniq_bad_bignums.add(bignum)
   203                                                           #show the baddies.
   204        73       311825   4271.6      0.1                  bignum_show(bignum, width, height)
   205        73        67225    920.9      0.0                  print('')
   206                                                   else:
   207      2301        39677     17.2      0.0              if res:
   208                                                           repeat_good_bignums.add(bignum)
   209                                                       else:
   210      2301        47033     20.4      0.0                  repeat_bad_bignums.add(bignum)
   211                                           
   212      4736        79245     16.7      0.0          if 0 and bignum % 100 == 0:
   213                                                       print('%d/%d done.  good %d/%d, bad %d/%d' % (bignum, searcher.maxnum,
   214                                                                                                     len(uniq_good_bignums),
   215                                                                                                     len(repeat_good_bignums),
   216                                                                                                     len(uniq_bad_bignums),
   217                                                                                                     len(repeat_bad_bignums)))
   218                                                       print('%0.1fs' % (time.clock() - st))
   219                                                       if bignum % 10000 == 0:
   220                                                           print('uniq good: %s' % uniq_good_bignums)
   221                                                           print('uniq bad: %s' % uniq_bad_bignums)
   222                                                           print('repeat good: %s' % uniq_good_bignums)
   223                                                           print('repeat bad: %s' % uniq_bad_bignums)
   224                                           
   225         4           89     22.2      0.0      return uniq_good_bignums, uniq_bad_bignums, repeat_good_bignums, repeat_bad_bignums

