Exemple #1
0
    def solve(
            self, name: str,
            src_model: Optional[bytes],
            tgt_model: Optional[bytes]) -> SolverResult:
        if src_model is not None:
            Model.parse(src_model)  # as a sanity check
        if tgt_model is not None:
            Model.parse(tgt_model)  # as a sanity check

        trace_data = data_files.full_default_trace(name)
        return SolverResult(trace_data)
def main():
    from production import data_files

    task_name = sys.argv[1] if len(sys.argv) > 1 else 'FA001'

    data_src, data_tgt = data_files.full_problem(task_name)
    m_src = m_tgt = None
    if data_src is not None:
        m_src = Model.parse(data_src)
    if data_tgt is not None:
        m_tgt = Model.parse(data_tgt)

    commands = default_disassembly(m_src, m_tgt)
    trace = compose_commands(commands)
    write_solution(trace, task_name)
    def solve(self, name: str, src_model: Optional[bytes],
              tgt_model: Optional[bytes]) -> SolverResult:
        m_src = m_tgt = None
        if src_model is not None:
            m_src = Model.parse(src_model)
            strategy = default_disassembly
        if tgt_model is not None:
            m_tgt = Model.parse(tgt_model)
            strategy = default_assembly
        if src_model is not None and tgt_model is not None:
            strategy = default_reassembly

        trace = strategy(m_src, m_tgt)
        trace_data = compose_commands(trace)
        return SolverResult(trace_data, extra={})
Exemple #4
0
 def solve(self, name: str, src_model: Optional[bytes],
           tgt_model: Optional[bytes]) -> SolverResult:
     assert src_model is None
     m = Model.parse(tgt_model)
     trace_data = compose_commands(
         solve_gen(m, self.w, self.h, low=self.low))
     return SolverResult(trace_data, extra={})
 def solve(self, name: str, src_model: Optional[bytes],
           tgt_model: Optional[bytes]) -> SolverResult:
     assert tgt_model is None
     m = Model.parse(src_model)
     trace = cubical(m, high=self.high)
     trace_data = compose_commands(trace)
     return SolverResult(trace_data, extra={})
def main():
    from production import data_files

    task_number = int(sys.argv[1]) if len(sys.argv) > 1 else 1

    m = Model.parse(lightning_problem_by_id(task_number))

    solve(up_pass, m, task_number)
def main():
    from production import data_files

    name = 'LA004'
    m = Model.parse(data_files.lightning_problem(f'{name}_tgt.mdl'))

    trace_name = f'{name}.nbt'
    trace = parse_commands(buf=data_files.lightning_default_trace(trace_name),
                           source=trace_name)

    state = State(m.R)
    state.time_step(trace)
    def solve(self, name: str, src_model: Optional[bytes],
              tgt_model: Optional[bytes]) -> SolverResult:
        assert src_model is None
        model = Model.parse(tgt_model)
        model_height = get_model_height(model)

        plots = create_plots(model)

        trace = single_bot_trace(model, model_height, plots)

        trace_data = compose_commands(trace)
        return SolverResult(trace_data, extra={})
    def solve(self, name: str, src_model: Optional[bytes],
              tgt_model: Optional[bytes]) -> SolverResult:
        assert src_model is None
        m = Model.parse(tgt_model)
        try:
            trace_data = compose_commands(self.solve_gen(m))

            return SolverResult(trace_data, extra={})
        except KeyboardInterrupt:
            raise
        except:
            exc = StringIO()
            traceback.print_exc(file=exc)
            return SolverResult(Fail(), extra=dict(tb=exc.getvalue()))
Exemple #10
0
def test_full():
    assert 'FR042' in full_names()

    src_model, tgt_model = full_problem('FA001')
    assert src_model is None
    Model.parse(tgt_model)

    src_model, tgt_model = full_problem('FD001')
    Model.parse(src_model)
    assert tgt_model is None

    src_model, tgt_model = full_problem('FR001')
    Model.parse(src_model)
    Model.parse(tgt_model)

    trace = full_default_trace('FR001')
    parse_commands(trace, source='FR001.nbt')
def main():
    logging.basicConfig(
        level=logging.INFO,
        format='%(levelname).1s %(module)10.10s:%(lineno)-4d %(message)s')

    conn = db.get_conn()
    cur = conn.cursor()

    for name in sorted(data_files.full_names()):
        if not name.startswith('FR'):
            continue
        logging.info(name)

        src_data, tgt_data = data_files.full_problem(name)
        tgt_data = None

        stats = {}
        if src_data is not None:
            m = Model.parse(src_data)
            num_full_voxels = 0
            for pos in m.enum_voxels():
                if m[pos]:
                    num_full_voxels += 1
            stats.update(R=m.R, src_size=num_full_voxels)
            src_data = zlib.compress(src_data)
        if tgt_data is not None:
            m = Model.parse(tgt_data)
            num_full_voxels = 0
            for pos in m.enum_voxels():
                if m[pos]:
                    num_full_voxels += 1
            stats.update(R=m.R, tgt_size=num_full_voxels)
            tgt_data = zlib.compress(tgt_data)

        logging.info(stats)

        name = name.replace('FR', 'ZD')
        logging.info(name)

        extra = {}

        cur.execute(
            '''
            INSERT INTO problems(
                name, src_data, tgt_data, stats, extra, invocation_id, timestamp)
            VALUES (%s, %s, %s, %s, %s, %s, %s)
            ON CONFLICT DO NOTHING
            RETURNING id
            ''', [
                name, src_data, tgt_data,
                json.dumps(stats),
                json.dumps(extra),
                db.get_this_invocation_id(conn),
                time.time()
            ])
        res = cur.fetchall()
        if res:
            [[model_id]] = res
            logger.info(f'Recorded as model/{model_id}')
        else:
            logger.info(f'Model {name!r} already exists')
        conn.commit()
        yield Cmd.Halt()

    def solve_gen(self, model: 'Model'):
        self.commands = iter([])
        self.state = State(model.R)

        voxels_to_fill = breadth_first_search(floor_contact(model),
                                              filled_neighbors(model))

        for voxel in voxels_to_fill:
            current_position = self.state.bots[0].pos
            self.add_commands(navigate_near_voxel(current_position, voxel))
            current_position = self.state.bots[0].pos
            self.add_commands([Cmd.Fill(voxel - current_position)])

        self.add_commands(self.finish())
        return self.commands


if __name__ == '__main__':
    task_number = int(sys.argv[1]) if len(sys.argv) > 1 else 1

    name = 'LA{0:03d}_tgt.mdl'.format(task_number)
    data = data_files.lightning_problem(name)
    m = Model.parse(data)

    with open('LA{0:03d}.nbt'.format(task_number), 'wb') as f:
        solver = BFSSolver(None)
        for cmd in solver.solve_gen(m):
            f.write(bytearray(cmd.compose()))
Exemple #13
0
def get_model(model_id):
    return Model.parse(lightning_problem_by_id(model_id))