def _solve(fringe, explored, lock, num_threads):
    global waiting, is_finished
    while waiting < num_threads and not is_finished:
        while not fringe:
            with lock:
                waiting += 1
            with cv:
                cv.wait()
            with lock:
                waiting -= 1
        # stack
        grid = fringe.pop()
        if grid in explored:
            continue
        if is_solved(grid):
            is_finished = True
            return grid
        with lock:
            explored.append(grid)

        _, square = min_possible_values(grid)
        for digit in grid[square]:
            new_grid = place(grid.copy(), square, digit)
            if new_grid and valid_grid(new_grid):
                with lock:
                    fringe.append(new_grid)
                with cv:
                    cv.notify()

    return False
Esempio n. 2
0
    async def solve(self, num_threads):

        # while self.waiting < num_threads:
        # while not self.fringe:
        #     self.waiting += 1
        #     with Sudoku.cv:
        #         Sudoku.cv.wait()
        #     self.waiting -= 1
        while True:
            await self.queue.consume(self.consume)
            # stack
            if not self.fringe:
                continue
            with Sudoku.lock:
                grid = self.fringe.pop()
            if grid in self.explored:
                continue
            if is_solved(grid):
                await self.exchange.publish(Message(
                    json.dumps(grid).encode('utf-8')),
                                            routing_key=Sudoku.QUEUE_NAME)
                return grid
            self.explored.append(grid)
            _, square = min_possible_values(grid)
            for digit in grid[square]:
                new_grid = place(grid.copy(), square, digit)
                if new_grid and valid_grid(new_grid):
                    await self.exchange.publish(Message(
                        json.dumps(new_grid).encode('utf-8')),
                                                routing_key=Sudoku.QUEUE_NAME)
        return False
Esempio n. 3
0
def test_zero():
    cv = CanvasPDK()
    ox = oy = 0
    track_pattern = {'G': [6], 'S': [4], 'D': [2]}
    for nfin in range(1, 9):
        ox = 0
        for model_name in ['n', 'p']:
            for device_type in ["stack", "parallel"]:
                for nf in [2, 4, 6]:
                    mg = MOS()
                    tx = Transistor(model_name=model_name,
                                    nf=nf,
                                    nfin=nfin,
                                    device_type=device_type)
                    data = mg.mos(tx, track_pattern=track_pattern)
                    place(cv, data, ox, oy)
                    ox += data['bbox'][2]
        oy += data['bbox'][3]
    compare_with_golden("test_transistor_0", cv)
Esempio n. 4
0
def storyline(yyyyMMdd):
    info = moves.user_storyline_daily(yyyyMMdd, trackPoints={'false'}, access_token='access_token')
    print info[0]['date']
    segments = info[0]['segments']
    # print json.dumps(segments, indent=2)
    res = ''
    for segment in segments:
        if segment['type'] == 'place':
            res = utils.place(segment, res)
        elif segment['type'] == 'move':
            res = utils.move(segment, res)
        res += '<hr>'
    return res
Esempio n. 5
0
def storyline(yyyyMMdd):
    info = moves.user_storyline_daily(yyyyMMdd,
                                      trackPoints={'false'},
                                      access_token='access_token')
    print info[0]['date']
    segments = info[0]['segments']
    # print json.dumps(segments, indent=2)
    res = ''
    for segment in segments:
        if segment['type'] == 'place':
            res = utils.place(segment, res)
        elif segment['type'] == 'move':
            res = utils.move(segment, res)
        res += '<hr>'
    return res
Esempio n. 6
0
def solve_1(grid, num_threads):
    explored = []
    lock = Lock()
    executors = ThreadPoolExecutor(max_workers = num_threads)
    futures = []
    _, square = max_possible_values(grid)
    for digit in grid[square]:
        new_grid = place(grid.copy(), square, digit)
        if new_grid and valid_grid(grid):
            futures.append(executors.submit(_solve, [new_grid], explored, lock))
    
    result = False
    for future in as_completed(futures):
        result = result or future.result()
        if result:
            return result
    return False
Esempio n. 7
0
def _solve(fringe, explored, lock):
    while fringe:
        # queue
        grid = fringe.pop(0)

        # stack
        # grid = fringe.pop()

        if grid in explored:
            continue
        if is_solved(grid):
            return grid
        _, square = min_possible_values(grid)
        with lock:
            explored.append(grid)
        for digit in grid[square]:
            new_grid = place(grid.copy(), square, digit)
            if new_grid and valid_grid(new_grid):
                fringe.append(new_grid)
    return False