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()
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()
def test_excel_change_geometry(): start_state = read_text("""\ # Meal #0 3 2 1 0 # Meal #1 3 2 1 0 # Meal #2 2 1 0 """) assert dump(start_state) == """\ # Meal #0 [2 3] [0 1] # Meal #1 [2 3] [0 1] # Meal #2 [1 2] [0] """ rb = open_workbook(file_contents=(write_excel(start_state))) assert int(rb.sheet_by_index(1).cell(0, 1).value) == 2 wb = copy(rb) wb.get_sheet(1).write(0, 1, 3) result = BytesIO() wb.save(result) new_state = read_excel(result.getvalue()) assert dump(new_state) == """\
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))
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
def test_stats(explicit_initial): subject = explicit_initial print dump(subject) assert stats(subject) == [("Alice-Bob", 2, 17), ("Charlie-Dave", 2, 42)]
def dump(self): state = self.state_keeper.get_current_state() return dump(state) + u"\n%s\n" % (u"#"*80,) + report(state)
def dump(self): state = self.state_keeper.get_current_state() return dump(state) + u"\n%s\n" % (u"#" * 80,) + report(state)