def testGetPayoffMatrixFromFile(self):
        games = {
                 'bosx.nfg' :
                        [[[4, 2], [0, 0], [0, 1]], 
                         [[0, 0], [2, 4], [1, 3]]], 
                 
                 'sspes.nfg' :
                        [[[0, 0], [-1, 1], [1, -1], [1, -1], [-1, 1]], 
                         [[1, -1], [0, 0], [-1, 1], [1, -1], [-1, 1]], 
                         [[-1, 1], [1, -1], [0, 0], [-1, 1], [1, -1]], 
                         [[-1, 1], [-1, 1], [1, -1], [0, 0], [1, -1]], 
                         [[1, -1], [1, -1], [-1, 1], [-1, 1], [0, 0]]],
                 
                 'airstrike4.nfg' : 
                        [[[0, 0], [2, -2], [2, -2], [2, -2]], 
                         [[3, -3], [0, 0], [3, -3], [3, -3]], 
                         [[4, -4], [4, -4], [0, 0], [4, -4]], 
                         [[5, -5], [5, -5], [5, -5], [0, 0]]], 
                 
                 'bos.nfg' : 
                        [[[2, 1], [0, 0]], 
                         [[0, 0], [1, 2]]], 
                 
                 'sspb.nfg' : 
                        [[[0, 0], [-1, 1], [1, -1], [-1, 1]], 
                         [[1, -1], [0, 0], [-1, 1], [-1, 1]], 
                         [[-1, 1], [1, -1], [0, 0], [1, -1]], 
                         [[1, -1], [1, -1], [-1, 1], [0, 0]]], 
                 
                 'chicken.nfg' :
                        [[[3, 3], [2, 4]], 
                         [[4, 2], [1, 1]]], 
                 
                 'coordination.nfg' : 
                        [[[3, 3], [0, 0]], 
                         [[0, 0], [1, 1]]],
                 
                 'airstrike.nfg' : 
                        [[[0, 0], [2, -2], [2, -2]], 
                         [[3, -3], [0, 0], [3, -3]], 
                         [[4, -4], [4, -4], [0, 0]]]

                 }

        for (filename, payoffMatrix) in games.iteritems():
            game = NfgReader().read(filename="../games/" + filename)
            self.assertEquals(payoffMatrix, game.getPayoffMatrix())
Exemplo n.º 2
0
def statistics():
    games = os.listdir("../games/")
    runs = 10
    #games = ["stengel.nfg"]
    for file in games:
        game = NfgReader().read(filename="../games/" + file)
        print game.game_title
        
        print "Computing one NE with own algorithm...",
        alltime = 0
        for i in range(runs):
            startTime = time.time()
            game.findMixedNash(oneNash = True)
            alltime += time.time() - startTime
        print "Time: " + str(alltime/runs) + "\n", 
        
        print "Computing all NE with own algorithm...",
        alltime = 0
        for i in range(runs):
            startTime = time.time()
            game.findMixedNash(oneNash = False)
            alltime += time.time() - startTime
        print "Time: " + str(alltime/runs) + "\n"
        
        
        print "Computing one NE with gambit...",
        alltime = 0
        for i in range(runs):
            startTime = time.time()
            os.system("gambit-simpdiv -q -S " + "< ../games/" + file + " > /dev/null")
            alltime += time.time() - startTime
        print "Time: " + str(alltime/runs) + "\n"
        
        
        print "Computing all NE with gambit...",
        alltime = 0
        for i in range(runs):
            startTime = time.time()
            os.system("gambit-enummixed -q -S " + "< ../games/" + file + " > /dev/null")
            alltime += time.time() - startTime
        print "Time: " + str(alltime/runs) + "\n"
        print "-----------------------------------------------------------"