コード例 #1
0
def start(board, window, top, algorithm):
    # tracker for when algorithm is finished
    done = False
    while True:
        top.update_idletasks()
        top.update()
        # start time
        start = time.time()
        # reset iterations
        game.iterations = 0
        # call appropriate algorithm based on user input
        if algorithm.lower() == 'reverse backtracking':
            game.solve(board, window, top, start, reverse=True)
        elif algorithm.lower() == 'best first search':
            game.solve(board, window, top, start, optimized=True)
        elif algorithm.lower() == 'algorithm x':
            for solution in game.solve_Algorithm_X(board, window, top):
                pass
        else:
            game.solve(board, window, top, start)
        # once algorithm finishes, update the time taken and number of iterations
        if not done:
            window.redraw(board,
                          -1,
                          -1,
                          game.iterations,
                          round(time.time() - start, 10),
                          done=True)
            done = True
コード例 #2
0
    def place(self, val):
        row, col = self.selected
        if self.cubes[row][col].value == 0:
            self.cubes[row][col].set(val)
            self.update_model()

            if valid(self.model, val, (row, col)) and solve(self.model):
                return True
            else:
                self.cubes[row][col].set(0)
                self.cubes[row][col].set_temp(0)
                self.update_model()
                return False
コード例 #3
0
def test_solve(n, expect):
    assert expect == solve(n)
コード例 #4
0
ファイル: run.py プロジェクト: sallen7/ice
import ce
import game
import loss
import numpy
import routing
import sample
import sgd

N = 4  # number of players
T = 100000  # SGD iterations
M = 100  # samples of play
eps = 0.01  # multinomial smoothing
C = 0.01  # CE max welfare coefficient
c = C * numpy.ones(N)
w = numpy.array([0.0, 0.0, 0.0, 1.0])  # true utility function

g = routing.create(N)
truth = ce.solve(g, c, w, sgd.create(T, 1, 0, 0, sgd.Rpprox))
demon = sample.draw(M, truth)

inst = game.to_instance((g, demon))
w = game.solve(inst, sgd.create(T, 1, 0, 0))
pred = game.predict(inst, w)

print(('multinomial loss', loss.logloss(truth, demon, eps)))
print(('ice loss', loss.logloss(truth, pred)))
print(('truth entropy', loss.logloss(truth, truth)))
コード例 #5
0
ファイル: final_solver.py プロジェクト: pbl64k/icfpc2015
    print 'Global dealine:', deadline

seed_deadline = None

fnum = 0
for fn in args.f:
    if witht:
        t = time.time()
        file_deadline = t + ((deadline - t) / (len(args.f) - fnum))
        if pdl:
            print fn, 'deadline:', file_deadline
    snum = 0
    for seeds, game in konstruckt(fn, args.nodebug):
        if witht:
            t = time.time()
            seed_deadline = t + ((file_deadline - t) / (seeds - snum))
            if pdl:
                print fn, 'seed', game.lcg.seed, 'deadline:', seed_deadline
        s = game.solve(seed_deadline)
        sols.append({'problemId': game.id, 'seed': game.lcg.seed, 'tag': curTag + '-' + str(game.id) + '-' + str(game.lcg.seed) + '-' + str(time.time()), 'solution': s})
        snum += 1
    fnum += 1

print json.dumps(sols)

if not args.nosave:
    fn = 'solutions/solution_' + str(game.id) + '.json'
    f = open(fn, 'w+')
    f.write(json.dumps(sols))

コード例 #6
0
ファイル: initials.py プロジェクト: workingenius/huarongdao
    height = 5

    initial = L(B(G(1, 3), G(2, 3), G(1, 4), G(2, 4), cap='曹'),
                B(G(0, 3), cap='董'), B(G(0, 2), G(0, 1), G(1, 2), cap='刘'),
                B(G(3, 2), G(4, 2), cap='吕'), B(G(3, 3), cap='陶'),
                B(G(4, 3), G(3, 4), G(4, 4), cap='袁'),
                B(G(3, 0), G(4, 1), G(4, 0), cap='孙'),
                B(G(1, 0), G(1, 1), cap='晋'), B(G(0, 4), cap='马'))


class Game99(Game):
    title = '逗逼三国'

    width = 5
    height = 5

    initial = L(
        B(G(1, 3), G(2, 3), G(1, 4), G(2, 4), cap='曹'),
        B(G(0, 2), G(0, 3), G(1, 2), G(1, 1), cap='刘'),
        B(G(3, 1), G(3, 2), G(4, 1), G(2, 1), G(3, 0), cap='孙'),
        # B(G(4, 3), cap='袁')
    )


if __name__ == '__main__':
    import sys
    num = sys.argv[1]

    gm_cls = locals()['Game' + str(num)]
    solve(gm_cls())
コード例 #7
0
ファイル: tests.py プロジェクト: geekypandey/sudoku-solver
def test_two(test_input, expected, capsys):
    solve(test_input)
    captured = capsys.readouterr()
    assert captured.out.strip() == expected
コード例 #8
0
ファイル: run.py プロジェクト: kdub0/ice
import ce
import game
import loss
import numpy
import routing
import sample
import sgd

N = 4      # number of players
T = 100000 # SGD iterations
M = 100    # samples of play
eps = 0.01 # multinomial smoothing
C   = 0.01 # CE max welfare coefficient
c   = C*numpy.ones(N);
w   = numpy.array([0.0,0.0,0.0,1.0]) # true utility function


g     = routing.create(N)
truth = ce.solve(g, c, w, sgd.create(T, 1, 0, 0, sgd.Rpprox))
demon = sample.draw(M, truth) 

inst  = game.to_instance((g,demon))
w     = game.solve(inst, sgd.create(T, 1, 0, 0))
pred  = game.predict(inst, w)

print 'multinomial loss', loss.logloss(truth, demon, eps)
print 'ice loss', loss.logloss(truth, pred)
print 'truth entropy', loss.logloss(truth, truth)