def run_test(map_path, timeout):
    start = clock()
    world = World.from_file(map_path)
    print 'solving {:50}'.format(map_path),
    
    start = clock()
    solver = Solver(world, timeout=timeout)
    solver.solve()
    score, solution = solver.get_best()
    solver.log_stats()
    t = clock()-start    
    
    
    world = World.from_file(map_path)
    for cmd in solution:
        world = world.apply_command(cmd)
        if world.terminated:
            break
    validated_score = world.score
    
    assert score == validated_score, (score, validated_score)
    print '{:>10} {:>10.3f}s'.format(score, t)
    print 'genetic done', score
    if score > 0:
        solver.best_score = score
        solver.best_solution = solution
        


if __name__ == '__main__':
    realout = sys.stdout
    sys.stdout = sys.stderr

    signal.signal(signal.SIGINT, handler)
    
    data = sys.stdin.read()
    world = World.from_string(data)
    
    world.show()
    
    solver = Solver(world, timeout=1000000)
    
    greedy(World(world))
    
    call_genetic(World(world))
    
    solver.solve()
    
    print>>realout, solver.get_best()[1]
    print 'final score', solver.get_best()[0]
    
    sys.stdout = realout