week3/crossword/generate.py
def ac3(self, arcs=None):
        """
        USE PSEUDOCODE FROM THE LECTURE NOTES

        Update `self.domains` such that each variable is arc consistent.
        If `arcs` is None, begin with initial list of all arcs in the problem.
        Otherwise, use `arcs` as the initial list of arcs to make consistent.

        Return True if arc consistency is enforced and no domains are empty;
        return False if one or more domains end up empty.
        """
        if arcs is None:  # if given arcs is none, initialize a queue with all edges (arcs)
            arcs = deque()
            for v1 in self.crossword.variables:
                for v2 in self.crossword.neighbors(v1):
                    arcs.appendleft((v1, v2))
        else:  # if given arcs is not None, convert the list to deque
            arcs = deque(arcs)

        while arcs:
            x, y = arcs.pop()
            if self.revise(x, y):  # revise each combination of nodes in an edge (arc)
                # if there are no variables for x, return False, meaning that arc
                # consistency is impossible
                if len(self.domains[x]) == 0:
                    return False

                # take all x's neighbors except Y and add the edges between them and x to the queue
                for z in self.crossword.neighbors(x) - {y}:
                    arcs.appendleft((z, x))

        return True

        USE PSEUDOCODE FROM THE LECTURE NOTES

        Update `self.domains` such that each variable is arc consistent.
        If `arcs` is None, begin with initial list of all arcs in the problem.
        Otherwise, use `arcs` as the initial list of arcs to make consistent.

        Return True if arc consistency is enforced and no domains are empty;
        return False if one or more domains end up empty.
        


Return True if arc consistency is enforced and no domains are empty;
return False if one or more domains end up empty.
Return True if arc consistency is enforced and no domains are empty ; return False if one or more domains end up empty .
def ac3(self, arcs=None):
        if arcs is None:  
            arcs = deque()
            for v1 in self.crossword.variables:
                for v2 in self.crossword.neighbors(v1):
                    arcs.appendleft((v1, v2))
        else:  
            arcs = deque(arcs)
        while arcs:
            x, y = arcs.pop()
            if self.revise(x, y):  
                if len(self.domains[x]) == 0:
                    return False
                for z in self.crossword.neighbors(x) - {y}:
                    arcs.appendleft((z, x))
        return True
def ac3 ( self , arcs = None ) : if arcs is None : arcs = deque ( ) for v1 in self . crossword . variables : for v2 in self . crossword . neighbors ( v1 ) : arcs . appendleft ( ( v1 , v2 ) ) else : arcs = deque ( arcs ) while arcs : x , y = arcs . pop ( ) if self . revise ( x , y ) : if len ( self . domains [ x ] ) == 0 : return False for z in self . crossword . neighbors ( x ) - { y } : arcs . appendleft ( ( z , x ) ) return True
USE PSEUDOCODE FROM THE LECTURE NOTES
Update `self.domains` such that each variable is arc consistent.
USE PSEUDOCODE FROM THE LECTURE NOTES Update ` self . domains ` such that each variable is arc consistent .
"""
        USE PSEUDOCODE FROM THE LECTURE NOTES

        Update `self.domains` such that each variable is arc consistent.
        If `arcs` is None, begin with initial list of all arcs in the problem.
        Otherwise, use `arcs` as the initial list of arcs to make consistent.

        Return True if arc consistency is enforced and no domains are empty;
        return False if one or more domains end up empty.
        """ # if given arcs is none, initialize a queue with all edges (arcs) # if given arcs is not None, convert the list to deque # revise each combination of nodes in an edge (arc) # if there are no variables for x, return False, meaning that arc # consistency is impossible # take all x's neighbors except Y and add the edges between them and x to the queue
self
arcs