def __call__(self, model):
     #    For each cell, for each value for each dim:
     #    remove value as a possible from each adjacent cell.
     for cell in model.cells:
         self._checkAbort()
         cellsR = model.getCellsForRow(cell)
         cellsC = model.getCellsForCol(cell)
         for index, row in enumerate(cell.rows):
             known = aRow(row).knowns()
             if len(list(known))>0:
                 self._checkAbort()
                 for cell_ in cellsR:
                     row_ = cell_.getRow(index)
                     for element in row_:
                         if not element.hasValue():
                             possibles = element.getPossibles()
                             element.setPossibles(possibles-known)
         for index, col in enumerate(cell.cols):
             known = aCol(col).knowns()
             if len(list(known))>0:
                 for cell_ in cellsC:
                     self._checkAbort()
                     col_ = cell_.getCol(index)
                     for element in col_:
                         if not element.hasValue():
                             possibles = element.getPossibles()
                             element.setPossibles(possibles-known)
Ejemplo n.º 2
0
    def __callOLD__(self, model, vertex, altVertex):
        print model.prettyprint()
        allXwings = collections.defaultdict(list)
        for value in model.unknowns():
            for rr in xrange(model._maxSize):
                xwings = collections.defaultdict(list)
                r = aRow(model.findElementsForRow(rr))
                unknownCounts = r.unknownCounts()
                if value in unknownCounts.keys():
                    if len(unknownCounts[value])==2:
                        #    Now look in the other vertex (cols) for these
                        #    coords.
                        cols = [elUref.absCol for elUref in unknownCounts[value]]
                        #    Get the 2 columns and see if any of 'value' appear in the
                        #    columns on the same row index.
                        cols0 = aCol(model.findElementsForCol(cols[0]))
                        cols1 = aCol(model.findElementsForCol(cols[1]))
                        try:
                            uc0 = cols0.unknownCounts()
                            uc1 = cols1.unknownCounts()
                            if ((len(uc0[value])>=2) and
                                (len(uc1[value])>=2) ):
                                #    Now see if the index's overlap on at least 2:
                                #    At least 2 uRef's from uc0 should be same row as uc1:
                                rows_ = []
                                for i in uc0[value]:
                                    iR = i.absRow
                                    for k in uc1[value]:
                                        kR = k.absRow
                                        if iR==kR:
                                            rows_.append(([i.absCol, k.absCol], iR))
                                #    Now make sure 'value' is only present twice in each
                                #    rows' possible values.
                                for (cols, row) in rows_:
                                    tRow = aRow(model.findElementsForRow(row))
                                    c = tRow.countPossibleValues()
                                    if c[value]==2:
#                                         print "'%s' is present twice in row: %s"%(value, row)
                                        if row not in xwings[value]:
                                            xwings[value].append(row)
                        except Exception, _e:
                            #    no luck!
                            pass
                voo = Set(xwings[value])
                if voo not in allXwings[value]:
                    allXwings[value].append(voo)
Ejemplo n.º 3
0
    def __call__(self, model):
        for digits in xrange(2, model._maxSize):
#             print model.prettyprint()
            #    Work on cells first:
            for cell in model.cells:
                unknownElements = cell.getUnknownElements()
                self._work(unknownElements, digits)
#                 print model.prettyprint()
            #    Now work on rows:
            for row in model.getElementRows():
                row = aRow(row)
                unknownElements = row.getUnknownElements()
                self._work(unknownElements, digits)
#                 print model.prettyprint()
            #    Now work on cols:
            for col in model.getElementCols():
                col = aCol(col)
                unknownElements = col.getUnknownElements()
                self._work(unknownElements, digits)
Ejemplo n.º 4
0
#                         print "> %s"%k
        #    Now fix the xwings:
        for value, i in newXwings.items():
            for k in i:
                for j in k:
                    j = list(j)
                    #    Got an xwing in rows, so get the cols for 'value':
#                     print "value: %s in rows: %s"%(value, j)
                    r = j[0]
                    row = aRow(model.findElementsForRow(r))
                    #    Get the cols for both possibleValues=value:
                    cols = []
                    for col, el in enumerate(row):
                        if not el.hasValue():
                            possibles = el.getPossibles()
                            if value in possibles:
                                cols.append(aCol(model.findElementsForCol(col)))
#                     print cols
                    #    Now remove 'value' from the cols possibles EXCEPT
                    #    from rows in j.
                    for col in cols:
                        for index, el in enumerate(col):
                            if index not in j:
                                if not el.hasValue():
                                    possibles = el.getPossibles()
                                    newPossibles = possibles-Set([value])
                                    el.setPossibles(newPossibles)
                    print "Fixed xwing for value: %s in cols: %s"%(value, j)