main.py
def buildGraph(a, b):
    """ Creates a Graph with all possible vertices and edges. Required
    arguments are the maximum amount that jug a and jug b can hold as an
    integer."""
    state = (0, 0)
    q = Queue()
    g = Graph()
    g.addVertex(state)
    q.enqueue(state)
    while q.size() > 0:
        state = q.dequeue()
        x = state[0]
        y = state[1]
        # Empty jug a
        if x > 0:
            if g.getVertex((0, y)):
                g.addEdge(state, (0, y))
            else:
                q.enqueue((0, y))
                g.addEdge(state, (0, y))
        # Empty jug b
        if y > 0:
            if g.getVertex((x, 0)):
                g.addEdge(state, (x, 0))
            else:
                q.enqueue((x, 0))
                g.addEdge(state, (x, 0))
        # Fill jug a
        if x < a:
            if g.getVertex((a, y)):
                g.addEdge(state, (a, y))
            else:
                q.enqueue((a, y))
                g.addEdge(state, (a, y))
        # Fill jug b
        if y < b:
            if g.getVertex((x, b)):
                g.addEdge(state, (x, b))
            else:
                q.enqueue((x, b))
                g.addEdge(state, (x, b))
        # Poor jug b into jug a
        if x < a and y > 0:
            tx = x
            ty = y
            while tx < a and ty > 0:
                tx += 1
                ty -= 1
            if g.getVertex((tx, ty)):
                g.addEdge(state, (tx, ty))
            else:
                q.enqueue((tx, ty))
                g.addEdge(state, (tx, ty))
        # Poor jug a into jug b
        if y < b and x > 0:
            tx = x
            ty = y
            while ty < b and tx > 0:
                tx -= 1
                ty += 1
            if g.getVertex((tx, ty)):
                g.addEdge(state, (tx, ty))
            else:
                q.enqueue((tx, ty))
                g.addEdge(state, (tx, ty))
    return g
 Creates a Graph with all possible vertices and edges. Required
    arguments are the maximum amount that jug a and jug b can hold as an
    integer.
Creates a Graph with all possible vertices and edges. Required
arguments are the maximum amount that jug a and jug b can hold as an
integer.
Creates a Graph with all possible vertices and edges . Required arguments are the maximum amount that jug a and jug b can hold as an integer .
def buildGraph(a, b):
    state = (0, 0)
    q = Queue()
    g = Graph()
    g.addVertex(state)
    q.enqueue(state)
    while q.size() > 0:
        state = q.dequeue()
        x = state[0]
        y = state[1]
        if x > 0:
            if g.getVertex((0, y)):
                g.addEdge(state, (0, y))
            else:
                q.enqueue((0, y))
                g.addEdge(state, (0, y))
        if y > 0:
            if g.getVertex((x, 0)):
                g.addEdge(state, (x, 0))
            else:
                q.enqueue((x, 0))
                g.addEdge(state, (x, 0))
        if x < a:
            if g.getVertex((a, y)):
                g.addEdge(state, (a, y))
            else:
                q.enqueue((a, y))
                g.addEdge(state, (a, y))
        if y < b:
            if g.getVertex((x, b)):
                g.addEdge(state, (x, b))
            else:
                q.enqueue((x, b))
                g.addEdge(state, (x, b))
        if x < a and y > 0:
            tx = x
            ty = y
            while tx < a and ty > 0:
                tx += 1
                ty -= 1
            if g.getVertex((tx, ty)):
                g.addEdge(state, (tx, ty))
            else:
                q.enqueue((tx, ty))
                g.addEdge(state, (tx, ty))
        if y < b and x > 0:
            tx = x
            ty = y
            while ty < b and tx > 0:
                tx -= 1
                ty += 1
            if g.getVertex((tx, ty)):
                g.addEdge(state, (tx, ty))
            else:
                q.enqueue((tx, ty))
                g.addEdge(state, (tx, ty))
    return g
def buildGraph ( a , b ) : state = ( 0 , 0 ) q = Queue ( ) g = Graph ( ) g . addVertex ( state ) q . enqueue ( state ) while q . size ( ) > 0 : state = q . dequeue ( ) x = state [ 0 ] y = state [ 1 ] if x > 0 : if g . getVertex ( ( 0 , y ) ) : g . addEdge ( state , ( 0 , y ) ) else : q . enqueue ( ( 0 , y ) ) g . addEdge ( state , ( 0 , y ) ) if y > 0 : if g . getVertex ( ( x , 0 ) ) : g . addEdge ( state , ( x , 0 ) ) else : q . enqueue ( ( x , 0 ) ) g . addEdge ( state , ( x , 0 ) ) if x < a : if g . getVertex ( ( a , y ) ) : g . addEdge ( state , ( a , y ) ) else : q . enqueue ( ( a , y ) ) g . addEdge ( state , ( a , y ) ) if y < b : if g . getVertex ( ( x , b ) ) : g . addEdge ( state , ( x , b ) ) else : q . enqueue ( ( x , b ) ) g . addEdge ( state , ( x , b ) ) if x < a and y > 0 : tx = x ty = y while tx < a and ty > 0 : tx += 1 ty -= 1 if g . getVertex ( ( tx , ty ) ) : g . addEdge ( state , ( tx , ty ) ) else : q . enqueue ( ( tx , ty ) ) g . addEdge ( state , ( tx , ty ) ) if y < b and x > 0 : tx = x ty = y while ty < b and tx > 0 : tx -= 1 ty += 1 if g . getVertex ( ( tx , ty ) ) : g . addEdge ( state , ( tx , ty ) ) else : q . enqueue ( ( tx , ty ) ) g . addEdge ( state , ( tx , ty ) ) return g
Creates a Graph with all possible vertices and edges.
Creates a Graph with all possible vertices and edges .
""" Creates a Graph with all possible vertices and edges. Required
    arguments are the maximum amount that jug a and jug b can hold as an
    integer.""" # Empty jug a # Empty jug b # Fill jug a # Fill jug b # Poor jug b into jug a # Poor jug a into jug b
a
b