Exemplo n.º 1
0
def testGame(file_path):

    TEST_CASES = 100

    game = gambit.read_game(file_path)

    vertices, edges = CorrEq.findPolygon(game)
    edges = CorrEq.removeExtraEdges(vertices, edges)

    constraints = deriveConstraints(game)

    points = CorrEq.orderVertices(edges)

    if points == None:
        points = vertices

    for i in range(TEST_CASES):
        # Pick a random probability distribution
        probs = [random() for j in range(len(game.contingencies))]
        # Ensure probabilities sum to 1
        probs = [j / sum(probs) for j in probs]

        # Determine whether the distribution is a correlated equilibrium
        # It is if it satisfies the constraints in the LP
        is_corr_eq = True

        for j in constraints:
            if sum(multiply(probs, j)) < 0:
                is_corr_eq = False
                break

        u1, u2 = CorrEq.probsToUtilities(probs, game)
        inside = pnpoly(u1, u2, points)

        if is_corr_eq == True and inside == False:
            raise Exception('Test failed on: ' + file_path)
            print 'Test failed on: ' + file_path
def testGame(file_path):

    TEST_CASES = 100
    
    game = gambit.read_game(file_path)

    vertices,edges = CorrEq.findPolygon(game)
    edges = CorrEq.removeExtraEdges(vertices,edges)

    constraints = deriveConstraints(game)

    points = CorrEq.orderVertices(edges)

    if points == None:
        points = vertices
    
    for i in range(TEST_CASES):
        # Pick a random probability distribution
        probs = [random() for j in range(len(game.contingencies))]       
        # Ensure probabilities sum to 1
        probs = [j/sum(probs) for j in probs]
        
        # Determine whether the distribution is a correlated equilibrium
            # It is if it satisfies the constraints in the LP       
        is_corr_eq = True
        
        for j in constraints:
            if sum(multiply(probs,j)) < 0:
                is_corr_eq = False
                break
        
        u1,u2 = CorrEq.probsToUtilities(probs, game)
        inside = pnpoly(u1,u2,points)
        
        if is_corr_eq == True and inside == False:
            raise Exception('Test failed on: ' + file_path)
            print 'Test failed on: ' + file_path