Ejemplo n.º 1
0
def main(start=None, addr=None, port=None, slave=None):
    if slave:
        client = SeatingSlave(addr, port)
        client.run()
    else:
        if start:
            if start.endswith('.xls') or start.endswith('.xlsx'):
                state = read_excel(open(start).read())
            elif start.endswith('.txt'):
                state = read_text(open(start).read())
            else:
                raise Exception("Don't know how to open %s" % start)

        else:
            state = start_seating()

        print dump(state)
        state.shuffle()

        state_evaluator = SquareStateEvaluator(
            TablePositionAgnosticClosnessEvaluator())
        server = SeatingMaster(
            StateKeeper(HillClimber(state_evaluator), state=state),
            (addr, 5000), state_evaluator)
        server.run()
Ejemplo n.º 2
0
def main(start=None, addr=None, port=None, slave=None):
    if slave:
        client = SeatingSlave(addr, port)
        client.run()
    else:
        if start:
            if start.endswith('.xls') or start.endswith('.xlsx'):
                state = read_excel(open(start).read())
            elif start.endswith('.txt'):
                state = read_text(open(start).read())
            else:
                raise Exception("Don't know how to open %s" % start)

        else:
            state = start_seating()

        print dump(state)
        state.shuffle()

        state_evaluator = SquareStateEvaluator(TablePositionAgnosticClosnessEvaluator())
        server = SeatingMaster(
            StateKeeper(
                HillClimber(state_evaluator),
                state=state),
            (addr, 5000),
            state_evaluator
        )
        server.run()
Ejemplo n.º 3
0
def test_optimize():
    initial = start_seating()
    evaluator = TablePositionAgnosticClosnessEvaluator()
    searcher = SingleThreadedSearcher(
        ClosenessStepper(evaluator),
        SquareStateEvaluator(evaluator),
        PrintLogger()
    )
    state, e1 = searcher.search(initial, n=1)
    _, e2 = searcher.search(initial, n=100)
    assert e2 < e1
Ejemplo n.º 4
0
def test_swap():
    initial = start_seating(persons=2, meals=3, positions=2, groups=0)

    state = initial.copy()
    assert dump(initial) == dump(state)
    state.swap(2, 4, 0, 1)
    assert dump(initial) != dump(state)
    state.swap(2, 4, 0, 1)
    assert dump(initial) == dump(state)
    _assert_same_state(initial, state)
    assert initial == state
    assert not initial != state
Ejemplo n.º 5
0
def main():
    filename = sys.argv[1] if len(sys.argv) == 2 else "seating.xls"
    if filename.endswith('.xls') or filename.endswith('.xlsx'):
        state = read_excel(open(filename).read())
    elif filename.endswith('.txt'):
        state = read_text(open(filename).read())
    else:
        state = start_seating()

    state.shuffle()
    state = fast_search(state)

    print dump(state)
    print report(state)
    print repr(state)
    print write_text(state)
    with open("seating.xls", "wb") as f:
        f.write(write_excel(state))
Ejemplo n.º 6
0
def main():
    filename = sys.argv[1] if len(sys.argv) == 2 else "seating.xls"
    if filename.endswith('.xls') or filename.endswith('.xlsx'):
        state = read_excel(open(filename).read())
    elif filename.endswith('.txt'):
        state = read_text(open(filename).read())
    else:
        state = start_seating()

    state.shuffle()
    state = fast_search(state)

    print dump(state)
    print report(state)
    print repr(state)
    print write_text(state)
    with open("seating.xls", "wb") as f:
        f.write(write_excel(state))
Ejemplo n.º 7
0
def test_fast_search():
    initial = start_seating()
    score = energy_sum_of_square
    e1 = score(initial)
    e2 = score(fast_search(initial, score=score, n=100))
    assert e2 < e1
Ejemplo n.º 8
0
Charlie
Dave

# Group 1 (17)

Alice
Bob

# Group 2 (42)

Charlie
Dave
""")


@pytest.fixture(params=[start_seating(),
                        explicit_initial()])
def initial(request):
    return request.param


def test_json(initial):
    json = initial.to_json()
    actual = State.from_json(json)
    _assert_same_state(initial, actual)


def test_excel(initial):
    excel_content = write_excel(initial)
    actual = read_excel(excel_content)
    _assert_same_state(initial, actual)